Recently, Norge found a string $$$s = s_1 s_2 \ldots s_n$$$ consisting of $$$n$$$ lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string $$$s$$$. Yes, all $$$\frac{n (n + 1)}{2}$$$ of them!A substring of $$$s$$$ is a non-empty string $$$x = s[a \ldots b] = s_{a} s_{a + 1} \ldots s_{b}$$$ ($$$1 \leq a \leq b \leq n$$$). For example, "auto" and "ton" are substrings of "automaton".Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only $$$k$$$ Latin letters $$$c_1, c_2, \ldots, c_k$$$ out of $$$26$$$.After that, Norge became interested in how many substrings of the string $$$s$$$ he could still type using his broken keyboard. Help him to find this number.

The first line contains two space-separated integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$, $$$1 \leq k \leq 26$$$) — the length of the string $$$s$$$ and the number of Latin letters still available on the keyboard. The second line contains the string $$$s$$$ consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains $$$k$$$ space-separated distinct lowercase Latin letters $$$c_1, c_2, \ldots, c_k$$$ — the letters still available on the keyboard.

Print a single number — the number of substrings of $$$s$$$ that can be typed using only available letters $$$c_1, c_2, \ldots, c_k$$$.

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n, k int
var S []rune
var Avail []rune

func main() {
	n, k = ReadInt2()
	S = ReadRuneSlice()
	for i := 0; i < k; i++ {
		tmp := ReadRuneSlice()
		Avail = append(Avail, tmp[0])
	}

	memo := make([]int, n)
	for i := 0; i < n; i++ {
		if !isAvail(S[i]) {
			memo[i] = -1
		}
	}

	cur := int64(0)
	sums := make([]int64, n)
	for i := 0; i < n; i++ {
		if memo[i] == -1 {
			// アウトなのでリセット
			cur = 0
		} else {
			// 継続
			cur++
		}
		sums[i] = cur
	}

	ans := int64(0)
	for i := 0; i < n; i++ {
		ans += sums[i]
	}
	fmt.Println(ans)
}

func isAvail(r rune) bool {
	for i := 0; i < len(Avail); i++ {
		if Avail[i] == r {
			return true
		}
	}
	return false
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
*/

/*******************************************************************/

package main

import (
	"bufio"
	"fmt"
	"os"
)

var inf int = 0x3f3f3f3f
var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

var n, m int
var s string

func main() {
	fmt.Fscan(reader, &n, &m, &s)
	mp := make(map[byte]int)
	for i := 0; i < m; i++ {
		var c string
		fmt.Fscan(reader, &c)
		mp[c[0]] = 1
	}
	var sum,ans int64
	for i := 0; i < n; i++ {
		if mp[s[i]] == 0 {
			ans += sum * (sum + 1) / 2
			sum = 0
		} else {
			sum++
		}
	}
	ans += sum * (sum + 1) / 2
	fmt.Println(ans)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)

	var str, keys string

	reader := bufio.NewReader(os.Stdin)

	str, _ = reader.ReadString('\n')
	keys, _ = reader.ReadString('\n')

	keyMap := make(map[int]bool)
	for i := 0; i < len(keys); i++ {
		key := int(keys[i])
		if key >= 97 && key <= 122 {
			keyMap[key] = true
		}
	}

	var substringLen, result int64
	substringLen = 0
	result = 0
	for i := 0; i < n; i++ {
		if keyMap[int(str[i])] {
			substringLen++
		} else {
			result += (substringLen * (substringLen + 1)) / 2
			substringLen = 0
		}
	}

	result += (substringLen * (substringLen + 1)) / 2
	fmt.Println(result)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)

	var str, keys string

	reader := bufio.NewReader(os.Stdin)

	//input, _ := ioutil.ReadFile("input.txt")
	//str = string(input)
	//keys = "a b c d e f g h i j k l m n o p q r s t u v w x y z"

	str, _ = reader.ReadString('\n')
	keys, _ = reader.ReadString('\n')

	keyMap := make(map[int]bool)
	for i := 0; i < len(keys); i++ {
		key := int(keys[i])
		if key >= 97 && key <= 122 {
			keyMap[key] = true
		}
	}

	var substringLen, result int64
	substringLen = 0
	result = 0
	for i := 0; i < n; i++ {
		if keyMap[int(str[i])] {
			substringLen++
		} else {
			result += (substringLen * (substringLen + 1)) / 2
			substringLen = 0
		}
	}

	result += (substringLen * (substringLen + 1)) / 2
	fmt.Println(result)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k int
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	var s, temp string
	fmt.Fscanf(reader, "%s\n", &s)
	letters := make([]string, 0)
	for i := 1; i <= k; i++ {
		fmt.Fscanf(reader, "%s", &temp)
		letters = append(letters, temp)
		s = strings.Replace(s, temp, "1", -1)
	}
	fmt.Fscanf(reader, "\n")
	var count, ans int64
	for _, ch := range []rune(s) {
		if ch != 49 {
			//fmt.Fprintf(writer, "%d %c %d\n", idx, ch, count)
			if count > 0 {
				ans = ans + ((count * (count + 1)) / 2)
			}
			count = 0
		} else {
			count = count + 1
		}
	}
	ans = ans + ((count * (count + 1)) / 2)
	fmt.Fprintf(writer, "%d\n", ans)
}

// Author: sighduck
// URL: https://codeforces.com/contest/1272/problem/C

package main

import (
	"bufio"
	"fmt"
	"os"
)

func Solve(n int, k int, s string, c []string) int64 {
	substringCount := int64(0)
	run := int64(0)
	alphabetMap := make(map[string]bool)
	for _, elem := range c {
		alphabetMap[string(elem)] = true
	}
	for i, elem := range s {
		if alphabetMap[string(elem)] == true {
			run += 1
		}
		if alphabetMap[string(elem)] == false || i == n-1 {
			substringCount += run * (run + 1) / 2
			run = 0
		}
	}
	return substringCount
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k int
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	var s string
	fmt.Fscanf(reader, "%s\n", &s)
	c := make([]string, k)
	for i := 0; i < k; i++ {
		fmt.Fscanf(reader, "%s", &c[i])
	}

	fmt.Fprintf(writer, "%d\n", Solve(n, k, s, c))
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	var n, k uint64
	fmt.Scanf("%d %d\n", &n, &k)

	var s, availChars string
	fmt.Scanln(&s)

	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		availChars = scanner.Text()
	}

	availArray := strings.Split(availChars, " ")
	letterMap := make(map[rune]bool)
	for _, char := range availArray {
		runes := []rune(char)
		letterMap[runes[0]] = true
	}

	var substrings, num uint64
	substrings = 0
	num = 0
	letters := []rune(s)
	for _, char := range letters {
		if letterMap[char] {
			num++
		} else {
			substrings += (uint64)(num * (num + 1) / 2)
			num = 0
		}
	}

	substrings += (uint64)(num * (num + 1) / 2)

	fmt.Println(substrings)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var inf int = 0x3f3f3f3f
var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

var n, m int
var s string

func main() {
	fmt.Fscan(reader, &n, &m, &s)
	mp := make(map[byte]int)
	for i := 0; i < m; i++ {
		var c string
		fmt.Fscan(reader, &c)
		mp[c[0]] = 1
	}
	sum := 0
	ans := 0
	for i := 0; i < n; i++ {
		if mp[s[i]] == 0 {
			ans += sum * (sum + 1) / 2
			sum = 0
		} else {
			sum++
		}
	}
	ans += sum * (sum + 1) / 2
	fmt.Println(ans)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)

	var str, keys string

	reader := bufio.NewReaderSize(os.Stdin, 300000)
	str, _ = reader.ReadString('\n')
	keys, _ = reader.ReadString('\n')

	keyMap := make(map[int]bool)
	for i := 0; i < len(keys); i++ {
		key := int(keys[i])
		if key >= 97 && key <= 122 {
			keyMap[key] = true
		}
	}

	substringLen := 0
	result := 0
	for i := 0; i < len(str); i++ {
		if keyMap[int(str[i])] {
			substringLen++
		} else {
			result += (substringLen * (substringLen + 1)) / 2
			substringLen = 0
		}
	}

	result += (substringLen * (substringLen + 1)) / 2
	fmt.Println(result)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)

	var str, keys string

	reader := bufio.NewReader(os.Stdin)

	//input, _ := ioutil.ReadFile("input.txt")
	//str = string(input)
	//keys = "a b c d e f g h i j k l m n o p q r s t u v w x y z"

	str, _ = reader.ReadString('\n')
	keys, _ = reader.ReadString('\n')

	keyMap := make(map[int]bool)
	for i := 0; i < len(keys); i++ {
		key := int(keys[i])
		if key >= 97 && key <= 122 {
			keyMap[key] = true
		}
	}

	substringLen := 0
	result := 0
	for i := 0; i < n; i++ {
		if keyMap[int(str[i])] {
			substringLen++
		} else {
			result += (substringLen * (substringLen + 1)) / 2
			substringLen = 0
		}
	}

	result += (substringLen * (substringLen + 1)) / 2
	fmt.Println(result)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)

	var str, keys string
	fmt.Scanln(&str)

	scanner := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 0, 1024*1024)
	scanner.Buffer(buf, 2048*1024)

	if scanner.Scan() {
		keys = scanner.Text()
	}

	keyMap := make(map[int]bool)
	for i := 0; i < len(keys); i++ {
		key := int(keys[i])
		if key >= 97 && key <= 122 {
			keyMap[key] = true
		}
	}

	substringLen := 0
	result := 0
	for i := 0; i < len(str); i++ {
		if keyMap[int(str[i])] {
			substringLen++
		} else {
			result += (substringLen * (substringLen + 1)) / 2
			substringLen = 0
		}
	}

	result += (substringLen * (substringLen + 1)) / 2
	fmt.Println(result)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)

	var str, keys string

	reader := bufio.NewReader(os.Stdin)

	//input, _ := ioutil.ReadFile("input.txt")
	//str = string(input)
	//keys = "a b c d e f g h i j k l m n o p q r s t u v w x y z"

	str, _ = reader.ReadString('\n')
	keys, _ = reader.ReadString('\n')

	keyMap := make(map[int]bool)
	for i := 0; i < len(keys); i++ {
		key := int(keys[i])
		if key >= 97 && key <= 122 {
			keyMap[key] = true
		}
	}

	substringLen := 0
	result := int64(0)
	for i := 0; i < n; i++ {
		if keyMap[int(str[i])] {
			substringLen++
		} else {
			result += int64((substringLen * (substringLen + 1)) / 2)
			substringLen = 0
		}
	}

	result += int64((substringLen * (substringLen + 1)) / 2)
	fmt.Println(result)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)

	var str, keys string

	reader := bufio.NewReader(os.Stdin)

	buf := make([]byte, n+1)
	//str, _ = reader.ReadString('\n')
	reader.Read(buf)
	str = string(buf)
	keys, _ = reader.ReadString('\n')

	keyMap := make(map[int]bool)
	for i := 0; i < len(keys); i++ {
		key := int(keys[i])
		if key >= 97 && key <= 122 {
			keyMap[key] = true
		}
	}

	substringLen := 0
	result := 0
	for i := 0; i < len(str); i++ {
		if keyMap[int(str[i])] {
			substringLen++
		} else {
			result += (substringLen * (substringLen + 1)) / 2
			substringLen = 0
		}
	}

	result += (substringLen * (substringLen + 1)) / 2
	fmt.Println(result)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)

	var str, keys string

	scanner := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 0, 1024*1024)
	scanner.Buffer(buf, 2048*1024)

	if scanner.Scan() {
		str = scanner.Text()
	}

	if scanner.Scan() {
		keys = scanner.Text()
	}

	keyMap := make(map[int]bool)
	for i := 0; i < len(keys); i++ {
		key := int(keys[i])
		if key >= 97 && key <= 122 {
			keyMap[key] = true
		}
	}

	substringLen := 0
	result := 0
	for i := 0; i < len(str); i++ {
		if keyMap[int(str[i])] {
			substringLen++
		} else {
			result += (substringLen * (substringLen + 1)) / 2
			substringLen = 0
		}
	}

	result += (substringLen * (substringLen + 1)) / 2
	fmt.Println(result)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)

	var str, keys string
	fmt.Scanln(&str)

	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		keys = scanner.Text()
	}

	keyMap := make(map[int]bool)
	for i := 0; i < len(keys); i++ {
		key := int(keys[i])
		if key >= 97 && key <= 122 {
			keyMap[key] = true
		}
	}

	substringLen := 0
	result := 0
	for i := 0; i < len(str); i++ {
		if keyMap[int(str[i])] {
			substringLen++
		} else {
			result += (substringLen * (substringLen + 1)) / 2
			substringLen = 0
		}
	}

	result += (substringLen * (substringLen + 1)) / 2
	fmt.Println(result)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)

	var str, keys string

	reader := bufio.NewReader(os.Stdin)
	str, _ = reader.ReadString('\n')
	keys, _ = reader.ReadString('\n')

	keyMap := make(map[int]bool)
	for i := 0; i < len(keys); i++ {
		key := int(keys[i])
		if key >= 97 && key <= 122 {
			keyMap[key] = true
		}
	}

	substringLen := 0
	result := 0
	for i := 0; i < len(str); i++ {
		if keyMap[int(str[i])] {
			substringLen++
		} else {
			result += (substringLen * (substringLen + 1)) / 2
			substringLen = 0
		}
	}

	result += (substringLen * (substringLen + 1)) / 2
	fmt.Println(result)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)

	var str, keys string
	fmt.Scanln(&str)

	scanner := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 0, 64*1024)
	scanner.Buffer(buf, 2048*1024)

	if scanner.Scan() {
		keys = scanner.Text()
	}

	keyMap := make(map[int]bool)
	for i := 0; i < len(keys); i++ {
		key := int(keys[i])
		if key >= 97 && key <= 122 {
			keyMap[key] = true
		}
	}

	substringLen := 0
	result := 0
	for i := 0; i < len(str); i++ {
		if keyMap[int(str[i])] {
			substringLen++
		} else {
			result += (substringLen * (substringLen + 1)) / 2
			substringLen = 0
		}
	}

	result += (substringLen * (substringLen + 1)) / 2
	fmt.Println(result)
}

// Author: sighduck
// URL: https://codeforces.com/contest/1272/problem/C

package main

import (
	"bufio"
	"fmt"
	"os"
)

func Solve(n int, k int, s string, c []string) int {
	substringCount := 0
	run := 0
	alphabetMap := make(map[string]bool)
	for _, elem := range c {
		alphabetMap[string(elem)] = true
	}
	for i, elem := range s {
		if alphabetMap[string(elem)] == true {
			run += 1
		}
		if alphabetMap[string(elem)] == false || i == n-1 {
			substringCount += run * (run + 1) / 2
			run = 0
		}
	}
	return substringCount
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k int
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	var s string
	fmt.Fscanf(reader, "%s\n", &s)
	c := make([]string, k)
	for i := 0; i < k; i++ {
		fmt.Fscanf(reader, "%s", &c[i])
	}

	fmt.Fprintf(writer, "%d\n", Solve(n, k, s, c))
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)

	var s, availChars string
	fmt.Scanln(&s)

	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		availChars = scanner.Text()
	}

	availArray := strings.Split(availChars, " ")
	letterMap := make(map[rune]bool)
	for _, char := range availArray {
		runes := []rune(char)
		letterMap[runes[0]] = true
	}

	var substrings uint64
	substrings = 0
	num := 0
	letters := []rune(s)
	for _, char := range letters {
		if letterMap[char] {
			num++
		} else {
			substrings += (uint64)(num * (num + 1) / 2)
			num = 0
		}
	}

	substrings += (uint64)(num * (num + 1) / 2)

	fmt.Println(substrings)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)

	var s, availChars string
	fmt.Scanln(&s)

	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		availChars = scanner.Text()
	}

	availArray := strings.Split(availChars, " ")
	letterMap := make(map[rune]bool)
	for _, char := range availArray {
		runes := []rune(char)
		letterMap[runes[0]] = true
	}

	substrings := 0
	num := 0
	letters := []rune(s)
	for _, char := range letters {
		if letterMap[char] {
			num++
		} else {
			substrings += num * (num + 1) / 2
			num = 0
		}
	}

	substrings += num * (num + 1) / 2

	fmt.Println(substrings)
}


As you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires.Vova managed to build a large army, but forgot about the main person in the army - the commander. So he tries to hire a commander, and he wants to choose the person who will be respected by warriors.Each warrior is represented by his personality — an integer number pi. Each commander has two characteristics — his personality pj and leadership lj (both are integer numbers). Warrior i respects commander j only if  ( is the bitwise excluding OR of x and y).Initially Vova's army is empty. There are three different types of events that can happen with the army:  1 pi — one warrior with personality pi joins Vova's army;  2 pi — one warrior with personality pi leaves Vova's army;  3 pi li — Vova tries to hire a commander with personality pi and leadership li. For each event of the third type Vova wants to know how many warriors (counting only those who joined the army and haven't left yet) respect the commander he tries to hire.

The first line contains one integer q (1 ≤ q ≤ 100000) — the number of events. Then q lines follow. Each line describes the event:   1 pi (1 ≤ pi ≤ 108) — one warrior with personality pi joins Vova's army;  2 pi (1 ≤ pi ≤ 108) — one warrior with personality pi leaves Vova's army (it is guaranteed that there is at least one such warrior in Vova's army by this moment);  3 pi li (1 ≤ pi, li ≤ 108) — Vova tries to hire a commander with personality pi and leadership li. There is at least one event of this type.

For each event of the third type print one integer — the number of warriors who respect the commander Vova tries to hire in the event.

NoteIn the example the army consists of two warriors with personalities 3 and 4 after first two events. Then Vova tries to hire a commander with personality 6 and leadership 3, and only one warrior respects him (, and 2 < 3, but , and 5 ≥ 3). Then warrior with personality 4 leaves, and when Vova tries to hire that commander again, there are no warriors who respect him.

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

type Node struct {
	value int
	left  *Node
	right *Node
}

func add(root *Node, value int, layer int) {
	bit := (value >> uint(layer)) & 1
	root.value++
	if layer == -1 {
		return
	}
	if bit == 0 {
		if root.left == nil {
			root.left = &Node{}
		}
		add(root.left, value, layer-1)
	} else {
		if root.right == nil {
			root.right = &Node{}
		}
		add(root.right, value, layer-1)
	}
}

func remove(root *Node, value, layer int) {
	bit := (value >> uint(layer)) & 1
	root.value--
	if layer == -1 {
		return
	}
	if bit == 0 {
		remove(root.left, value, layer-1)
	} else {
		remove(root.right, value, layer-1)
	}
}

func cal(root *Node, p int, l int, layer int) int {
	if root == nil || layer == -1 {
		return 0
	}
	pbit := (p >> uint(layer)) & 1
	lbit := (l >> uint(layer)) & 1
	lvalue, rvalue := 0, 0
	if root.left != nil {
		lvalue = root.left.value
	}

	if root.right != nil {
		rvalue = root.right.value
	}

	if pbit == 0 && lbit == 0 {
		return cal(root.left, p, l, layer-1)
	} else if pbit == 0 && lbit == 1 {
		return lvalue + cal(root.right, p, l, layer-1)
	} else if pbit == 1 && lbit == 0 {
		return cal(root.right, p, l, layer-1)
	} else if pbit == 1 && lbit == 1 {
		return rvalue + cal(root.left, p, l, layer-1)
	}
	return 0
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	root := &Node{}
	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var t, p, l int
		fmt.Fscanf(reader, "%d ", &t)
		switch t {
		case 1:
			fmt.Fscanf(reader, "%d\n", &p)
			add(root, p, 30)
		case 2:
			fmt.Fscanf(reader, "%d\n", &p)
			remove(root, p, 30)
		case 3:
			fmt.Fscanf(reader, "%d %d\n", &p, &l)
			fmt.Printf("%d\n", cal(root, p, l, 30))
		}
	}
}


Toad Pimple has an array of integers $$$a_1, a_2, \ldots, a_n$$$.We say that $$$y$$$ is reachable from $$$x$$$ if $$$x<y$$$ and there exists an integer array $$$p$$$ such that $$$x = p_1 < p_2 < \ldots < p_k=y$$$, and $$$a_{p_i}\, \&\, a_{p_{i+1}} > 0$$$ for all integers $$$i$$$ such that $$$1 \leq i < k$$$.Here $$$\&$$$ denotes the bitwise AND operation.You are given $$$q$$$ pairs of indices, check reachability for each of them.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$2 \leq n \leq 300\,000$$$, $$$1 \leq q \leq 300\,000$$$) — the number of integers in the array and the number of queries you need to answer. The second line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 300\,000$$$) — the given array. The next $$$q$$$ lines contain two integers each. The $$$i$$$-th of them contains two space-separated integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \leq x_i < y_i \leq n$$$). You need to check if $$$y_i$$$ is reachable from $$$x_i$$$.

Output $$$q$$$ lines. In the $$$i$$$-th of them print "Shi" if $$$y_i$$$ is reachable from $$$x_i$$$, otherwise, print "Fou".

NoteIn the first example, $$$a_3 = 0$$$. You can't reach it, because AND with it is always zero. $$$a_2\, \&\, a_4 > 0$$$, so $$$4$$$ is reachable from $$$2$$$, and to go from $$$1$$$ to $$$4$$$ you can use $$$p = [1, 2, 4]$$$.

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func (io *IO) Solve() {
	var j, k, h uint
	k = 19
	n, q := io.Int(), io.Int()
	a := io.UIntArray(n)
	last := make([]int, k)
	for j = 0; j < k; j++ {
		last[j] = n
	}
	dp := make([][]int, n)
	for i := n - 1; i >= 0; i-- {
		dp[i] = make([]int, k)
		for j = 0; j < k; j++ {
			if (a[i]>>j)&1 != 0 {
				dp[i][j] = i
			} else {
				dp[i][j] = n
				for h = 0; h < k; h++ {
					if (1<<h)&a[i] != 0 &&
						last[h] < n &&
						dp[last[h]][j] < dp[i][j] {
						dp[i][j] = dp[last[h]][j]
					}
				}
			}
		}
		for j = 0; j < k; j++ {
			if (a[i]>>j)&1 != 0 {
				last[j] = i
			}
		}
	}
	for i := 0; i < q; i++ {
		x, y := io.Int()-1, io.Int()-1
		shi := false
		for j = 0; j < k; j++ {
			if (a[y]>>j)&1 != 0 && dp[x][j] <= y {
				shi = true
				break
			}
		}
		if shi {
			io.Print("Shi\n")
		} else {
			io.Print("Fou\n")
		}
	}
	return
}

func main() {
	NewIO().Solve()
}

type IO struct {
	scanner *bufio.Scanner
	writer  io.Writer
}

func NewIO() *IO {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return &IO{scanner, os.Stdout}
}

func (io *IO) Skip() {
	io.scanner.Scan()
}

func (io *IO) Int32() (n int32) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int32(v-'0')
	}
	return
}

func (io *IO) Int() (n int) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

func (io *IO) UInt() (n uint) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + uint(v-'0')
	}
	return
}

func (io *IO) Bytes() []byte {
	io.scanner.Scan()
	return io.scanner.Bytes()
}

func (io *IO) IntArray(n int) (arr []int) {
	arr = make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = io.Int()
	}
	return
}

func (io *IO) UIntArray(n int) (arr []uint) {
	arr = make([]uint, n)
	for i := 0; i < n; i++ {
		arr[i] = io.UInt()
	}
	return
}

func (io *IO) Print(a interface{}) {
	fmt.Fprint(io.writer, a)
}

func (io *IO) Printf(format string, a interface{}) {
	fmt.Fprintf(io.writer, format, a)
}

func (io *IO) setBuffer() {
	io.scanner.Buffer(make([]byte, 4096), 512*1024)
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func (io *IO) Solve() {
	var j, k, h uint
	k = 19
	n, q := io.Int(), io.Int()
	a := io.UIntArray(n)
	last := make([][]int, n)
	last[n-1] = make([]int, k)
	for j = 0; j < k; j++ {
		last[n-1][j] = n
	}
	for i := n - 2; i >= 0; i-- {
		last[i] = make([]int, k)
		for j = 0; j < k; j++ {
			if (1<<j)&a[i+1] != 0 {
				last[i][j] = i + 1
			} else {
				last[i][j] = last[i+1][j]
			}
		}
	}
	go_ := make([][]int, n)
	for i := n - 1; i >= 0; i-- {
		go_[i] = make([]int, k)
		for j = 0; j < k; j++ {
			if (1<<j)&a[i] != 0 {
				go_[i][j] = i
			} else {
				min, isMin := 0, false
				for h = 0; h < k; h++ {
					if (1<<h)&a[i] != 0 {
						lasth := last[i][h]
						if lasth < n {
							goj := go_[lasth][j]
							if !isMin || goj < min {
								min = goj
								isMin = true
							}
						}
					}
				}
				if isMin {
					go_[i][j] = min
				} else {
					go_[i][j] = n
				}
			}
		}
	}
	for i := 0; i < q; i++ {
		x, y := io.Int()-1, io.Int()-1
		shi := false
		for j = 0; j < k; j++ {
			if (1<<j)&a[y] != 0 && go_[x][j] <= y {
				shi = true
				break
			}
		}
		if shi {
			io.Print("Shi\n")
		} else {
			io.Print("Fou\n")
		}
	}
	return
}

func main() {
	NewIO().Solve()
}

type IO struct {
	scanner *bufio.Scanner
	writer  io.Writer
}

func NewIO() *IO {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return &IO{scanner, os.Stdout}
}

func (io *IO) Skip() {
	io.scanner.Scan()
}

func (io *IO) Int32() (n int32) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int32(v-'0')
	}
	return
}

func (io *IO) Int() (n int) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

func (io *IO) UInt() (n uint) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + uint(v-'0')
	}
	return
}

func (io *IO) Bytes() []byte {
	io.scanner.Scan()
	return io.scanner.Bytes()
}

func (io *IO) IntArray(n int) (arr []int) {
	arr = make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = io.Int()
	}
	return
}

func (io *IO) UIntArray(n int) (arr []uint) {
	arr = make([]uint, n)
	for i := 0; i < n; i++ {
		arr[i] = io.UInt()
	}
	return
}

func (io *IO) Print(a interface{}) {
	fmt.Fprint(io.writer, a)
}

func (io *IO) Printf(format string, a interface{}) {
	fmt.Fprintf(io.writer, format, a)
}

func (io *IO) setBuffer() {
	io.scanner.Buffer(make([]byte, 4096), 512*1024)
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func (io *IO) Solve() {
	var j, k, h uint
	k = 19
	n, q := io.Int(), io.Int()
	a := io.UIntArray(n)
	last := make([]int, k)
	for j = 0; j < k; j++ {
		last[j] = n
	}
	dp := make([][]int, n)
	for i := n - 1; i >= 0; i-- {
		dp[i] = make([]int, k)
		for j = 0; j < k; j++ {
			dp[i][j] = n
		}
		for j = 0; j < k; j++ {
			if (a[i]>>j)&1 != 0 {
				if last[j] < n {
					for h = 0; h < k; h++ {
						if dp[last[j]][h] < dp[i][h] {
							dp[i][h] = dp[last[j]][h]
						}
					}
				}
				dp[i][j] = i
				last[j] = i
			}
		}
	}
	for i := 0; i < q; i++ {
		x, y := io.Int()-1, io.Int()-1
		shi := false
		for j = 0; j < k; j++ {
			if (a[y]>>j)&1 != 0 && dp[x][j] <= y {
				shi = true
				break
			}
		}
		if shi {
			io.Print("Shi\n")
		} else {
			io.Print("Fou\n")
		}
	}
	return
}

func main() {
	NewIO().Solve()
}

type IO struct {
	scanner *bufio.Scanner
	writer  io.Writer
}

func NewIO() *IO {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return &IO{scanner, os.Stdout}
}

func (io *IO) Skip() {
	io.scanner.Scan()
}

func (io *IO) Int32() (n int32) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int32(v-'0')
	}
	return
}

func (io *IO) Int() (n int) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

func (io *IO) UInt() (n uint) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + uint(v-'0')
	}
	return
}

func (io *IO) Bytes() []byte {
	io.scanner.Scan()
	return io.scanner.Bytes()
}

func (io *IO) IntArray(n int) (arr []int) {
	arr = make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = io.Int()
	}
	return
}

func (io *IO) UIntArray(n int) (arr []uint) {
	arr = make([]uint, n)
	for i := 0; i < n; i++ {
		arr[i] = io.UInt()
	}
	return
}

func (io *IO) Print(a interface{}) {
	fmt.Fprint(io.writer, a)
}

func (io *IO) Printf(format string, a interface{}) {
	fmt.Fprintf(io.writer, format, a)
}

func (io *IO) setBuffer() {
	io.scanner.Buffer(make([]byte, 4096), 512*1024)
}


Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya.

The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls.  Each of the following n lines contains information about a foul in the following form:    first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs;  then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player;  then goes the player's number m (1 ≤ m ≤ 99);  then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given.  The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute.

For each event when a player received his first red card in a chronological order print a string containing the following information:   The name of the team to which the player belongs;  the player's number in his team;  the minute when he received the card.  If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards).

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	teamNames := []string {next(), next()}
	players := [][]int{make([]int, 100), make([]int, 100)}
	n := nextInt()
	time, number, team := 0, 0, 0
	card := ""

	for ; n > 0; n-- {
		time = nextInt()

		if next() == "h" {
			team = 0
		} else {
			team = 1
		}

		number, card = nextInt(), next()

		if players[team][number] <= 0  {
			if card == "y" {
				if players[team][number] == 0 {
					players[team][number] = -1
				} else {
					players[team][number] = time
					println(teamNames[team], number, time)
				}
			} else {
				players[team][number] = time
				println(teamNames[team], number, time)

			}
		}
	}

}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

// Input & Output
var (
	input  = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

type Player struct {
	TeamName *string
	Number   int
	HasYC    bool
	HasRC    bool
}

var (
	homeName string
	awayName string
	n        int
	result   int
)

func in() {
	fmt.Fscan(input, &homeName)
	fmt.Fscan(input, &awayName)
	fmt.Fscan(input, &n)
}

func out() {
	defer output.Flush()
}

func run() {
	homePlayers := make([]Player, 100)
	awayPlayers := make([]Player, 100)
	var min, num int
	var team, card string
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &min)
		fmt.Fscan(input, &team)
		fmt.Fscan(input, &num)
		fmt.Fscan(input, &card)
		var player *Player
		if team == "a" {
			player = &awayPlayers[num]
		} else {
			player = &homePlayers[num]
		}

		if player.Number == 0 {
			player.Number = num
			if team == "a" {
				player.TeamName = &awayName
			} else {
				player.TeamName = &homeName
			}

		}
		if player.HasRC {
			continue
		}
		if card == "y" {
			if !player.HasYC {
				player.HasYC = true
			} else {
				player.HasRC = true
				print(player, min)
			}
		} else {
			player.HasRC = true
			print(player, min)
		}
	}
}

func print(player *Player, min int) {
	fmt.Fprintf(output, "%s %d %d\n", *player.TeamName, player.Number, min)
}

func main() {
	in()
	run()
	out()
}

package main

import (
	"fmt"
)

func main() {
	var home, away string
	var n int
	homePlayers := make([]int, 100)
	awayPlayers := make([]int, 100)

	fmt.Scan(&home, &away, &n)

	for i := 0; i < n; i++ {
		var t, no int
		var team, card string
		var players []int

		fmt.Scan(&t, &team, &no, &card)

		if team == "h" {
			players = homePlayers
			team = home
		} else {
			players = awayPlayers
			team = away
		}

		if players[no] >= 2 {
			continue
		}

		if card == "y" {
			players[no]++
		} else {
			players[no] += 2
		}

		if players[no] >= 2 {
			fmt.Println(team, no, t)
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var team [2]string // team[0] ... home
	var n int
	fmt.Scan(&team[0], &team[1], &n)
	var card [200]int
	for i := 0; i < n; i++ {
		var t, m int
		var ha, yr string
		fmt.Scan(&t, &ha, &m, &yr)
		if ha == "a" {
			m += 100
		}
		if card[m] >= 2 {
			continue
		}
		switch yr {
		case "r":
			card[m] = 2
		case "y":
			card[m]++
		}
		if card[m] == 2 {
			fmt.Printf("%s %d %d\n", team[m/100], m%100, t)
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var home, away string
	var n int
	fmt.Scan(&home, &away, &n)
	var yellow, out [200]int
	for i := 0; i < n; i++ {
		var t, m int
		var ha, card string
		fmt.Scan(&t, &ha, &m, &card)
		idx := m
		if ha == "a" {
			idx += 100
		}
		record := func() {
			if out[idx] > 0 {
				return
			}
			out[idx] = 1
			team := home
			if ha == "a" {
				team = away
			}
			fmt.Printf("%s %d %d\n", team, m, t)
		}
		if card == "r" {
			record()
			continue
		}
		if yellow[idx] > 0 {
			record()
			continue
		}
		yellow[idx] = 1
	}
}

package main

import (
    "strconv"
    "bufio"
    "os"
    "fmt"
)
// var file, _ = os.Open("input.txt")
// var outfile, _ = os.Create("output.txt")
// var in = bufio.NewScanner(file)
// var out = bufio.NewWriter(outfile)
var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
    if !in.Scan() {
        panic("Scan error")
    }
    return in.Text()
}

func nextInt() int {
    ret, _ := strconv.Atoi(next())
    return ret
}

func nextFloat() float64 {
    ret, _ := strconv.ParseFloat(next(), 64)
    return ret
}

func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    t1 := next()
    t2 := next()
    n := nextInt()
    h := make(map[int]int)
    a := make(map[int]int)
    for i := 0; i < n; i++ {
        t := next()
        tm := next()
        m := nextInt()
        c := next()
        if tm == "h" {
            if c == "y" && h[m] < 2 {
                h[m]++;
                if h[m] == 2 {
                    fmt.Fprintln(out, t1 + " " + strconv.Itoa(m) + " " + t)
                }
            } else if c == "r" && h[m] < 2 {
                h[m] = 2
                fmt.Fprintln(out, t1 + " " + strconv.Itoa(m) + " " + t)
            }
        } else {
            if c == "y" && a[m] < 2 {
                a[m]++;
                if a[m] == 2 {
                    fmt.Fprintln(out, t2 + " " + strconv.Itoa(m) + " " + t)
                }
            } else if c == "r" && a[m] < 2 {
                a[m] = 2
                fmt.Fprintln(out, t2 + " " + strconv.Itoa(m) + " " + t)
            }

        }
    }

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	teamName := []string {next(), next()}
	players := [][]int{make([]int, 100), make([]int, 100)}
	times := [][]int{make([]int, 100), make([]int, 100)}
	n := nextInt()
	time, number, team := 0, 0, 0
	card := ""

	for ; n > 0; n-- {
		time = nextInt()

		if next() == "h" {
			team = 0
		} else {
			team = 1
		}

		number, card = nextInt(), next()

		if players[team][number] <= 0  {
			if card == "y" {
				if players[team][number] == 0 {
					players[team][number] = -1
				} else {
					players[team][number] = time
					times[team][time] = number
				}
			} else {
				players[team][number] = time
				times[team][time] = number
			}
		}
	}
	// println(players)
	printPlayers(teamName[0], times[0])
	printPlayers(teamName[1], times[1])

}

func printPlayers(team string, times []int) {
	for i, v := range times {
		if v >= 1 {
			println(team, v, i)
		}
	}
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	teamName := []string {next(), next()}
	players := [][]int{make([]int, 100), make([]int, 100)}
	n := nextInt()
	time, number, team := 0, 0, 0
	card := ""

	for ; n > 0; n-- {
		time = nextInt()

		if next() == "h" {
			team = 0
		} else {
			team = 1
		}

		number, card = nextInt(), next()

		if players[team][number] <= 0  {
			if card == "y" {
				if players[team][number] == 0 {
					players[team][number] = -1
				} else {
					players[team][number] = time
				}
			} else {
				players[team][number] = time
			}
		}
	}
	// println(players)
	printPlayers(teamName[0], players[0])
	printPlayers(teamName[1], players[1])

}

func printPlayers(team string, players []int) {
	for i, v := range players {
		if v >= 1 {
			println(team, i, v)
		}
	}
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	teamName := []string {next(), next()}
	players := [][]int{make([]int, 100), make([]int, 100)}
	n := nextInt()
	time, number, team := 0, 0, 0
	card := ""

	for ; n > 0; n-- {
		time = nextInt()

		if next() == "h" {
			team = 0
		} else {
			team = 1
		}

		number, card = nextInt(), next()

		if players[team][number] <= 0  {
			if card == "y" {
				if players[team][number] == 0 {
					players[team][number] = -1
				} else {
					players[team][number] = time
				}
			} else {
				players[team][number] = time
			}
		}
	}
	// println(players)
	printPlayers(teamName[0], players[0])
	printPlayers(teamName[1], players[1])

}

func printPlayers(team string, players []int) {
	for i, v := range players {
		if v > 1 {
			println(team, i, v)
		}
	}
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	hName, aName := next(), next()
	n := nextInt()
	players := make([][]int, 2)
	players[0], players[1] = make([]int, 100), make([]int, 100)
	time, number, team := 0, 0, 0
	card := ""

	for ; n > 0; n-- {
		time = nextInt()
		if next() == "h" {
			team = 0
		} else {
			team = 1
		}

		number, card = nextInt(), next()

		if card == "y" {
			if players[team][number] == 0 {
				players[team][number] = 1
			} else {
				players[team][number] = time
			}
		} else {
			players[team][number] = time
		}
	}

	printPlayers(hName, players[0])
	printPlayers(aName, players[1])

}

func printPlayers(team string, players []int) {
	for i, v := range players {
		if v > 1 {
			println(team, i, v)
		}
	}
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

// Input & Output
var (
	input  = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

type Player struct {
	TeamName *string
	Number   int
	HasYC    bool
	HasRC    bool
}

var (
	homeName string
	awayName string
	n        int
	result   int
)

func in() {
	fmt.Fscan(input, &homeName)
	fmt.Fscan(input, &awayName)
	fmt.Fscan(input, &n)
}

func out() {
	defer output.Flush()
}

func run() {
	players := make([]Player, 100)
	var min, num int
	var team, card string
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &min)
		fmt.Fscan(input, &team)
		fmt.Fscan(input, &num)
		fmt.Fscan(input, &card)
		player := &players[num]
		if player.Number == 0 {
			player.Number = num
			if team == "a" {
				player.TeamName = &awayName
			} else {
				player.TeamName = &homeName
			}

		}
		if player.HasRC {
			continue
		}
		if card == "y" {
			if !player.HasYC {
				player.HasYC = true
			} else {
				player.HasRC = true
				print(player, min)
			}
		} else {
			player.HasRC = true
			print(player, min)
		}
	}
}

func print(player *Player, min int) {
	fmt.Fprintf(output, "%s %d %d\n", *player.TeamName, player.Number, min)
}

func main() {
	in()
	run()
	out()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

// Input & Output
var (
	input  = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

type Player struct {
	TeamName *string
	Number   int
	HasYC    bool
	HasRC    bool
}

var (
	homeName string
	awayName string
	n        int
	result   int
)

func in() {
	fmt.Fscan(input, &homeName)
	fmt.Fscan(input, &awayName)
	fmt.Fscan(input, &n)
}

func out() {
	defer output.Flush()
}

func run() {
	players := make([]Player, 100)
	var min, num int
	var team, card string
	for i := 0; i < n; i++ {
		fmt.Scan(&min)
		fmt.Scan(&team)
		fmt.Scan(&num)
		fmt.Scan(&card)
		player := &players[num]
		if player.Number == 0 {
			player.Number = num
			if team == "a" {
				player.TeamName = &awayName
			} else {
				player.TeamName = &homeName
			}

		}
		if player.HasRC {
			continue
		}
		if card == "y" {
			if !player.HasYC {
				player.HasYC = true
			} else {
				player.HasRC = true
				print(player, min)
			}
		} else {
			player.HasRC = true
			print(player, min)
		}
	}
}

func print(player *Player, min int) {
	fmt.Fprintf(output, "%s %d %d\n", *player.TeamName, player.Number, min)
}

func main() {
	in()
	run()
	out()
}

package main

import (
	"fmt"
)

func main() {
	var home, away string
	var n int
	fmt.Scan(&home, &away, &n)
	var yellow [200]int
	for i := 0; i < n; i++ {
		var t, m int
		var ha, card string
		fmt.Scan(&t, &ha, &m, &card)
		record := func() {
			team := home
			if ha == "a" {
				team = away
			}
			fmt.Printf("%s %d %d\n", team, m, t)
		}
		if card == "r" {
			record()
			continue
		}
		idx := m
		if ha == "a" {
			idx += 100
		}
		if yellow[idx] > 0 {
			record()
			continue
		}
		yellow[idx] = 1
	}
}


Today on a math lesson the teacher told Vovochka that the Euler function of a positive integer φ(n) is an arithmetic function that counts the positive integers less than or equal to n that are relatively prime to n. The number 1 is coprime to all the positive integers and φ(1) = 1.Now the teacher gave Vovochka an array of n positive integers a1, a2, ..., an and a task to process q queries li ri — to calculate and print  modulo 109 + 7. As it is too hard for a second grade school student, you've decided to help Vovochka.

The first line of the input contains number n (1 ≤ n ≤ 200 000) — the length of the array given to Vovochka. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106). The third line contains integer q (1 ≤ q ≤ 200 000) — the number of queries. Next q lines contain the queries, one per line. Each query is defined by the boundaries of the segment li and ri (1 ≤ li ≤ ri ≤ n).

Print q numbers — the value of the Euler function for each query, calculated modulo 109 + 7.

package main

import "fmt"
import "sort"
import "os"
import "bufio"
import "strconv"

type B struct {
  l, r, id int
}

type Bs []B

func (s Bs) Len() int {
  return len(s)
}

func (s Bs) Swap(i, j int){
  s[i], s[j] = s[j], s[i]
}

func (s Bs) Less(i, j int) bool { return s[i].r < s[j].r }

var scanner *bufio.Scanner

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)

  for i := 2; i<MAX; i++ {
    if (0==fac[i]) {
      for j := i; j < MAX; j += i {
        fac[j] = i;
      }
    }
  }

  n := ri()
  for i := 0; i<n; i++ {
    a[i] = ri();
    if i!=0 {
      prod[i] = int(int64(prod[i-1]) * int64(a[i]) % MOD)
    } else {
      prod[i] = int(int64(a[i]) % MOD)
    }
  }
  q := ri()
  for i:=0; i<q; i++ {
    b[i].id = i;
    b[i].l = ri()-1;
    b[i].r = ri()-1;
  }

  //sort!("a.r < b.r")(b[0..q]); // TODO
  sort.Sort(Bs(b[0:q]))

  for i:=0; i<NN*2; i++ {
    seg[i] = 1;
  }

  j := 0;
  for i:=0; i<n; i++ {
    for x := a[i]; x > 1; {
      y := fac[x];
      x /= y
      for (x % y == 0){x /= y}
      modify(pre[y], i+1, int(int64(y-1)*int64(inv(y))%MOD));
      pre[y] = i+1;
    }

    for ; j < q && b[j].r == i; j++ {
      if b[j].l != 0 {
        ans[b[j].id] = int(int64(query(b[j].l)) * int64(prod[i]) % MOD * int64(inv(prod[b[j].l-1])) % MOD);
      } else {
        ans[b[j].id] = int(int64(query(b[j].l)) * int64(prod[i]) % MOD % MOD);
      }
    }
  }
  for i:=0; i<q; i++ {
    fmt.Printf("%d\n", ans[i]);
  }
}

func ri1() int {
  var x int;
  fmt.Scanf("%d", &x);
  return x;
}

func ri() int {
  scanner.Scan()
  x, _ := strconv.Atoi(scanner.Text())
  return x
}

const N = 200000
const NN = 1 << 18
const Q = 200000
const MAX = 1000001
const MOD = 1000000007;

var b [Q]B;

var pre [MAX]int
var fac [MAX]int
var a [N]int
var prod [N]int
var seg [NN*2]int
var ans [Q]int

func modify(l, r, x int) {
  l += NN-1
  r += NN-1
  for ; l < r; {
    if (l%2 == 0) {
      seg[l] = int(int64(seg[l]) * int64(x) % MOD);
    }
    if (r%2 == 0) {
      r--;
      seg[r] = int(int64(seg[r]) * int64(x) % MOD);
    }
    l >>= 1;
    r >>= 1;
  }
}

func query(i int) int {
  r := 1;
  for i += NN-1; ; {
    r = int(int64(r) * int64(seg[i]) % MOD);
    if (i==0) {break;}
    i = ((i-1) >> 1);
  }
  return r;
}

func inv(x int) int {
  r := 1;
  for ; x > 1; x = MOD % x {
    r = int(int64(r) * int64(-MOD/x) % MOD)
  }
  return (r+MOD)%MOD;
}

package main

import "fmt"
import "sort"

type B struct {
  l, r, id int
}

type Bs []B

func (s Bs) Len() int {
  return len(s)
}

func (s Bs) Swap(i, j int){
  s[i], s[j] = s[j], s[i]
}

func (s Bs) Less(i, j int) bool { return s[i].r < s[j].r }

func main() {
  for i := 2; i<MAX; i++ {
    if (0==fac[i]) {
      for j := i; j < MAX; j += i {
        fac[j] = i;
      }
    }
  }

  n := ri()
  for i := 0; i<n; i++ {
    a[i] = ri();
    if i!=0 {
      prod[i] = int(int64(prod[i-1]) * int64(a[i]) % MOD)
    } else {
      prod[i] = int(int64(a[i]) % MOD)
    }
  }
  q := ri()
  for i:=0; i<q; i++ {
    b[i].id = i;
    b[i].l = ri()-1;
    b[i].r = ri()-1;
  }

  //sort!("a.r < b.r")(b[0..q]); // TODO
  sort.Sort(Bs(b[0:q]))

  for i:=0; i<NN*2; i++ {
    seg[i] = 1;
  }

  j := 0;
  for i:=0; i<n; i++ {
    for x := a[i]; x > 1; {
      y := fac[x];
      x /= y
      for (x % y == 0){x /= y}
      modify(pre[y], i+1, int(int64(y-1)*int64(inv(y))%MOD));
      pre[y] = i+1;
    }

    for ; j < q && b[j].r == i; j++ {
      if b[j].l != 0 {
        ans[b[j].id] = int(int64(query(b[j].l)) * int64(prod[i]) % MOD * int64(inv(prod[b[j].l-1])) % MOD);
      } else {
        ans[b[j].id] = int(int64(query(b[j].l)) * int64(prod[i]) % MOD % MOD);
      }
    }
  }
  for i:=0; i<q; i++ {
    fmt.Printf("%d\n", ans[i]);
  }
}

func ri() int {
  var x int;
  fmt.Scanf("%d", &x);
  return x;
}

const N = 200000
const NN = 1 << 18
const Q = 200000
const MAX = 1000001
const MOD = 1000000007;

var b [Q]B;

var pre [MAX]int
var fac [MAX]int
var a [N]int
var prod [N]int
var seg [NN*2]int
var ans [Q]int

func modify(l, r, x int) {
  l += NN-1
  r += NN-1
  for ; l < r; {
    if (l%2 == 0) {
      seg[l] = int(int64(seg[l]) * int64(x) % MOD);
    }
    if (r%2 == 0) {
      r--;
      seg[r] = int(int64(seg[r]) * int64(x) % MOD);
    }
    l >>= 1;
    r >>= 1;
  }
}

func query(i int) int {
  r := 1;
  for i += NN-1; ; {
    r = int(int64(r) * int64(seg[i]) % MOD);
    if (i==0) {break;}
    i = ((i-1) >> 1);
  }
  return r;
}

func inv(x int) int {
  r := 1;
  for ; x > 1; x = MOD % x {
    r = int(int64(r) * int64(-MOD/x) % MOD)
  }
  return (r+MOD)%MOD;
}


Please notice the unusual memory limit of this problem.Orac likes games. Recently he came up with the new game, "Game of Life".You should play this game on a black and white grid with $$$n$$$ rows and $$$m$$$ columns. Each cell is either black or white.For each iteration of the game (the initial iteration is $$$0$$$), the color of each cell will change under the following rules: If there are no adjacent cells with the same color as this cell on the current iteration, the color of it on the next iteration will be the same. Otherwise, the color of the cell on the next iteration will be different.Two cells are adjacent if they have a mutual edge.Now Orac has set an initial situation, and he wants to know for the cell $$$(i,j)$$$ (in $$$i$$$-th row and $$$j$$$-th column), what will be its color at the iteration $$$p$$$. He may ask you these questions several times.

The first line contains three integers $$$n,m,t\ (1\le n,m\le 1000, 1\le t\le 100\,000)$$$, representing the number of rows, columns, and the number of Orac queries. Each of the following $$$n$$$ lines contains a binary string of length $$$m$$$, the $$$j$$$-th character in $$$i$$$-th line represents the initial color of cell $$$(i,j)$$$. '0' stands for white, '1' stands for black. Each of the following $$$t$$$ lines contains three integers $$$i,j,p\ (1\le i\le n, 1\le j\le m, 1\le p\le 10^{18})$$$, representing a query from Orac.

Print $$$t$$$ lines, in $$$i$$$-th line you should print the answer to the $$$i$$$-th query by Orac. If the color of this cell is black, you should print '1'; otherwise, you should write '0'.

Note  For the first example, the picture above shows the initial situation and the color of cells at the iteration $$$1$$$, $$$2$$$, and $$$3$$$. We can see that the color of $$$(1,1)$$$ at the iteration $$$1$$$ is black, the color of $$$(2,2)$$$ at the iteration $$$2$$$ is black, and the color of $$$(3,3)$$$ at the iteration $$$3$$$ is also black.For the second example, you can prove that the cells will never change their colors.

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1350E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := [...]pair{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}

	var n, m, t, x, y int
	var p int64
	Fscan(in, &n, &m, &t)
	g := make([][]byte, n)
	dep := make([][]int, n)
	for i := range g {
		Fscan(in, &g[i])
		dep[i] = make([]int, m)
	}
	q := []pair{}
	for i, row := range g {
		for j, b := range row {
			for _, d := range dir4 {
				if x, y := i+d.x, j+d.y; x >= 0 && x < n && y >= 0 && y < m && g[x][y] == b {
					dep[i][j] = 1
					q = append(q, pair{i, j})
					break
				}
			}
		}
	}
	for len(q) > 0 {
		p := q[0]
		q = q[1:]
		for _, d := range dir4 {
			if x, y := p.x+d.x, p.y+d.y; x >= 0 && x < n && y >= 0 && y < m && dep[x][y] == 0 {
				dep[x][y] = dep[p.x][p.y] + 1
				q = append(q, pair{x, y})
			}
		}
	}
	for ; t > 0; t-- {
		Fscan(in, &x, &y, &p)
		c := g[x-1][y-1] - '0'
		d := dep[x-1][y-1]
		if d == 0 {
			Fprintln(out, c)
			continue
		}
		p -= int64(d - 1)
		if p <= 0 {
			Fprintln(out, c)
		} else {
			Fprintln(out, byte(p&1)^c)
		}
	}
}

func main() { CF1350E(os.Stdin, os.Stdout) }