Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process queries of the following type: "Given string s, determine if the memory of the mechanism contains string t that consists of the same number of characters as s and differs from s in exactly one position".Watto has already compiled the mechanism, all that's left is to write a program for it and check it on the data consisting of n initial lines and m queries. He decided to entrust this job to you.

The first line contains two non-negative numbers n and m (0 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) — the number of the initial strings and the number of queries, respectively. Next follow n non-empty strings that are uploaded to the memory of the mechanism. Next follow m non-empty strings that are the queries to the mechanism. The total length of lines in the input doesn't exceed 6·105. Each line consists only of letters 'a', 'b', 'c'.

For each query print on a single line "YES" (without the quotes), if the memory of the mechanism contains the required string, otherwise print "NO" (without the quotes).

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)

	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)

	words := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &words[i])
	}

	t, lookupIndex := makeBloomFilter(words)

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	for i := 0; i < m; i++ {
		var s string
		fmt.Fscanf(r, "%s\n", &s)

		if _, ok := t[len(s)]; ok == false {
			fmt.Fprintf(w, "NO\n")
			continue
		}

		h1 := rollingHash(s, 17, 1e9+7)
		h2 := rollingHash(s, 11, 998244353)

		p17 := make([]int64, len(s))
		p11 := make([]int64, len(s))

		p17[0], p11[0] = 1, 1
		for j := 1; j < len(s); j++ {
			p17[j] = (p17[j-1] * 17) % (1e9 + 7)
			p11[j] = (p11[j-1] * 11) % 998244353
		}

		found := false
		for j := 0; j < len(s) && !found; j++ {
			for ch := byte('a'); ch <= 'c'; ch++ {
				if ch == s[j] {
					continue
				}

				diff := int64(int(ch) - int(s[j]))
				a1 := (h1 + p17[j]*diff + 10*(1e9+7)) % (1e9 + 7)
				a2 := (h2 + p11[j]*diff + 10*998244353) % 998244353

				h := merge(a1, a2)
				if _, ok := t[len(s)][h]; ok == false {
					continue
				}
				for k, _ := range lookupIndex[h] {
					if eq(s, words[k]) {
						found = true
						break
					}
				}
			}
		}

		if found {
			fmt.Fprintf(w, "YES\n")
		} else {
			fmt.Fprintf(w, "NO\n")
		}
	}
}

func eq(s, t string) bool {
	if len(s) != len(t) {
		return false
	}
	for i := 0; i < len(s); i++ {
		if s[i] != t[i] {
			return true
		}
	}
	return false
}

func makeBloomFilter(words []string) (map[int]map[int64]bool, map[int64]map[int]bool) {
	t := make(map[int]map[int64]bool)
	idx := make(map[int64]map[int]bool)
	for i, w := range words {
		if _, ok := t[len(w)]; ok == false {
			t[len(w)] = make(map[int64]bool)
		}
		h1 := rollingHash(w, 17, 1e9+7)
		h2 := rollingHash(w, 11, 998244353)
		h := merge(h1, h2)
		t[len(w)][h] = true
		if idx[h] == nil {
			idx[h] = make(map[int]bool)
		}
		idx[h][i] = true
	}
	return t, idx
}

func merge(a, b int64) int64 {
	return a*(1e9+9) + b
}

func rollingHash(s string, b, mod int64) int64 {
	cur := int64(0)
	for i := len(s) - 1; i >= 0; i-- {
		d := int64(s[i] - 'a' + 1)
		cur = (cur*b + d) % mod
	}
	return cur
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	ooo := make(map[uint64]bool)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		ooo[hash([]byte(a[i]))] = true
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
	}
	for i := 0; i < m; i++ {
		var j int
		qq := false
		hh := hash([]byte(b[i]))
		for j = 0; j < len(b[i]); j++ {
			for _, v := range "abc" {
				if b[i][j] != byte(v) {
					hhh := hh ^ (pow(j+5) * uint64(b[i][j]))
					hhh ^= (pow(j+5) * uint64(v))
					if _, exists := ooo[hhh]; exists {
						O("YES", "\n")
						j = len(b[i])
						qq = true
						break
					}
				}
			}
		}
		if !qq {
			O("NO", "\n")
		}
	}
}

func hash(s []byte) uint64 {
	h := uint64(11111111111111111011)
	for i := 0; i < len(s); i++ {
		h ^= (pow(i+5) * uint64(s[i]))
	}
	return h
}

var A uint64 = 1e9 + 7
var pp [2000020]uint64

func pow(a int) uint64 {
	if a == 1 {
		return uint64(17)
	}
	if a == 0 {
		return 1
	}
	if pp[a] == 0 {
		pp[a] = (uint64(17) * pow(a-1)) % A
	}
	return pp[a]
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	ooo := make(map[uint64]bool)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		ooo[hash([]byte(a[i]))] = true
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
	}
	for i := 0; i < m; i++ {
		var j int
		qq := false
		hh := hash([]byte(b[i]))
		for j = 0; j < len(b[i]); j++ {
			for _, v := range "abc" {
				if b[i][j] != byte(v) {
					hhh := hh ^ (pow(j+5) * uint64(b[i][j]))
					hhh ^= (pow(j+5) * uint64(v))
					if _, exists := ooo[hhh]; exists {
						O("YES", "\n")
						j = len(b[i])
						qq = true
						break
					}
				}
			}
		}
		if !qq {
			O("NO", "\n")
		}
	}
}

func hash(s []byte) uint64 {
	h := A
	for i := 0; i < len(s); i++ {
		h ^= (pow(i+5) * uint64(s[i]))
	}
	return h
}

var A uint64 = 11111111111111111011
var pp [2000020]uint64

func pow(a int) uint64 {
	a %= len(pp)
	if a == 1 {
		return uint64(1117)
	}
	if a == 0 {
		return 1
	}
	if pp[a] == 0 {
		pp[a] = (uint64(1117) * pow(a-1)) % A
	}
	return pp[a]
}

package main

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

var (
	base      = uint64(257)
	base2     = uint64(311)
	maxN      = int(1e7)
	mod       = uint64(1e9 + 7)
	powerBase = make([]uint64, maxN)
	hashed    = make([]uint64, maxN)
	hashes    = map[uint64]bool{}
	letters   = []byte{'a', 'b', 'c'}
)

func solve(s string, n int) bool {
	var newHash uint64
	originalHash := hash2(hash(s, len(s)))

	for i := range s {
		for j := range letters {
			if letters[j] != s[i] {
				newHash = ((originalHash-hash2(uint64(s[i])*powerBase[n-1-i])+mod*mod)%mod + hash2(uint64(letters[j])*powerBase[n-1-i])) % mod
				if hashes[newHash] {
					return true
				}
			}
		}
	}

	return false
}

func hash2(h uint64) uint64 {
	return h * base2 % mod
}

func initPowerBase() {
	powerBase[0] = 1

	for i := 1; i < maxN; i++ {
		powerBase[i] = powerBase[i-1] * base % mod
	}
}

func hash(s string, n int) uint64 {
	hashed[0] = uint64(s[0])

	for i := 1; i < n; i++ {
		hashed[i] = (hashed[i-1]*base + uint64(s[i])) % mod
	}

	return hashed[n-1]
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	var s string
	initPowerBase()

	fmt.Fscanf(r, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		hashes[hash2(hash(s, len(s)))] = true
	}

	for i := 0; i < m; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		found := solve(s, len(s))
		if found {
			fmt.Fprintf(os.Stdout, "%s\n", "YES")
		} else {
			fmt.Fprintf(os.Stdout, "%s\n", "NO")
		}
	}
}

package main

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

var (
	base      = uint64(257)
	maxN      = int(1e7)
	mod       = uint64(1e9 + 7)
	powerBase = make([]uint64, maxN)
	hashed    = make([]uint64, maxN)
	hashes    = map[uint64]bool{}
	letters   = []byte{'a', 'b', 'c'}
)

func solve(s string, n int) bool {
	var newHash uint64
	originalHash := hash(s, len(s))

	for i := range s {
		for j := range letters {
			if letters[j] != s[i] {
				newHash = ((originalHash-uint64(s[i])*powerBase[n-1-i]+mod*mod)%mod + uint64(letters[j])*powerBase[n-1-i]) % mod
				if hashes[newHash] {
					return true
				}
			}
		}
	}

	return false
}

func initPowerBase() {
	powerBase[0] = 1

	for i := 1; i < maxN; i++ {
		powerBase[i] = powerBase[i-1] * base % mod
	}
}

func hash(s string, n int) uint64 {
	hashed[0] = uint64(s[0])

	for i := 1; i < n; i++ {
		hashed[i] = (hashed[i-1]*base + uint64(s[i])) % mod
	}

	return hashed[n-1]
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	var s string
	initPowerBase()

	fmt.Fscanf(r, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		hashes[hash(s, len(s))] = true
	}

	for i := 0; i < m; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		found := solve(s, len(s))
		if found {
			fmt.Fprintf(os.Stdout, "%s\n", "YES")
		} else {
			fmt.Fprintf(os.Stdout, "%s\n", "NO")
		}
	}
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)

	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)

	words := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &words[i])
	}

	t := makeBloomFilter(words)

	fmt.Println(t)

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	for i := 0; i < m; i++ {
		var s string
		fmt.Fscanf(r, "%s\n", &s)

		if _, ok := t[len(s)]; ok == false {
			fmt.Fprintf(w, "NO\n")
			continue
		}

		h1 := skipHashes(s, 4, int64(1e9)+7)
		h2 := skipHashes(s, 17, int64(1e9)+9)
		h3 := skipHashes(s, 256, 998244353)
		found := false
		for j := 0; j < len(h1); j++ {
			if t[len(s)][h1[j]] && t[len(s)][h2[j]] && t[len(s)][h3[j]] {
				found = true
				break
			}
		}

		if found {
			fmt.Fprintf(w, "YES\n")
		} else {
			fmt.Fprintf(w, "NO\n")
		}
	}
}

func makeBloomFilter(words []string) map[int]map[int64]bool {
	t := make(map[int]map[int64]bool)
	for _, w := range words {
		if _, ok := t[len(w)]; ok == false {
			t[len(w)] = make(map[int64]bool)
		}
		for _, h := range skipHashes(w, 4, int64(1e9)+7) {
			t[len(w)][h] = true
		}
		for _, h := range skipHashes(w, 17, int64(1e9)+9) {
			t[len(w)][h] = true
		}
		for _, h := range skipHashes(w, 256, 998244353) {
			t[len(w)][h] = true
		}
	}
	return t
}

func skipHashes(s string, b, mod int64) []int64 {
	suff := make([]int64, len(s))
	cur := int64(0)
	for i := len(s) - 1; i >= 0; i-- {
		suff[i] = (cur*b + int64(s[i]-'a'+1)) % mod
		cur = suff[i]
	}

	pws := make([]int64, len(s))
	pws[0] = 1
	for i := 1; i < len(s); i++ {
		pws[i] = (pws[i-1] * b) % mod
	}

	var skips []int64

	pref := int64(0)
	for i := 0; i < len(s); i++ {
		skipHash := pref
		if i+1 < len(s) {
			skipHash += (suff[i+1] * pws[i]) % mod
			skipHash %= mod
		}
		skips = append(skips, skipHash)
		pref = (pref + pws[i]*int64(s[i]-'a'+1)) % mod
	}

	return skips
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)

	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)

	words := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &words[i])
	}

	t := MakeFingerprints(words)

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	for i := 0; i < m; i++ {
		var s string
		fmt.Fscanf(r, "%s\n", &s)

		if _, ok := t[len(s)]; ok == false {
			fmt.Fprintf(w, "NO\n")
			continue
		}

		h1s := skipHashes(s, 4, int64(1e9)+7)
		h2s := skipHashes(s, 17, int64(1e9)+9)
		h3s := skipHashes(s, 256, int64(1e9)+9)
		found := false
		for j := 0; j < len(h1s); j++ {
			if t[len(s)][h1s[j]] && t[len(s)][h2s[j]] && t[len(s)][h3s[j]] {
				found = true
				break
			}
		}

		if found {
			fmt.Fprintf(w, "YES\n")
		} else {
			fmt.Fprintf(w, "NO\n")
		}
	}
}

func MakeFingerprints(words []string) map[int]map[int64]bool {
	t := make(map[int]map[int64]bool)
	for _, w := range words {
		if _, ok := t[len(w)]; ok == false {
			t[len(w)] = make(map[int64]bool)
		}
		for _, h := range skipHashes(w, 4, int64(1e9)+7) {
			t[len(w)][h] = true
		}
		for _, h := range skipHashes(w, 17, int64(1e9)+9) {
			t[len(w)][h] = true
		}
		for _, h := range skipHashes(w, 256, int64(1e9)+9) {
			t[len(w)][h] = true
		}
	}
	return t
}

func skipHashes(s string, b, mod int64) []int64 {
	suff := make([]int64, len(s))
	cur := int64(0)
	for i := len(s) - 1; i >= 0; i-- {
		suff[i] = (cur*b + int64(s[i]-'a'+1)) % mod
		cur = suff[i]
	}

	pws := make([]int64, len(s))
	pws[0] = 1
	for i := 1; i < len(s); i++ {
		pws[i] = (pws[i-1] * b) % mod
	}

	var skips []int64

	pref := int64(0)
	for i := 0; i < len(s); i++ {
		skipHash := pref
		if i+1 < len(s) {
			skipHash += (suff[i+1] * pws[i]) % mod
			skipHash %= mod
		}
		skips = append(skips, skipHash)
		pref = (pref + pws[i]*int64(s[i]-'a'+1)) % mod
	}

	return skips
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)

	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)

	words := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &words[i])
	}

	t := MakeFingerprints(words)

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	for i := 0; i < m; i++ {
		var s string
		fmt.Fscanf(r, "%s\n", &s)

		if _, ok := t[len(s)]; ok == false {
			fmt.Fprintf(w, "NO\n")
			continue
		}

		h1s := skipHashes(s, 4, int64(1e9)+7)
		h2s := skipHashes(s, 17, int64(1e9)+9)
		found := false
		for j := 0; j < len(h1s); j++ {
			if t[len(s)][h1s[j]] && t[len(s)][h2s[j]] {
				found = true
				break
			}
		}

		if found {
			fmt.Fprintf(w, "YES\n")
		} else {
			fmt.Fprintf(w, "NO\n")
		}
	}
}

func MakeFingerprints(words []string) map[int]map[int64]bool {
	t := make(map[int]map[int64]bool)
	for _, w := range words {
		if _, ok := t[len(w)]; ok == false {
			t[len(w)] = make(map[int64]bool)
		}
		for _, h := range skipHashes(w, 4, int64(1e9)+7) {
			t[len(w)][h] = true
		}
		for _, h := range skipHashes(w, 17, int64(1e9)+9) {
			t[len(w)][h] = true
		}
	}
	return t
}

func skipHashes(s string, b, mod int64) []int64 {
	suff := make([]int64, len(s))
	cur := int64(0)
	for i := len(s) - 1; i >= 0; i-- {
		suff[i] = (cur*b + int64(s[i]-'a')) % mod
		cur = suff[i]
	}

	pws := make([]int64, len(s))
	pws[0] = 1
	for i := 1; i < len(s); i++ {
		pws[i] = (pws[i-1] * b) % mod
	}

	var skips []int64

	pref := int64(0)
	for i := 0; i < len(s); i++ {
		skipHash := pref
		if i+1 < len(s) {
			skipHash += (suff[i+1] * pws[i]) % mod
			skipHash %= mod
			skips = append(skips, skipHash)
		}
		pref = (pref + pws[i]*int64(s[i]-'a')) % mod
	}

	return skips
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)

	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)

	words := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &words[i])
	}

	t := makeBloomFilter(words)
	// fmt.Println(t)

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	for i := 0; i < m; i++ {
		var s string
		fmt.Fscanf(r, "%s\n", &s)

		if _, ok := t[len(s)]; ok == false {
			fmt.Fprintf(w, "NO\n")
			continue
		}

		h1 := skipHashes(s, 17, int64(1e9)+7)
		h2 := skipHashes(s, 11, 998244353)
		found := false
		for j := 0; j < len(h1); j++ {
			if t[len(s)][merge(h1[j], h2[j])] {
				found = true
				break
			}
		}

		if found {
			fmt.Fprintf(w, "YES\n")
		} else {
			fmt.Fprintf(w, "NO\n")
		}
	}
}

func makeBloomFilter(words []string) map[int]map[int64]bool {
	t := make(map[int]map[int64]bool)
	for _, w := range words {
		if _, ok := t[len(w)]; ok == false {
			t[len(w)] = make(map[int64]bool)
		}
		h1 := skipHashes(w, 17, int64(1e9)+7)
		h2 := skipHashes(w, 11, 998244353)
		for j := 0; j < len(h1); j++ {
			// fmt.Printf("IDX(%d) [%d] [%d] -> %d\n", j, h1[j], h2[j], merge(h1[j], h2[j]))
			t[len(w)][merge(h1[j], h2[j])] = true
		}
	}
	return t
}

func merge(a, b int64) int64 {
	return a*(1e9+9) + b
}

func skipHashes(s string, b, mod int64) []int64 {
	suff := make([]int64, len(s))
	cur := int64(0)
	for i := len(s) - 1; i >= 0; i-- {
		d := int64(s[i] - 'a' + 1)
		suff[i] = (cur*b + d*d) % mod
		cur = suff[i]
	}

	// fmt.Println(suff)

	pws := make([]int64, len(s))
	pws[0] = 1
	for i := 1; i < len(s); i++ {
		pws[i] = (pws[i-1] * b) % mod
	}

	var skips []int64

	pref := int64(0)
	for i := 0; i < len(s); i++ {
		skipHash := pref
		if i+1 < len(s) {
			skipHash += (suff[i+1] * pws[i]) % mod
			skipHash %= mod
		}
		skips = append(skips, skipHash)
		d := int64(s[i] - 'a' + 1)
		pref = (pref + pws[i]*d*d) % mod
	}

	return skips
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)

	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)

	words := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &words[i])
	}

	t, lookupIndex := makeBloomFilter(words)

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	for i := 0; i < m; i++ {
		var s string
		fmt.Fscanf(r, "%s\n", &s)

		if _, ok := t[len(s)]; ok == false {
			fmt.Fprintf(w, "NO\n")
			continue
		}

		h1 := skipHashes(s, 17, int64(1e9)+7)
		h2 := skipHashes(s, 11, 998244353)
		found := false
		for j := 0; j < len(h1); j++ {
			h := merge(h1[j], h2[j])
			if _, ok := t[len(s)][h]; ok == false {
				continue
			}
			for k, _ := range lookupIndex[h] {
				if eq(s, words[k]) {
					found = true
					break
				}
			}
			if found {
				break
			}
		}

		if found {
			fmt.Fprintf(w, "YES\n")
		} else {
			fmt.Fprintf(w, "NO\n")
		}
	}
}

func eq(s, t string) bool {
	if len(s) != len(t) {
		return false
	}
	for i := 0; i < len(s); i++ {
		if s[i] != t[i] {
			return true
		}
	}
	return false
}

func makeBloomFilter(words []string) (map[int]map[int64]bool, map[int64]map[int]bool) {
	t := make(map[int]map[int64]bool)
	idx := make(map[int64]map[int]bool)
	for i, w := range words {
		if _, ok := t[len(w)]; ok == false {
			t[len(w)] = make(map[int64]bool)
		}
		h1 := skipHashes(w, 17, int64(1e9)+7)
		h2 := skipHashes(w, 11, 998244353)
		for j := 0; j < len(h1); j++ {
			h := merge(h1[j], h2[j])
			t[len(w)][h] = true
			if idx[h] == nil {
				idx[h] = make(map[int]bool)
			}
			idx[h][i] = true
		}
	}
	return t, idx
}

func merge(a, b int64) int64 {
	return a*(1e9+9) + b
}

func skipHashes(s string, b, mod int64) []int64 {
	suff := make([]int64, len(s))
	cur := int64(0)
	for i := len(s) - 1; i >= 0; i-- {
		d := int64(s[i] - 'a' + 1)
		suff[i] = (cur*b + d*d) % mod
		cur = suff[i]
	}

	pws := make([]int64, len(s))
	pws[0] = 1
	for i := 1; i < len(s); i++ {
		pws[i] = (pws[i-1] * b) % mod
	}

	var skips []int64

	pref := int64(0)
	for i := 0; i < len(s); i++ {
		skipHash := pref
		if i+1 < len(s) {
			skipHash += (suff[i+1] * pws[i]) % mod
			skipHash %= mod
		}
		skips = append(skips, skipHash)
		d := int64(s[i] - 'a' + 1)
		pref = (pref + pws[i]*d*d) % mod
	}

	return skips
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)

	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)

	words := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &words[i])
	}

	t := MakeFingerprints(words)

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	for i := 0; i < m; i++ {
		var s string
		fmt.Fscanf(r, "%s\n", &s)

		if _, ok := t[len(s)]; ok == false {
			fmt.Fprintf(w, "NO\n")
			continue
		}

		h1s := skipHashes(s, 4, int64(1e9)+7)
		h2s := skipHashes(s, 17, int64(1e9)+9)
		found := false
		for j := 0; j < len(h1s); j++ {
			if t[len(s)][h1s[j]] && t[len(s)][h2s[j]] {
				found = true
				break
			}
		}

		if found {
			fmt.Fprintf(w, "YES\n")
		} else {
			fmt.Fprintf(w, "NO\n")
		}
	}
}

func MakeFingerprints(words []string) map[int]map[int64]bool {
	t := make(map[int]map[int64]bool)
	for _, w := range words {
		if _, ok := t[len(w)]; ok == false {
			t[len(w)] = make(map[int64]bool)
		}
		for _, h := range skipHashes(w, 4, int64(1e9)+7) {
			t[len(w)][h] = true
		}
		for _, h := range skipHashes(w, 17, int64(1e9)+9) {
			t[len(w)][h] = true
		}
	}
	return t
}

func skipHashes(s string, b, mod int64) []int64 {
	suff := make([]int64, len(s))
	cur := int64(0)
	for i := len(s) - 1; i >= 0; i-- {
		suff[i] = (cur*b + int64(s[i]-'a'+1)) % mod
		cur = suff[i]
	}

	pws := make([]int64, len(s))
	pws[0] = 1
	for i := 1; i < len(s); i++ {
		pws[i] = (pws[i-1] * b) % mod
	}

	var skips []int64

	pref := int64(0)
	for i := 0; i < len(s); i++ {
		skipHash := pref
		if i+1 < len(s) {
			skipHash += (suff[i+1] * pws[i]) % mod
			skipHash %= mod
		}
		skips = append(skips, skipHash)
		pref = (pref + pws[i]*int64(s[i]-'a'+1)) % mod
	}

	return skips
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	ooo := make(map[uint64]bool)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		ooo[hash([]byte(a[i]))] = true
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
	}
	for i := 0; i < m; i++ {
		var j int
		for j = 0; j < len(b[i]); j++ {
			t := []byte(b[i])
			for _, v := range "abc" {
				if b[i][j] != byte(v) {
					t[j] = byte(v)
					if _, exists := ooo[hash(t)]; exists {
						O("YES", "\n")
						j = len(b[i])
						break
					}
				}
			}
		}
		if j == len(b[i]) {
			O("NO", "\n")
		}
	}
}

var A uint64 = 77777777977777777

func hash(s []byte) uint64 {
	h := uint64(len(s)) ^ uint64(9576890767)
	for i := 0; i < len(s); i++ {
		h += (pow(i%17) * uint64(s[i])) % A
		h %= A
	}
	return h
}

var pp [20]uint64

func pow(a int) uint64 {
	if a == 1 {
		return uint64(7)
	}
	if a == 0 {
		return 1
	}
	if pp[a] == 0 {
		pp[a] = uint64(7) * pow(a-1)
	}
	return pp[a]
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	ooo := make(map[string]string)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		ooo[a[i]] = a[i]
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
	}
	for i := 0; i < m; i++ {
		var j int
		for j = 0; j < len(b[i]); j++ {
			t := []byte(b[i])
			t[j] = 'a'
			if _, exists := ooo[string(t)]; exists {
				O("YES", "\n")
				break
			}
			t[j] = 'b'
			if _, exists := ooo[string(t)]; exists {
				O("YES", "\n")
				break
			}
			t[j] = 'c'
			if _, exists := ooo[string(t)]; exists {
				O("YES", "\n")
				break
			}
		}
		if j == len(b[i]) {
			O("NO", "\n")
		}
	}
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	bb := make([]string, m)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
	}
	ans := make(map[string]string)
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
		bb[i] = b[i]
		ans[b[i]] = "NO"
	}
	sort.Strings(bb)
	for i := 0; i < n; i++ {
		for j := 0; j < len(a[i]); j++ {
			t := []byte(a[i])
			t[j] = 'a'
			o := sort.SearchStrings(bb, string(t))
			if o < len(bb) && bb[o] == string(t) {
				ans[bb[o]] = "YES"
				bb = append(bb[:o], bb[o+1:]...)
			}
			t[j] = 'b'
			o = sort.SearchStrings(bb, string(t))
			if o < len(bb) && bb[o] == string(t) {
				ans[bb[o]] = "YES"
				bb = append(bb[:o], bb[o+1:]...)
			}
			t[j] = 'c'
			o = sort.SearchStrings(bb, string(t))
			if o < len(bb) && bb[o] == string(t) {
				ans[bb[o]] = "YES"
				bb = append(bb[:o], bb[o+1:]...)
			}
		}
	}
	for i := 0; i < m; i++ {
		O(ans[b[i]], "\n")
	}
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	ooo := make(map[string]bool)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		ooo[hash(a[i])] = true
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
	}
	for i := 0; i < m; i++ {
		var j int
		for j = 0; j < len(b[i]); j++ {
			t := []byte(b[i])
			for _, v := range "abc" {
				if b[i][j] != byte(v) {
					t[j] = byte(v)
					if _, exists := ooo[hash(string(t))]; exists {
						O("YES", "\n")
						j = len(b[i])
						break
					}
				}
			}

		}
		if j == len(b[i]) {
			O("NO", "\n")
		}
	}
}

func hash(s string) string {
	ss := make([]byte, 16)
	for i, v := range s {
		ss[i%16] = byte((int(v)*(1e5+7)>>7 + int(s[len(s)-1-i])) % 255)
	}
	return string(ss)
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

type node struct {
	childs map[byte]*node
	isLeaf bool
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	t := &node{make(map[byte]*node), false}
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		t.add(a[i])
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
		if res, o := t.query(b[i], 0); res && o == 1 {
			O("YES", "\n")
		} else {
			O("NO", "\n")
		}
	}
}

func (t *node) add(s string) {
	if len(s) == 0 {
		t.isLeaf = true
		return
	}
	if _, exists := t.childs[s[0]]; !exists {
		t.childs[s[0]] = &node{make(map[byte]*node), false}
	}
	t.childs[s[0]].add(s[1:])
}

func (t *node) query(s string, o int) (bool, int) {
	if len(s) == 0 {
		return t.isLeaf, o
	}
	if o <= 1 {
		for _, v := range "abc" {
			if p, exists := t.childs[byte(v)]; exists {
				oo := o
				if byte(v) != s[0] {
					oo++
				}
				q, oo := p.query(s[1:], oo)
				if q && oo <= 1 {
					return q, oo
				}
			}
		}
	}
	return false, 0
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	ooo := make(map[uint64]bool)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		ooo[hash([]byte(a[i]))] = true
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
	}
	for i := 0; i < m; i++ {
		var j int
		qq := false
		hh := hash([]byte(b[i]))
		for j = 0; j < len(b[i]); j++ {
			for _, v := range "abc" {
				if b[i][j] != byte(v) {
					hhh := hh ^ (pow(j) * uint64(b[i][j]))
					hhh ^= (pow(j) * uint64(v))
					if _, exists := ooo[hhh]; exists {
						O("YES", "\n")
						j = len(b[i])
						qq = true
						break
					}
				}
			}
		}
		if !qq {
			O("NO", "\n")
		}
	}
}

func hash(s []byte) uint64 {
	h := uint64(len(s)) ^ uint64(77777777977777777)
	for i := 0; i < len(s); i++ {
		h ^= (pow(i) * uint64(s[i]))
	}
	return h
}

var A uint64 = 1e9 + 7
var pp [2000020]uint64

func pow(a int) uint64 {
	if a == 1 {
		return uint64(7)
	}
	if a == 0 {
		return 1
	}
	if pp[a] == 0 {
		pp[a] = (uint64(7) * pow(a-1)) % A
	}
	return pp[a]
}

package main

import (
	"bufio"
	"crypto/md5"
	"encoding/binary"
	"fmt"
	"io"
	"os"
)

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	ooo := make(map[uint16]bool)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		ooo[hash(a[i])] = true
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
	}
	for i := 0; i < m; i++ {
		var j int
		for j = 0; j < len(b[i]); j++ {
			t := []byte(b[i])
			for _, v := range "abc" {
				if b[i][j] != byte(v) {
					t[j] = byte(v)
					if _, exists := ooo[hash(string(t))]; exists {
						O("YES", "\n")
						j = len(b[i])
						break
					}
				}
			}
		}
		if j == len(b[i]) {
			O("NO", "\n")
		}
	}
}

func hash(s string) uint16 {
	h := md5.New()
	io.WriteString(h, s)
	return binary.BigEndian.Uint16(h.Sum(nil)[:4])
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	bb := make([]string, m)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
	}
	ans := make(map[string]string)
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
		bb[i] = b[i]
		ans[b[i]] = "NO"
	}
	sort.Strings(bb)
	for i := 0; i < n; i++ {
		for j := 0; j < len(a[i]); j++ {
			t := []byte(a[i])
			t[j] = 'a'
			o := sort.SearchStrings(bb, string(t))
			if o < len(bb) && bb[o] == string(t) {
				ans[bb[o]] = "YES"
				bb = append(bb[:o], bb[o+1:]...)
				i--
				break
			}
			t[j] = 'b'
			o = sort.SearchStrings(bb, string(t))
			if o < len(bb) && bb[o] == string(t) {
				ans[bb[o]] = "YES"
				bb = append(bb[:o], bb[o+1:]...)
				i--
				break
			}
			t[j] = 'c'
			o = sort.SearchStrings(bb, string(t))
			if o < len(bb) && bb[o] == string(t) {
				ans[bb[o]] = "YES"
				bb = append(bb[:o], bb[o+1:]...)
				i--
				break
			}
		}
	}
	for i := 0; i < m; i++ {
		O(ans[b[i]], "\n")
	}
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	ooo := make(map[string]bool)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		ooo[hash(a[i])] = true
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
	}
	for i := 0; i < m; i++ {
		var j int
		for j = 0; j < len(b[i]); j++ {
			t := []byte(b[i])
			if b[i][j] != 'a' {
				t[j] = 'a'
				if _, exists := ooo[hash(string(t))]; exists {
					O("YES", "\n")
					break
				}
			}
			if b[i][j] != 'b' {
				t[j] = 'b'
				if _, exists := ooo[hash(string(t))]; exists {
					O("YES", "\n")
					break
				}
			}
			if b[i][j] != 'c' {
				t[j] = 'c'
				if _, exists := ooo[hash(string(t))]; exists {
					O("YES", "\n")
					break
				}
			}
		}
		if j == len(b[i]) {
			O("NO", "\n")
		}
	}
}

func hash(s string) string {
	ss := make([]byte, 32)
	for i, v := range s {
		ss[i%32] = byte(((int(v)*(1e9+7))>>7 + int(s[len(s)-1-i])>>7) % 255)
	}
	return string(ss)
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	bb := make([]string, m)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
	}
	ans := make(map[string]string)
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
		bb[i] = b[i]
		ans[b[i]] = "NO"
	}
	sort.Strings(bb)
	for i := 0; i < n; i++ {
		for j := 0; j < len(a[i]); j++ {
			t := []byte(a[i])
			t[j] = 'a'
			o := sort.SearchStrings(bb, string(t))
			if o < len(b) && bb[o] == string(t) {
				ans[bb[o]] = "YES"
				break
			}
			t[j] = 'b'
			o = sort.SearchStrings(bb, string(t))
			if o < len(b) && bb[o] == string(t) {
				ans[bb[o]] = "YES"
				break
			}
			t[j] = 'c'
			o = sort.SearchStrings(bb, string(t))
			if o < len(b) && bb[o] == string(t) {
				ans[bb[o]] = "YES"
				break
			}
		}
	}
	for i := 0; i < m; i++ {
		O(ans[b[i]], "\n")
	}
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	ooo := make(map[uint32]bool)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		ooo[hash([]byte(a[i]))] = true
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
	}
	for i := 0; i < m; i++ {
		var j int
		for j = 0; j < len(b[i]); j++ {
			t := []byte(b[i])
			for _, v := range "abc" {
				if b[i][j] != byte(v) {
					t[j] = byte(v)
					if _, exists := ooo[hash(t)]; exists {
						O("YES", "\n")
						j = len(b[i])
						break
					}
				}
			}
		}
		if j == len(b[i]) {
			O("NO", "\n")
		}
	}
}

func hash(s []byte) uint32 {
	h := uint32(17)
	for i := 0; i < len(s); i++ {
		h += h*fib(i%1000) + uint32(s[i])
		h %= uint32(1e9 + 7)
	}
	return h
}

var fi [1000]uint32

func fib(n int) uint32 {
	if n == 0 || n == 1 {
		return 1
	}
	if fi[n] == 0 {
		fi[n] = fib(n-1) + fib(n-2)
	}
	return fi[n]
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

type node struct {
	childs map[byte]*node
	isLeaf bool
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	t := &node{make(map[byte]*node), false}
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		t.add(a[i])
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
		if res, o := t.query(b[i], 0); res && o == 1 {
			O("YES", "\n")
		} else {
			O("NO", "\n")
		}
	}
}

func (t *node) add(s string) {
	if len(s) == 0 {
		t.isLeaf = true
		return
	}
	if _, exists := t.childs[s[0]]; !exists {
		t.childs[s[0]] = &node{make(map[byte]*node), false}
	}
	t.childs[s[0]].add(s[1:])
}

func (t *node) query(s string, o int) (bool, int) {
	if len(s) == 0 {
		return t.isLeaf, o
	}
	qq := string(s[0]) + strings.Trim("abc", string(s[0]))
	if o <= 1 {
		for _, v := range qq {
			if p, exists := t.childs[byte(v)]; exists {
				oo := o
				if byte(v) != s[0] {
					oo++
				}
				q, oo := p.query(s[1:], oo)
				if q && oo <= 1 {
					return q, oo
				}
			}
		}
	}
	return false, o
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	bb := make([]string, m)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
	}
	ans := make(map[string]string)
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
		bb[i] = b[i]
		ans[b[i]] = "NO"
	}
	sort.Strings(bb)
	for i := 0; i < n; i++ {
		for j := 0; j < len(a[i]); j++ {
			t := []byte(a[i])
			t[j] = 'a'
			o := sort.SearchStrings(bb, string(t))
			if o < len(bb) && bb[o] == string(t) {
				ans[bb[o]] = "YES"
			}
			t[j] = 'b'
			o = sort.SearchStrings(bb, string(t))
			if o < len(bb) && bb[o] == string(t) {
				ans[bb[o]] = "YES"
			}
			t[j] = 'c'
			o = sort.SearchStrings(bb, string(t))
			if o < len(bb) && bb[o] == string(t) {
				ans[bb[o]] = "YES"
			}
		}
	}
	for i := 0; i < m; i++ {
		O(ans[b[i]], "\n")
	}
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	ooo := make(map[uint32]bool)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		ooo[hash([]byte(a[i]))] = true
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
	}
	for i := 0; i < m; i++ {
		var j int
		for j = 0; j < len(b[i]); j++ {
			t := []byte(b[i])
			for _, v := range "abc" {
				if b[i][j] != byte(v) {
					t[j] = byte(v)
					if _, exists := ooo[hash(t)]; exists {
						O("YES", "\n")
						j = len(b[i])
						break
					}
				}
			}
		}
		if j == len(b[i]) {
			O("NO", "\n")
		}
	}
}

func hash(s []byte) uint32 {
	h := uint32(17)
	for i := 0; i < len(s); i++ {
		h += h*fib(i%100) + uint32(s[i])
		h %= uint32(1e9 + 7)
	}
	return h
}

var fi [100]uint32

func fib(n int) uint32 {
	if n == 0 || n == 1 {
		return 1
	}
	if fi[n] == 0 {
		fi[n] = fib(n-1) + fib(n-2)
	}
	return fi[n]
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	ooo := make(map[string]bool)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		ooo[hash(a[i])] = true
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
	}
	for i := 0; i < m; i++ {
		var j int
		for j = 0; j < len(b[i]); j++ {
			t := []byte(b[i])
			for _, v := range "abc" {
				if b[i][j] != byte(v) {
					t[j] = byte(v)
					if _, exists := ooo[hash(string(t))]; exists {
						O("YES", "\n")
						j = len(b[i])
						break
					}
				}
			}
		}
		if j == len(b[i]) {
			O("NO", "\n")
		}
	}
}

func hash(s string) string {
	ss := make([]byte, 64)
	for i, v := range s {
		ss[i%64] = byte((int(v)*(1e3+7)<<3*(i+1) + int(v)<<2 + int(s[len(s)-1-i])<<2*(i+1)) % 255)
	}
	return string(ss)
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	ooo := make(map[uint32]bool)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		ooo[hash([]byte(a[i]))] = true
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
	}
	for i := 0; i < m; i++ {
		var j int
		for j = 0; j < len(b[i]); j++ {
			t := []byte(b[i])
			for _, v := range "abc" {
				if b[i][j] != byte(v) {
					t[j] = byte(v)
					if _, exists := ooo[hash(t)]; exists {
						O("YES", "\n")
						j = len(b[i])
						break
					}
				}
			}
		}
		if j == len(b[i]) {
			O("NO", "\n")
		}
	}
}

func hash(s []byte) uint32 {
	h := uint32(17)
	for i := 0; i < len(s); i++ {
		h += h*fib(i%1000) + uint32(s[i])
		h %= uint32(4*1e9 + 7)
	}
	return h
}

var fi [1000]uint32

func fib(n int) uint32 {
	if n == 0 || n == 1 {
		return 1
	}
	if fi[n] == 0 {
		fi[n] = fib(n-1) + fib(n-2)
	}
	return fi[n]
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	ooo := make(map[uint64]bool)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		ooo[hash([]byte(a[i]))] = true
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
	}
	for i := 0; i < m; i++ {
		var j int
		qq := false
		hh := hash([]byte(b[i]))
		for j = 0; j < len(b[i]); j++ {
			for _, v := range "abc" {
				if b[i][j] != byte(v) {
					hhh := hh
					hhh -= (pow(j) * uint64(b[i][j])) % A
					hhh += (pow(j) * uint64(v)) % A
					hhh %= A
					if _, exists := ooo[hhh]; exists {
						O("YES", "\n")
						j = len(b[i])
						qq = true
						break
					}
				}
			}
		}
		if !qq {
			O("NO", "\n")
		}
	}
}

var A uint64 = 77777777977777777

func hash(s []byte) uint64 {
	h := uint64(len(s)) ^ uint64(9576890767)
	for i := 0; i < len(s); i++ {
		h += (pow(i) * uint64(s[i])) % A
		h %= A
	}
	return h
}

var pp [2000020]uint64

func pow(a int) uint64 {
	if a == 1 {
		return uint64(3)
	}
	if a == 0 {
		return 1
	}
	if pp[a] == 0 {
		pp[a] = (uint64(3) * pow(a-1)) % A
	}
	return pp[a]
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	ooo := make(map[uint64]bool)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		ooo[hash([]byte(a[i]))] = true
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
	}
	for i := 0; i < m; i++ {
		var j int
		qq := false
		hh := hash([]byte(b[i]))
		for j = 0; j < len(b[i]); j++ {
			for _, v := range "abc" {
				if b[i][j] != byte(v) {
					hhh := hh ^ (pow(j%13) * uint64(b[i][j]))
					hhh ^= (pow(j%13) * uint64(v))
					if _, exists := ooo[hhh]; exists {
						O("YES", "\n")
						j = len(b[i])
						qq = true
						break
					}
				}
			}
		}
		if !qq {
			O("NO", "\n")
		}
	}
}

func hash(s []byte) uint64 {
	h := uint64(len(s)) ^ uint64(77777777977777777)
	for i := 0; i < len(s); i++ {
		h ^= (pow(i%13) * uint64(s[i]))
	}
	return h
}

var pp [30]uint64

func pow(a int) uint64 {
	if a == 1 {
		return uint64(5)
	}
	if a == 0 {
		return 1
	}
	if pp[a] == 0 {
		pp[a] = (uint64(5) * pow(a-1))
	}
	return pp[a]
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	bb := make([]string, m)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
	}
	ans := make(map[string]string)
	ooo := make(map[string]string)
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
		bb[i] = b[i]
		ans[b[i]] = "NO"
		ooo[b[i]] = b[i]
	}
	sort.Strings(bb)
	for i := 0; i < n; i++ {
		for j := 0; j < len(a[i]); j++ {
			t := []byte(a[i])
			t[j] = 'a'
			if _, exists := ooo[string(t)]; exists {
				ans[string(t)] = "YES"
			}
			t[j] = 'b'
			if _, exists := ooo[string(t)]; exists {
				ans[string(t)] = "YES"
			}
			t[j] = 'c'
			if _, exists := ooo[string(t)]; exists {
				ans[string(t)] = "YES"
			}
		}
	}
	for i := 0; i < m; i++ {
		O(ans[b[i]], "\n")
	}
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	ooo := make(map[uint64]bool)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		ooo[hash([]byte(a[i]))] = true
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
	}
	for i := 0; i < m; i++ {
		var j int
		qq := false
		hh := hash([]byte(b[i]))
		for j = 0; j < len(b[i]); j++ {
			for _, v := range "abc" {
				if b[i][j] != byte(v) {
					hhh := hh
					hhh -= (pow(j%17) * uint64(b[i][j])) % A
					hhh += (pow(j%17) * uint64(v)) % A
					hhh %= A
					if _, exists := ooo[hhh]; exists {
						O("YES", "\n")
						j = len(b[i])
						qq = true
						break
					}
				}
			}
		}
		if !qq {
			O("NO", "\n")
		}
	}
}

var A uint64 = 77777777977777777

func hash(s []byte) uint64 {
	h := uint64(len(s)) ^ uint64(9576890767)
	for i := 0; i < len(s); i++ {
		h += (pow(i%17) * uint64(s[i])) % A
		h %= A
	}
	return h
}

var pp [20]uint64

func pow(a int) uint64 {
	if a == 1 {
		return uint64(7)
	}
	if a == 0 {
		return 1
	}
	if pp[a] == 0 {
		pp[a] = uint64(7) * pow(a-1)
	}
	return pp[a]
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	ooo := make(map[uint64]bool)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		ooo[hash([]byte(a[i]))] = true
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
	}
	for i := 0; i < m; i++ {
		var j int
		qq := false
		hh := hash([]byte(b[i]))
		for j = 0; j < len(b[i]); j++ {
			for _, v := range "abc" {
				if b[i][j] != byte(v) {
					hhh := hh
					hhh -= (pow(j) * uint64(b[i][j])) % A
					hhh += (pow(j) * uint64(v)) % A
					hhh %= A
					if _, exists := ooo[hhh]; exists {
						O("YES", "\n")
						j = len(b[i])
						qq = true
						break
					}
				}
			}
		}
		if !qq {
			O("NO", "\n")
		}
	}
}

var A uint64 = 9576890767

func hash(s []byte) uint64 {
	h := uint64(len(s)) ^ uint64(77777777977777777)
	for i := 0; i < len(s); i++ {
		h += (pow(i) * uint64(s[i])) % A
		h %= A
	}
	return h
}

var pp [2000020]uint64

func pow(a int) uint64 {
	if a == 1 {
		return uint64(13)
	}
	if a == 0 {
		return 1
	}
	if pp[a] == 0 {
		pp[a] = (uint64(13) * pow(a-1)) % A
	}
	return pp[a]
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	a := make([]string, n)
	b := make([]string, m)
	ooo := make(map[uint64]bool)
	for i := 0; i < n; i++ {
		I(&a[i], "\n")
		ooo[hash([]byte(a[i]))] = true
	}
	for i := 0; i < m; i++ {
		I(&b[i], "\n")
	}
	for i := 0; i < m; i++ {
		var j int
		hh := hash([]byte(b[i]))
		for j = 0; j < len(b[i]); j++ {
			t := []byte(b[i])
			for _, v := range "abc" {
				if b[i][j] != byte(v) {
					hhh := hh ^ (uint64(77777777977777777) ^ (fib(3+j%7) * uint64(v))) ^ (uint64(77777777977777777) ^ (fib(3+j%7) * uint64(t[j])))
					t[j] = byte(v)
					if _, exists := ooo[hhh]; exists {
						O("YES", "\n")
						j = len(b[i])
						break
					}
				}
			}
		}
		if j == len(b[i]) {
			O("NO", "\n")
		}
	}
}

func hash(s []byte) uint64 {
	h := uint64(9576890767)
	for i := 0; i < len(s); i++ {
		h ^= uint64(77777777977777777) ^ (fib(3+i%7) * uint64(s[i]))
	}
	return h
}

var fi [50]uint64

func fib(n int) uint64 {
	if n == 0 || n == 1 {
		return 1
	}
	if fi[n] == 0 {
		fi[n] = fib(n-1) + fib(n-2)
	}
	return fi[n]
}

package main

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

var (
	base      = uint64(191)
	maxN      = int(1e7)
	mod       = uint64(1e9 + 7)
	powerBase = make([]uint64, maxN)
	hashed    = make([]uint64, maxN)
	hashes    = map[uint64]bool{}
	letters   = []byte{'a', 'b', 'c'}
)

func solve(s string, n int) bool {
	var newHash uint64
	originalHash := hash(s, len(s))

	for i := range s {
		for j := range letters {
			if letters[j] != s[i] {
				newHash = ((originalHash-uint64(s[i])*powerBase[n-1-i]+mod*mod)%mod + uint64(letters[j])*powerBase[n-1-i]) % mod
				if hashes[newHash] {
					return true
				}
			}
		}
	}

	return false
}

func initPowerBase() {
	powerBase[0] = 1

	for i := 1; i < maxN; i++ {
		powerBase[i] = powerBase[i-1] * base % mod
	}
}

func hash(s string, n int) uint64 {
	hashed[0] = uint64(s[0])

	for i := 1; i < n; i++ {
		hashed[i] = (hashed[i-1]*base + uint64(s[i])) % mod
	}

	return hashed[n-1]
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	var s string
	initPowerBase()

	fmt.Fscanf(r, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		hashes[hash(s, len(s))] = true
	}

	for i := 0; i < m; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		found := solve(s, len(s))
		if found {
			fmt.Fprintf(os.Stdout, "%s\n", "YES")
		} else {
			fmt.Fprintf(os.Stdout, "%s\n", "NO")
		}
	}
}

package main

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

var (
	base      = uint64(65537)
	maxN      = int(1e7)
	mod       = uint64(1e9 + 7)
	powerBase = make([]uint64, maxN)
	hashed    = make([]uint64, maxN)
	hashes    = map[uint64]bool{}
	letters   = []byte{'a', 'b', 'c'}
)

func solve(s string, n int) bool {
	var newHash uint64
	originalHash := hash(s, len(s))

	for i := range s {
		for j := range letters {
			if letters[j] != s[i] {
				newHash = ((originalHash-uint64(s[i])*powerBase[n-1-i]+mod*mod)%mod + uint64(letters[j])*powerBase[n-1-i]) % mod
				if hashes[newHash] {
					return true
				}
			}
		}
	}

	return false
}

func initPowerBase() {
	powerBase[0] = 1

	for i := 1; i < maxN; i++ {
		powerBase[i] = powerBase[i-1] * base % mod
	}
}

func hash(s string, n int) uint64 {
	hashed[0] = uint64(s[0])

	for i := 1; i < n; i++ {
		hashed[i] = (hashed[i-1]*base + uint64(s[i])) % mod
	}

	return hashed[n-1]
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	var s string
	initPowerBase()

	fmt.Fscanf(r, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		hashes[hash(s, len(s))] = true
	}

	for i := 0; i < m; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		found := solve(s, len(s))
		if found {
			fmt.Fprintf(os.Stdout, "%s\n", "YES")
		} else {
			fmt.Fprintf(os.Stdout, "%s\n", "NO")
		}
	}
}

package main

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

var (
	base      = uint64(191)
	maxN      = int(1e7)
	mod       = uint64(1e9 + 7)
	powerBase = make([]uint64, maxN)
	hashed    = make([]uint64, maxN)
	hashes    = map[uint64]bool{}
	letters   = []byte{'a', 'b', 'c'}
)

func solve(s string, n int) bool {
	var newHash uint64
	originalHash := hash(s, len(s))

	if hashes[originalHash] {
		return true
	}

	for i := range s {
		for j := range letters {
			newHash = originalHash - uint64(s[i])*powerBase[n-1-i] + uint64(letters[j])*powerBase[n-1-i]
			if hashes[newHash] {
				return true
			}
		}
	}

	return false
}

func initPowerBase() {
	powerBase[0] = 1

	for i := 1; i < maxN; i++ {
		powerBase[i] = powerBase[i-1] * base % mod
	}
}

func hash(s string, n int) uint64 {
	hashed[0] = uint64(s[0])

	for i := 1; i < n; i++ {
		hashed[i] = (hashed[i-1]*base + uint64(s[i])) % mod
	}

	return hashed[n-1]
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	var s string
	initPowerBase()

	fmt.Fscanf(r, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		hashes[hash(s, len(s))] = true
	}

	for i := 0; i < m; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		found := solve(s, len(s))
		if found {
			fmt.Fprintf(os.Stdout, "%s\n", "YES")
		} else {
			fmt.Fprintf(os.Stdout, "%s\n", "NO")
		}
	}
}

package main

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

var (
	base      = uint64(251)
	maxN      = int(1e7)
	mod       = uint64(1e9 + 7)
	powerBase = make([]uint64, maxN)
	hashed    = make([]uint64, maxN)
	hashes    = map[uint64]bool{}
	letters   = []byte{'a', 'b', 'c'}
)

func solve(s string, n int) bool {
	var newHash uint64
	originalHash := hash(s, len(s))

	for i := range s {
		for j := range letters {
			if letters[j] != s[i] {
				newHash = ((originalHash-uint64(s[i])*powerBase[n-1-i]+mod*mod)%mod + uint64(letters[j])*powerBase[n-1-i]) % mod
				if hashes[newHash] {
					return true
				}
			}
		}
	}

	return false
}

func initPowerBase() {
	powerBase[0] = 1

	for i := 1; i < maxN; i++ {
		powerBase[i] = powerBase[i-1] * base % mod
	}
}

func hash(s string, n int) uint64 {
	hashed[0] = uint64(s[0])

	for i := 1; i < n; i++ {
		hashed[i] = (hashed[i-1]*base + uint64(s[i])) % mod
	}

	return hashed[n-1]
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	var s string
	initPowerBase()

	fmt.Fscanf(r, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		hashes[hash(s, len(s))] = true
	}

	for i := 0; i < m; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		found := solve(s, len(s))
		if found {
			fmt.Fprintf(os.Stdout, "%s\n", "YES")
		} else {
			fmt.Fprintf(os.Stdout, "%s\n", "NO")
		}
	}
}

package main

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

var (
	base      = uint64(378551)
	maxN      = int(1e7)
	mod       = uint64(1e9 + 7)
	powerBase = make([]uint64, maxN)
	hashed    = make([]uint64, maxN)
	hashes    = map[uint64]bool{}
	letters   = []byte{'a', 'b', 'c'}
)

func solve(s string, n int) bool {
	var newHash uint64
	originalHash := hash(s, len(s))

	for i := range s {
		for j := range letters {
			if letters[j] != s[i] {
				newHash = ((originalHash-uint64(s[i])*powerBase[n-1-i]+mod*mod)%mod + uint64(letters[j])*powerBase[n-1-i]) % mod
				if hashes[newHash] {
					return true
				}
			}
		}
	}

	return false
}

func initPowerBase() {
	powerBase[0] = 1

	for i := 1; i < maxN; i++ {
		powerBase[i] = powerBase[i-1] * base % mod
	}
}

func hash(s string, n int) uint64 {
	hashed[0] = uint64(s[0])

	for i := 1; i < n; i++ {
		hashed[i] = (hashed[i-1]*base + uint64(s[i])) % mod
	}

	return hashed[n-1]
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	var s string
	initPowerBase()

	fmt.Fscanf(r, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		hashes[hash(s, len(s))] = true
	}

	for i := 0; i < m; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		found := solve(s, len(s))
		if found {
			fmt.Fprintf(os.Stdout, "%s\n", "YES")
		} else {
			fmt.Fprintf(os.Stdout, "%s\n", "NO")
		}
	}
}

package main

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

var (
	base      = uint64(251)
	base2     = uint64(311)
	maxN      = int(1e7)
	mod       = uint64(1e9 + 7)
	powerBase = make([]uint64, maxN)
	hashed    = make([]uint64, maxN)
	hashes    = map[uint64]bool{}
	letters   = []byte{'a', 'b', 'c'}
)

func solve(s string, n int) bool {
	var newHash uint64
	originalHash := hash2(hash(s, len(s)))

	for i := range s {
		for j := range letters {
			if letters[j] != s[i] {
				newHash = ((originalHash-hash2(uint64(s[i])*powerBase[n-1-i])+mod*mod)%mod + hash2(uint64(letters[j])*powerBase[n-1-i])) % mod
				if hashes[newHash] {
					return true
				}
			}
		}
	}

	return false
}

func hash2(h uint64) uint64 {
	return h * base2 % mod
}

func initPowerBase() {
	powerBase[0] = 1

	for i := 1; i < maxN; i++ {
		powerBase[i] = powerBase[i-1] * base % mod
	}
}

func hash(s string, n int) uint64 {
	hashed[0] = uint64(s[0])

	for i := 1; i < n; i++ {
		hashed[i] = (hashed[i-1]*base + uint64(s[i])) % mod
	}

	return hashed[n-1]
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	var s string
	initPowerBase()

	fmt.Fscanf(r, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		hashes[hash2(hash(s, len(s)))] = true
	}

	for i := 0; i < m; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		found := solve(s, len(s))
		if found {
			fmt.Fprintf(os.Stdout, "%s\n", "YES")
		} else {
			fmt.Fprintf(os.Stdout, "%s\n", "NO")
		}
	}
}

package main

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

var (
	base      = uint64(311)
	maxN      = int(1e7)
	mod       = uint64(1e9 + 7)
	powerBase = make([]uint64, maxN)
	hashed    = make([]uint64, maxN)
	hashes    = map[uint64]bool{}
	letters   = []byte{'a', 'b', 'c'}
)

func solve(s string, n int) bool {
	var newHash uint64
	originalHash := hash(s, len(s))

	if hashes[originalHash] {
		return true
	}

	for i := range s {
		for j := range letters {
			newHash = ((originalHash-uint64(s[i])*powerBase[n-1-i]+mod*mod)%mod + uint64(letters[j])*powerBase[n-1-i]) % mod
			if hashes[newHash] {
				return true
			}
		}
	}

	return false
}

func initPowerBase() {
	powerBase[0] = 1

	for i := 1; i < maxN; i++ {
		powerBase[i] = powerBase[i-1] * base % mod
	}
}

func hash(s string, n int) uint64 {
	hashed[0] = uint64(s[0])

	for i := 1; i < n; i++ {
		hashed[i] = (hashed[i-1]*base + uint64(s[i])) % mod
	}

	return hashed[n-1]
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	var s string
	initPowerBase()

	fmt.Fscanf(r, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		hashes[hash(s, len(s))] = true
	}

	for i := 0; i < m; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		found := solve(s, len(s))
		if found {
			fmt.Fprintf(os.Stdout, "%s\n", "YES")
		} else {
			fmt.Fprintf(os.Stdout, "%s\n", "NO")
		}
	}
}

package main

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

var (
	base      = uint64(821)
	maxN      = int(1e7)
	mod       = uint64(1e9 + 7)
	powerBase = make([]uint64, maxN)
	hashed    = make([]uint64, maxN)
	hashes    = map[uint64]bool{}
	letters   = []byte{'a', 'b', 'c'}
)

func solve(s string, n int) bool {
	var newHash uint64
	originalHash := hash(s, len(s))

	for i := range s {
		for j := range letters {
			if letters[j] != s[i] {
				newHash = ((originalHash-uint64(s[i])*powerBase[n-1-i]+mod*mod)%mod + uint64(letters[j])*powerBase[n-1-i]) % mod
				if hashes[newHash] {
					return true
				}
			}
		}
	}

	return false
}

func initPowerBase() {
	powerBase[0] = 1

	for i := 1; i < maxN; i++ {
		powerBase[i] = powerBase[i-1] * base % mod
	}
}

func hash(s string, n int) uint64 {
	hashed[0] = uint64(s[0])

	for i := 1; i < n; i++ {
		hashed[i] = (hashed[i-1]*base + uint64(s[i])) % mod
	}

	return hashed[n-1]
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	var s string
	initPowerBase()

	fmt.Fscanf(r, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		hashes[hash(s, len(s))] = true
	}

	for i := 0; i < m; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		found := solve(s, len(s))
		if found {
			fmt.Fprintf(os.Stdout, "%s\n", "YES")
		} else {
			fmt.Fprintf(os.Stdout, "%s\n", "NO")
		}
	}
}

package main

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

var (
	base      = uint64(1999)
	maxN      = int(1e7)
	mod       = uint64(1e9 + 7)
	powerBase = make([]uint64, maxN)
	hashed    = make([]uint64, maxN)
	hashes    = map[uint64]bool{}
	letters   = []byte{'a', 'b', 'c'}
)

func solve(s string, n int) bool {
	var newHash uint64
	originalHash := hash(s, len(s))

	for i := range s {
		for j := range letters {
			if letters[j] != s[i] {
				newHash = ((originalHash-uint64(s[i])*powerBase[n-1-i]+mod*mod)%mod + uint64(letters[j])*powerBase[n-1-i]) % mod
				if hashes[newHash] {
					return true
				}
			}
		}
	}

	return false
}

func initPowerBase() {
	powerBase[0] = 1

	for i := 1; i < maxN; i++ {
		powerBase[i] = powerBase[i-1] * base % mod
	}
}

func hash(s string, n int) uint64 {
	hashed[0] = uint64(s[0])

	for i := 1; i < n; i++ {
		hashed[i] = (hashed[i-1]*base + uint64(s[i])) % mod
	}

	return hashed[n-1]
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	var s string
	initPowerBase()

	fmt.Fscanf(r, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		hashes[hash(s, len(s))] = true
	}

	for i := 0; i < m; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		found := solve(s, len(s))
		if found {
			fmt.Fprintf(os.Stdout, "%s\n", "YES")
		} else {
			fmt.Fprintf(os.Stdout, "%s\n", "NO")
		}
	}
}

package main

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

var (
	base      = uint64(311)
	maxN      = int(1e7)
	mod       = uint64(1e9 + 7)
	powerBase = make([]uint64, maxN)
	hashed    = make([]uint64, maxN)
	hashes    = map[uint64]bool{}
	letters   = []byte{'a', 'b', 'c'}
)

func solve(s string, n int) bool {
	var newHash uint64
	originalHash := hash(s, len(s))

	for i := range s {
		for j := range letters {
			if letters[j] != s[i] {
				newHash = ((originalHash-uint64(s[i])*powerBase[n-1-i]+mod*mod)%mod + uint64(letters[j])*powerBase[n-1-i]) % mod
				if hashes[newHash] {
					return true
				}
			}
		}
	}

	return false
}

func initPowerBase() {
	powerBase[0] = 1

	for i := 1; i < maxN; i++ {
		powerBase[i] = powerBase[i-1] * base % mod
	}
}

func hash(s string, n int) uint64 {
	hashed[0] = uint64(s[0])

	for i := 1; i < n; i++ {
		hashed[i] = (hashed[i-1]*base + uint64(s[i])) % mod
	}

	return hashed[n-1]
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	var s string
	initPowerBase()

	fmt.Fscanf(r, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		hashes[hash(s, len(s))] = true
	}

	for i := 0; i < m; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		found := solve(s, len(s))
		if found {
			fmt.Fprintf(os.Stdout, "%s\n", "YES")
		} else {
			fmt.Fprintf(os.Stdout, "%s\n", "NO")
		}
	}
}

package main

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

var (
	base      = uint64(191)
	maxN      = int(1e7)
	mod       = uint64(1e9 + 7)
	powerBase = make([]uint64, maxN)
	hashed    = make([]uint64, maxN)
	hashes    = map[uint64]bool{}
	letters   = []byte{'a', 'b', 'c'}
)

func solve(s string, n int) bool {
	var newHash uint64
	originalHash := hash(s, len(s))

	if hashes[originalHash] {
		return true
	}

	for i := range s {
		for j := range letters {
			newHash = ((originalHash-uint64(s[i])*powerBase[n-1-i]+mod*mod)%mod + uint64(letters[j])*powerBase[n-1-i]) % mod
			if hashes[newHash] {
				return true
			}
		}
	}

	return false
}

func initPowerBase() {
	powerBase[0] = 1

	for i := 1; i < maxN; i++ {
		powerBase[i] = powerBase[i-1] * base % mod
	}
}

func hash(s string, n int) uint64 {
	hashed[0] = uint64(s[0])

	for i := 1; i < n; i++ {
		hashed[i] = (hashed[i-1]*base + uint64(s[i])) % mod
	}

	return hashed[n-1]
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	var s string
	initPowerBase()

	fmt.Fscanf(r, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		hashes[hash(s, len(s))] = true
	}

	for i := 0; i < m; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		found := solve(s, len(s))
		if found {
			fmt.Fprintf(os.Stdout, "%s\n", "YES")
		} else {
			fmt.Fprintf(os.Stdout, "%s\n", "NO")
		}
	}
}

package main

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

var (
	base      = uint64(311)
	base2     = uint64(1999)
	maxN      = int(1e7)
	mod       = uint64(1e9 + 7)
	powerBase = make([]uint64, maxN)
	hashed    = make([]uint64, maxN)
	hashes    = map[uint64]bool{}
	letters   = []byte{'a', 'b', 'c'}
)

func solve(s string, n int) bool {
	var newHash uint64
	originalHash := hash2(hash(s, len(s)))

	for i := range s {
		for j := range letters {
			if letters[j] != s[i] {
				newHash = ((originalHash-hash2(uint64(s[i])*powerBase[n-1-i])+mod*mod)%mod + hash2(uint64(letters[j])*powerBase[n-1-i])) % mod
				if hashes[newHash] {
					return true
				}
			}
		}
	}

	return false
}

func hash2(h uint64) uint64 {
	return h * base2 % mod
}

func initPowerBase() {
	powerBase[0] = 1

	for i := 1; i < maxN; i++ {
		powerBase[i] = powerBase[i-1] * base % mod
	}
}

func hash(s string, n int) uint64 {
	hashed[0] = uint64(s[0])

	for i := 1; i < n; i++ {
		hashed[i] = (hashed[i-1]*base + uint64(s[i])) % mod
	}

	return hashed[n-1]
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	var s string
	initPowerBase()

	fmt.Fscanf(r, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		hashes[hash2(hash(s, len(s)))] = true
	}

	for i := 0; i < m; i++ {
		fmt.Fscanf(r, "%s\n", &s)
		found := solve(s, len(s))
		if found {
			fmt.Fprintf(os.Stdout, "%s\n", "YES")
		} else {
			fmt.Fprintf(os.Stdout, "%s\n", "NO")
		}
	}
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)

	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)

	words := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%s\n", &words[i])
	}

	t := makeBloomFilter(words)

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	for i := 0; i < m; i++ {
		var s string
		fmt.Fscanf(r, "%s\n", &s)

		if _, ok := t[len(s)]; ok == false {
			fmt.Fprintf(w, "NO\n")
			continue
		}

		h1 := skipHashes(s, 4, int64(1e9)+7)
		h2 := skipHashes(s, 17, int64(1e9)+9)
		h3 := skipHashes(s, 256, 998244353)
		found := false
		for j := 0; j < len(h1); j++ {
			if t[len(s)][h1[j]] && t[len(s)][h2[j]] && t[len(s)][h3[j]] {
				found = true
				break
			}
		}

		if found {
			fmt.Fprintf(w, "YES\n")
		} else {
			fmt.Fprintf(w, "NO\n")
		}
	}
}

func makeBloomFilter(words []string) map[int]map[int64]bool {
	t := make(map[int]map[int64]bool)
	for _, w := range words {
		if _, ok := t[len(w)]; ok == false {
			t[len(w)] = make(map[int64]bool)
		}
		for _, h := range skipHashes(w, 4, int64(1e9)+7) {
			t[len(w)][h] = true
		}
		for _, h := range skipHashes(w, 17, int64(1e9)+9) {
			t[len(w)][h] = true
		}
		for _, h := range skipHashes(w, 256, 998244353) {
			t[len(w)][h] = true
		}
	}
	return t
}

func skipHashes(s string, b, mod int64) []int64 {
	suff := make([]int64, len(s))
	cur := int64(0)
	for i := len(s) - 1; i >= 0; i-- {
		suff[i] = (cur*b + int64(s[i]-'a'+1)) % mod
		cur = suff[i]
	}

	pws := make([]int64, len(s))
	pws[0] = 1
	for i := 1; i < len(s); i++ {
		pws[i] = (pws[i-1] * b) % mod
	}

	var skips []int64

	pref := int64(0)
	for i := 0; i < len(s); i++ {
		skipHash := pref
		if i+1 < len(s) {
			skipHash += (suff[i+1] * pws[i]) % mod
			skipHash %= mod
		}
		skips = append(skips, skipHash)
		pref = (pref + pws[i]*int64(s[i]-'a'+1)) % mod
	}

	return skips
}


Lunar New Year is approaching, and Bob is struggling with his homework – a number division problem.There are $$$n$$$ positive integers $$$a_1, a_2, \ldots, a_n$$$ on Bob's homework paper, where $$$n$$$ is always an even number. Bob is asked to divide those numbers into groups, where each group must contain at least $$$2$$$ numbers. Suppose the numbers are divided into $$$m$$$ groups, and the sum of the numbers in the $$$j$$$-th group is $$$s_j$$$. Bob's aim is to minimize the sum of the square of $$$s_j$$$, that is $$$$$$\sum_{j = 1}^{m} s_j^2.$$$$$$Bob is puzzled by this hard problem. Could you please help him solve it?

The first line contains an even integer $$$n$$$ ($$$2 \leq n \leq 3 \cdot 10^5$$$), denoting that there are $$$n$$$ integers on Bob's homework paper. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^4$$$), describing the numbers you need to deal with.

A single line containing one integer, denoting the minimum of the sum of the square of $$$s_j$$$, which is $$$$$$\sum_{i = j}^{m} s_j^2,$$$$$$ where $$$m$$$ is the number of groups.

NoteIn the first sample, one of the optimal solutions is to divide those $$$4$$$ numbers into $$$2$$$ groups $$$\{2, 8\}, \{5, 3\}$$$. Thus the answer is $$$(2 + 8)^2 + (5 + 3)^2 = 164$$$.In the second sample, one of the optimal solutions is to divide those $$$6$$$ numbers into $$$3$$$ groups $$$\{1, 2\}, \{1, 2\}, \{1, 2\}$$$. Thus the answer is $$$(1 + 2)^2 + (1 + 2)^2 + (1 + 2)^2 = 27$$$.

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var result int64
	var n int
	fmt.Fscan(in, &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}
	sort.Ints(a)
	for i := 0; i < n/2; i++ {
		result += (int64(a[i]) + int64(a[n-i-1])) * (int64(a[i]) + int64(a[n-i-1]))
	}
	fmt.Println(result)
}

package main

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

type Int []int

func (m Int) Less(i, j int) bool {
	return m[i] <= m[j]
}
func (m Int) Swap(a, b int) {
	tmp := m[a]
	m[a] = m[b]
	m[b] = tmp
}
func (m Int) Len() int {
	return len(m)
}
func main() {
	buf := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscanf(buf, "%d\n", &n)
	mat := make(Int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &mat[i])
	}
	sort.Sort(mat)
	res := int64(0)
	for i := 0;i < n-i-1;i++{
		tmp := int64(mat[i])+int64(mat[n-i-1])
		res += tmp*tmp
	}
	fmt.Printf("%d\n",res)
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	var vs = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &vs[i])
	}
	sort.Ints(vs)
	var ans int64
	for i := 0; i < n/2; i++ {
		ans += sqr(vs[i] + vs[n-i-1])
	}
	fmt.Println(ans)
}

func sqr(x int) int64 {
	return int64(x) * int64(x)
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(reader, &n)

	hw := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &hw[i])
	}

	sort.Ints(hw)
	var count int64
	for i := 0; i < n/2; i++ {
		count += int64(math.Pow(float64(hw[i]+hw[n-i-1]), 2.00))
	}

	fmt.Println(count)
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()
	var n int
	var t1, ans int64
	arr := []int{}
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		scanf("%d ", &t1)
		arr = append(arr, int(t1))
	}
	sort.Ints(arr)
	for i := 0; i < n/2; i++ {
		t1 = int64(arr[i] + arr[n-i-1])
		t1 *= t1
		ans += t1
	}
	printf("%d", ans)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, res int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	for i := 0; i < n/2; i++ {
		res += (a[i] + a[n-i-1]) * (a[i] + a[n-i-1])
	}
	fmt.Println(res)
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(reader, &n)

	hw := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &hw[i])
	}

	sort.Ints(hw)
	var count float64
	for i := 0; i < n/2; i++ {
		count += math.Pow(float64(hw[i]+hw[n-i-1]), 2.00)
	}

	fmt.Println(count)
}


One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online full hd free". This got Polycarp confused — what if he decides to rewatch the entire series someday and won't be able to find the right episodes to watch? Polycarp now wants to count the number of times he will be forced to search for an episode using some different method.TV series have n seasons (numbered 1 through n), the i-th season has ai episodes (numbered 1 through ai). Polycarp thinks that if for some pair of integers x and y (x < y) exist both season x episode y and season y episode x then one of these search queries will include the wrong results. Help Polycarp to calculate the number of such pairs!

The first line contains one integer n (1  ≤ n  ≤  2·105) — the number of seasons. The second line contains n integers separated by space a1, a2, ..., an (1 ≤ ai ≤ 109) — number of episodes in each season.

Print one integer — the number of pairs x and y (x < y) such that there exist both season x episode y and season y episode x.

NotePossible pairs in the second example:  x = 1, y = 2 (season 1 episode 2  season 2 episode 1);  x = 2, y = 3 (season 2 episode 3  season 3 episode 2);  x = 1, y = 3 (season 1 episode 3  season 3 episode 1). In the third example:  x = 1, y = 2 (season 1 episode 2  season 2 episode 1);  x = 1, y = 3 (season 1 episode 3  season 3 episode 1).

package main

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

type stNode struct {
	l, r int
	vals []int
}
type segmentTree []stNode

func (t segmentTree) _pushUp(o int) []int {
	a, b := t[o<<1].vals, t[o<<1|1].vals
	i, n := 0, len(a)
	j, m := 0, len(b)
	res := make([]int, 0, n+m)
	for {
		if i == n {
			return append(res, b[j:]...)
		}
		if j == m {
			return append(res, a[i:]...)
		}
		if a[i] < b[j] {
			res = append(res, a[i])
			i++
		} else {
			res = append(res, b[j])
			j++
		}
	}
}

func (t segmentTree) _build(arr []int, o, l, r int) {
	t[o].l, t[o].r = l, r
	if l == r {
		t[o].vals = []int{arr[l-1]}
		return
	}
	m := (l + r) >> 1
	t._build(arr, o<<1, l, m)
	t._build(arr, o<<1|1, m+1, r)
	t[o].vals = t._pushUp(o)
}

func (t segmentTree) _query(o, l, r, x int) (res int) {
	if l <= t[o].l && t[o].r <= r {
		a := t[o].vals
		return len(a) - sort.SearchInts(a, x)
	}
	m := (t[o].l + t[o].r) >> 1
	if l <= m {
		res += t._query(o<<1, l, r, x)
	}
	if r > m {
		res += t._query(o<<1|1, l, r, x)
	}
	return
}

func (t segmentTree) init(arr []int)        { t._build(arr, 1, 1, len(arr)) }
func (t segmentTree) query(l, r, x int) int { return t._query(1, l, r, x) }

// github.com/EndlessCheng/codeforces-go
func CF961E(_r io.Reader, _w io.Writer) {
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}

	t := make(segmentTree, 4*n)
	t.init(a)
	ans := int64(0)
	for i, v := range a[:n-1] {
		if v > i+1 {
			ans += int64(t.query(i+2, min(v, n), i+1))
		}
	}
	Fprint(out, ans)
}

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

package main

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

const (
	MaxN = 1 << 18
)

type pos struct {
	val, index, sortIndex int64
}

var n, ans int64
var idx [MaxN]int64
var a [MaxN]pos
var b [MaxN]int64

func ask(k int64) int64 {
	return query(n) - query(k - 1)
}

func query(pos int64) int64 {
	cnt := int64(0)
	for pos > 0 {
		cnt += idx[pos]
		pos -= pos & -pos
	}
	return cnt
}

func update(pos int64) {
	for pos < MaxN {
		idx[pos]++
		pos += pos & -pos
	}
}

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	for i := int64(0); i < n; i++ {
		fmt.Fscanf(buf, "%d", &a[i].val)
		if a[i].val > n {
			a[i].val = n
		}
		b[i] = a[i].val
		a[i].index = i + 1
		a[i].sortIndex = min(i, a[i].val)
	}
	sort.Slice(a[:n], func(i, j int) bool {
		if a[i].sortIndex < a[j].sortIndex {
			return true
		}
		if a[i].sortIndex > a[j].sortIndex {
			return false
		}
		return a[i].index < a[j].index
	})
	k := int64(0)
	for i := int64(0); i < n; i++ {
		for k < n && a[k].sortIndex <= i {
			ans += ask(a[k].index)
			k++
		}
		update(b[i])
	}
	fmt.Println(ans)
}

package main

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

const (
	MaxN = 1 << 18
)

var n, ans int64
var idx [MaxN]int64

func ask(i int64) int64 {
	return query(n+1) - query(i)
}

func query(pos int64) int64 {
	cnt := int64(0)
	for pos > 0 {
		cnt += idx[pos]
		pos -= pos & -pos
	}
	return cnt
}

func update(pos int64) {
	for pos < MaxN {
		idx[pos]++
		pos += pos & -pos
	}
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	for i := int64(0); i < n; i++ {
		var tmp int64
		fmt.Fscanf(buf, "%d", &tmp)
		if tmp > n {
			tmp = n
		}
		ans += ask(i)
		update(tmp)
	}
	fmt.Println(ans)
}


It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days!When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day.The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is .You should write a program which will calculate average sleep times of Polycarp over all weeks.

The first line contains two integer numbers n and k (1 ≤ k ≤ n ≤ 2·105). The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 105).

Output average sleeping time over all weeks.  The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point.

NoteIn the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7.

package main

import (
	"bufio"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	inp := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	is, err := inp.ReadString('\n')
	if err != nil {
		out.WriteString("-1")
		out.Flush()
		return
	}
	is = strings.TrimRight(is, "\n\r\t ")
	l1 := strings.Split(is, " ")
	if len(l1) != 2 {
		out.WriteString("-2")
		out.Flush()
		return
	}
	n, err := strconv.Atoi(l1[0])
	if err != nil {
		out.WriteString("-3")
		out.Flush()
		return
	}
	k, err := strconv.Atoi(l1[1])
	if err != nil {
		out.WriteString("-4")
		out.Flush()
		return
	}
	is, err = inp.ReadString('\n')
	if err != nil {
		out.WriteString("-5")
		out.Flush()
		return
	}
	is = strings.TrimRight(is, "\n\r\t ")
	l2 := strings.Split(is, " ")
	if len(l2) != n {
		out.WriteString("-6")
		out.Flush()
		return
	}

	sum := int64(0)
	div := n - k + 1
	k = int(math.Min(float64(div), float64(k)))
	lb := k - 1
	rb := n - k
	for i := 0; i < n; i++ {
		a, err := strconv.Atoi(l2[i])
		if err != nil {
			out.WriteString("-7")
			out.Flush()
			return
		}
		if i < lb {
			sum += int64(a) * int64(i+1)
		} else if i > rb {
			k--
			sum += int64(a) * int64(k)
		} else {
			sum += int64(a) * int64(k)
		}
	}
	res := float64(sum) / float64(div)
	out.WriteString(strconv.FormatFloat(res, 'f', 10, 64))
	out.Flush()
}

package main

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

func main() {
	var n, k, tmp int
	var initSumm float64
	var total float64
	fmt.Scanf("%d %d\n", &n, &k)
	answer := make([]float64, n)
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	for i, j := range strings.Split(strings.TrimRight(line, "\n\r\t "), " ") {
		answer[i], _ = strconv.ParseFloat(j, 64)
	}
	tmp = n - k + 1
	for h := 0; h < k; h++ {
		initSumm += answer[h]
	}
	total += initSumm
	for i := 1; i < tmp; i++ {
		initSumm = initSumm - answer[i-1]
		initSumm = initSumm + answer[i+k-1]
		total += initSumm
	}
	fmt.Println(total / float64(tmp))
}

package main

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

func main() {
	var n, k int
	var initSumm float64
	var total, tmp float64
	fmt.Scanf("%d %d\n", &n, &k)
	answer := make([]float64, n)
	summ := make([]float64, n-k+1)
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	for i, j := range strings.Split(strings.TrimRight(line, "\n\r\t "), " ") {
		tmp, _ = strconv.ParseFloat(j, 64)
		answer[i] = tmp
	}
	tmp = float64(n - k + 1)
	for h := 0; h < k; h++ {
		initSumm += answer[h]
	}
	summ[0] = initSumm
	for i := 1; i < (n - k + 1); i++ {
		initSumm = initSumm - answer[i-1]
		initSumm = initSumm + answer[i+k-1]
		summ[i] = initSumm
	}
	for _, j := range summ {
		total += j
	}
	fmt.Println(total / tmp)
}

package main

import (
	"bufio"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	inp := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	is, err := inp.ReadString('\n')
	if err != nil {
		out.WriteString("-1")
		out.Flush()
		return
	}
	is = strings.TrimRight(is, "\n\r\t ")
	l1 := strings.Split(is, " ")
	if len(l1) != 2 {
		out.WriteString("-2")
		out.Flush()
		return
	}
	n, err := strconv.Atoi(l1[0])
	if err != nil {
		out.WriteString("-3")
		out.Flush()
		return
	}
	k, err := strconv.Atoi(l1[1])
	if err != nil {
		out.WriteString("-4")
		out.Flush()
		return
	}
	is, err = inp.ReadString('\n')
	if err != nil {
		out.WriteString("-5")
		out.Flush()
		return
	}
	is = strings.TrimRight(is, "\n\r\t ")
	l2 := strings.Split(is, " ")
	if len(l2) != n {
		out.WriteString("-6")
		out.Flush()
		return
	}

	sum := 0
	div := n - k + 1
	k = int(math.Min(float64(div), float64(k)))
	lb := k - 1
	rb := n - k
	for i := 0; i < n; i++ {
		a, err := strconv.Atoi(l2[i])
		if err != nil {
			out.WriteString("-7")
			out.Flush()
			return
		}
		if i < lb {
			sum += a * (i + 1)
		} else if i > rb {
			k--
			sum += a * k
		} else {
			sum += a * k
		}
	}
	res := float64(sum) / float64(div)
	out.WriteString(strconv.FormatFloat(res, 'f', 10, 64))
	out.Flush()
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
)

func main() {
	inp := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	is, err := inp.ReadString('\n')
	if err != nil {
		out.WriteString("-1")
		out.Flush()
		return
	}
	is = strings.TrimRight(is, "\n\r\t ")
	l1 := strings.Split(is, " ")
	if len(l1) != 2 {
		out.WriteString("-2")
		out.Flush()
		return
	}
	n, err := strconv.Atoi(l1[0])
	if err != nil {
		out.WriteString("-3")
		out.Flush()
		return
	}
	k, err := strconv.Atoi(l1[1])
	if err != nil {
		out.WriteString("-4")
		out.Flush()
		return
	}
	is, err = inp.ReadString('\n')
	if err != nil {
		out.WriteString("-5")
		out.Flush()
		return
	}
	is = strings.TrimRight(is, "\n\r\t ")
	l2 := strings.Split(is, " ")
	if len(l2) != n {
		out.WriteString("-6")
		out.Flush()
		return
	}
	lb := k - 1
	rb := n - k
	sum := 0
	div := float64(n - k + 1)
	for i := 0; i < n; i++ {
		a, err := strconv.Atoi(l2[i])
		if err != nil {
			out.WriteString("-7")
			out.Flush()
			return
		}
		if i < lb {
			sum += a * (i + 1)
		} else if i > rb {
			k--
			sum += a * k
		} else {
			sum += a * k
		}
	}
	res := float64(sum) / div
	out.WriteString(strconv.FormatFloat(res, 'f', 16, 64))
	out.Flush()
}


A plane is flying at a constant height of $$$h$$$ meters above the ground surface. Let's consider that it is flying from the point $$$(-10^9, h)$$$ to the point $$$(10^9, h)$$$ parallel with $$$Ox$$$ axis.A glider is inside the plane, ready to start his flight at any moment (for the sake of simplicity let's consider that he may start only when the plane's coordinates are integers). After jumping from the plane, he will fly in the same direction as the plane, parallel to $$$Ox$$$ axis, covering a unit of distance every second. Naturally, he will also descend; thus his second coordinate will decrease by one unit every second.There are ascending air flows on certain segments, each such segment is characterized by two numbers $$$x_1$$$ and $$$x_2$$$ ($$$x_1 < x_2$$$) representing its endpoints. No two segments share any common points. When the glider is inside one of such segments, he doesn't descend, so his second coordinate stays the same each second. The glider still flies along $$$Ox$$$ axis, covering one unit of distance every second.     If the glider jumps out at $$$1$$$, he will stop at $$$10$$$. Otherwise, if he jumps out at $$$2$$$, he will stop at $$$12$$$. Determine the maximum distance along $$$Ox$$$ axis from the point where the glider's flight starts to the point where his flight ends if the glider can choose any integer coordinate to jump from the plane and start his flight. After touching the ground the glider stops altogether, so he cannot glide through an ascending airflow segment if his second coordinate is $$$0$$$.

The first line contains two integers $$$n$$$ and $$$h$$$ $$$(1 \le n \le 2\cdot10^{5}, 1 \le h \le 10^{9})$$$ — the number of ascending air flow segments and the altitude at which the plane is flying, respectively. Each of the next $$$n$$$ lines contains two integers $$$x_{i1}$$$ and $$$x_{i2}$$$ $$$(1 \le x_{i1} < x_{i2} \le 10^{9})$$$ — the endpoints of the $$$i$$$-th ascending air flow segment. No two segments intersect, and they are given in ascending order.

Print one integer — the maximum distance along $$$Ox$$$ axis that the glider can fly from the point where he jumps off the plane to the point where he lands if he can start his flight at any integer coordinate.

NoteIn the first example if the glider can jump out at $$$(2, 4)$$$, then the landing point is $$$(12, 0)$$$, so the distance is $$$12-2 = 10$$$.In the second example the glider can fly from $$$(16,10)$$$ to $$$(34,0)$$$, and the distance is $$$34-16=18$$$.In the third example the glider can fly from $$$(-100,1000000000)$$$ to $$$(1999999899,0)$$$, so the distance is $$$1999999899-(-100)=1999999999$$$.

package main

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

type segment struct {
	start, end int64
}

var n int
var h int64
var a []segment
var s1, s2 []int64

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d %d\n", &n, &h)
	a := make([]segment, n)
	s1 := make([]int64, n+1)
	s2 := make([]int64, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d %d\n", &a[i].start, &a[i].end)
	}

	s1[0] = 0
	for i := 1; i <= n; i++ {
		s1[i] = s1[i-1] + a[i-1].end - a[i-1].start
	}
	for i := 1; i < n; i++ {
		s2[i] = a[i].start - a[i-1].end + s2[i-1]
	}
	s2[n] = s2[n-1] + h
	ans := int64(0)
	for i := 0; i < n; i++ {
		ind := sort.Search(n, func(index int) bool {
			return s2[index]-s2[i] >= h
		})
		b := s1[ind] - s1[i] + h
		if ans < b {
			ans = b
		}
	}
	fmt.Println(ans)
}