package main

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

// github.com/EndlessCheng/codeforces-go
func Sol490C(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var s string
	var a, b int
	Fscan(in, &s, &a, &b)
	n := len(s)

	l := int(s[0]-'0') % a
	validPos := []int{}
	for i := 1; i < n; i++ {
		if s[i] != '0' && l == 0 {
			validPos = append(validPos, i)
		}
		l = (10*l + int(s[i]-'0')) % a
	}
	if len(validPos) == 0 {
		Fprint(out, "NO")
		return
	}

	j := n - 2
	pow10 := 1
	r := int(s[n-1]-'0') % b
	for i := len(validPos) - 1; i >= 0; i-- {
		pos := validPos[i]
		for ; j >= pos; j-- {
			pow10 = pow10 * 10 % b
			r = (pow10*int(s[j]-'0') + r) % b
		}
		if r == 0 {
			Fprintf(out, "YES\n%s\n%s", s[:pos], s[pos:])
			return
		}
	}
	Fprint(out, "NO")
}

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

package main

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

var rdr = bufio.NewReader(os.Stdin)
var rbuf = make([]byte, 0, 1<<21)

func readLine() string {
	rbuf = rbuf[:0]
	for {
		l, p, e := rdr.ReadLine()
		if e != nil && e != io.EOF {
			panic(e)
		}
		rbuf = append(rbuf, l...)
		if !p {
			return string(rbuf)
		}
	}
}

func main() {
	s0 := readLine()
	n := len(s0)
	s1 := readLine()
	var ab [2]int64
	for i, s := range strings.Split(s1, " ") {
		x, e := strconv.ParseInt(s, 10, 64)
		if e != nil {
			panic(e)
		}
		ab[i] = x
	}
	a, b := ab[0], ab[1]
	var d, ma, mb [1 << 21]int64
	for i, r := range s0 {
		d[i] = int64(r - '0')
	}
	for x, i := int64(0), 0; i < n-1; i++ {
		x = (x*10 + d[i]) % a
		ma[i] = x
	}
	for y, base, i := int64(0), int64(1), n-1; i > 0; i-- {
		y = (y + base*d[i]) % b
		base = base * 10 % b
		mb[i-1] = y
	}

	for i := 0; i < n-1; i++ {
		if ma[i] == 0 && mb[i] == 0 && d[i+1] > 0 {
			fmt.Println("YES")
			fmt.Println(s0[0 : i+1])
			fmt.Println(s0[i+1:])
			return
		}
	}
	fmt.Println("NO")
}

package main

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

var (
	s   string
	a   int
	b   int
	pow int
)

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func main() {

	defer out.Flush()
	//in.Split(bufio.ScanWords)

	fmt.Fscan(in, &s)
	fmt.Fscan(in, &a, &b)

	n := len(s)
	ansA := make([]int, n)
	ansB := make([]int, n)
	num := make([]int, n)

	ansA[0], _ = strconv.Atoi(string(s[0]))
	ansB[n-1], _ = strconv.Atoi(string(s[n-1]))

	ansA[0] %= a
	ansB[n-1] %= b
	pow = 1 % b

	for i := 0; i < n; i++ {
		num[i] = int(s[i] - '0')
	}

	/*
		for i, j := 1, n-2; i < n; i, j = i+1, j-1 {

			ansA[i] = (ansA[i-1]*10 + num[i]) % a

			pow = pow * 10 % b

			ansB[j] = (pow*num[j] + ansB[j+1]) % b
		}
	*/

	for i := 1; i < n; i++ {
		ansA[i] = (ansA[i-1]*10 + num[i]) % a
	}

	for i := n - 2; i >= 0; i-- {
		pow = pow * 10 % b
		ansB[i] = (pow*num[i] + ansB[i+1]) % b
	}

	for i := 1; i < n; i++ {
		if num[i] > 0 && ansA[i-1] == 0 && ansB[i] == 0 {
			writeln("YES")
			writeln(s[:i])
			writeln(s[i:])
			return
		}
	}

	writeln("NO")

}

/*
func readStr(str *string) {
	//	*str, _ = in.ReadString()
	//*str = in.Text()
}

func readInt(num ...*int) {
	for _, value := range num {
		//in.Scan()
		b1 := make([]byte, 5)
		*value, _ = in.Read(b1)
		//*value, _ = strconv.Atoi(in.Text())
	}
}
*/
func writeln(str string) {
	out.WriteString(str + "\n")
}

package main

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

var rdr = bufio.NewReader(os.Stdin)
var rbuf = make([]byte, 0, 1<<21)

func readLine() string {
	rbuf = rbuf[:0]
	for {
		l, p, e := rdr.ReadLine()
		if e != nil && e != io.EOF {
			panic(e)
		}
		rbuf = append(rbuf, l...)
		if !p {
			return string(rbuf)
		}
	}
}

func main() {
	s0 := readLine()
	n := len(s0)
	s1 := readLine()
	var ab [2]int64
	for i, s := range strings.Split(s1, " ") {
		x, e := strconv.ParseInt(s, 10, 64)
		if e != nil {
			panic(e)
		}
		ab[i] = x
	}
	a, b := ab[0], ab[1]
	var d, ma, mb [1 << 21]int64
	rs := make([]rune, n)
	for i, r := range s0 {
		rs[i] = r
		d[i] = int64(r - '0')
	}
	for x, i := int64(0), 0; i < n-1; i++ {
		x = (x*10 + d[i]) % a
		ma[i] = x
	}
	for y, base, i := int64(0), int64(1), n-1; i > 0; i-- {
		y = (y + base*d[i]) % b
		base = base * 10 % b
		mb[i-1] = y
	}

	for i := 0; i < n-1; i++ {
		if ma[i] == 0 && mb[i] == 0 && d[i+1] > 0 {
			fmt.Println("YES")
			fmt.Println(string(rs[0 : i+1]))
			fmt.Println(string(rs[i+1:]))
			return
		}
	}
	fmt.Println("NO")
}

package main

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

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	reader := bufio.NewReader(os.Stdin)

	fmt.Fscan(reader, &publicKey)
	fmt.Fscan(reader, &a, &b)

	keyLength := len(publicKey)

	digits := make([]int, keyLength)
	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[keyLength-1] = modsOfB[keyLength-1] % b

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		digits[i] = d
		modsOfA[i] = (modsOfA[i-1]*10 + d) % a
	}

	for m, i := 1, keyLength-2; i >= 0; i-- {
		m = m * 10 % b
		modsOfB[i] = (digits[i]*m + modsOfB[i+1]) % b
		if modsOfA[i] == 0 && modsOfB[i+1] == 0 && publicKey[i+1] != '0' {
			res = YES
			resInd = i + 1
			break
		}
	}

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

import (
	"fmt"
	"math/big"
	"os"
)

var (
	s string
	a int64
	b int64
)

func main() {

	fmt.Scanf("%s", &s)
	fmt.Scanf("%d %d", &a, &b)

	num1 := big.NewInt(0)
	num2 := big.NewInt(0)

	ans1 := big.NewInt(0)
	ans2 := big.NewInt(0)

	intA := big.NewInt(a)
	intB := big.NewInt(b)

	zero := big.NewInt(0)

	os.Exit(0)
	for i := 1; i < len(s); i++ {
		if s[i] != '0' {
			num1.SetString(s[:i], 10)
			num2.SetString(s[i:], 10)

			ans1 = big.NewInt(0).Mod(num1, intA)
			ans2 = big.NewInt(0).Mod(num2, intB)
			/*
				fmt.Printf("%s %s\n", num1, num2)
				fmt.Printf("%s %s\n", intA, intB)
				fmt.Printf("%s %s\n", ans1, ans2)
				fmt.Println("-----------------------")
			*/
			if ans1.Cmp(zero) == 0 && ans2.Cmp(zero) == 0 {
				fmt.Println("YES")
				fmt.Printf("%s\n%s", num1, num2)

				os.Exit(0)
			}
		}
	}

	fmt.Println("NO")

}

package main

import (
	"fmt"
	"math/big"
	"os"
)

var (
	s string
	a int64
	b int64
)

func main() {

	fmt.Scanf("%s", &s)
	fmt.Scanf("%d %d", &a, &b)

	num1 := big.NewInt(0)
	num2 := big.NewInt(0)

	ans1 := big.NewInt(0)
	ans2 := big.NewInt(0)

	intA := big.NewInt(a)
	intB := big.NewInt(b)

	zero := big.NewInt(0)

	for i := 1; i < len(s); i++ {
		if s[i] != '0' {
			num1.SetString(s[:i], 10)
			num2.SetString(s[i:], 10)
			os.Exit(0)
			ans1 = big.NewInt(0).Mod(num1, intA)
			ans2 = big.NewInt(0).Mod(num2, intB)
			/*
				fmt.Printf("%s %s\n", num1, num2)
				fmt.Printf("%s %s\n", intA, intB)
				fmt.Printf("%s %s\n", ans1, ans2)
				fmt.Println("-----------------------")
			*/
			if ans1.Cmp(zero) == 0 && ans2.Cmp(zero) == 0 {
				fmt.Println("YES")
				fmt.Printf("%s\n%s", num1, num2)

				os.Exit(0)
			}
		}
	}

	fmt.Println("NO")

}

package main

import (
	"fmt"
	//	"os"
	"strconv"
)

var (
	s   string
	a   int
	b   int
	num int
	pow int
	pp  bool
)

func main() {

	fmt.Scan(&s)
	fmt.Scan(&a, &b)

	n := len(s)
	ansA := make([]int, n)
	ansB := make([]int, n)

	ansA[0], _ = strconv.Atoi(string(s[0]))
	ansB[n-1], _ = strconv.Atoi(string(s[n-1]))

	ansA[0] %= a
	ansB[0] %= b
	pow = 1 % b

	for i, j := 1, n-2; i < n; i, j = i+1, j-1 {
		num, _ = strconv.Atoi(string(s[i]))
		num %= a
		ansA[i] = (ansA[i-1]*10 + num) % a

		pow = pow * 10 % b

		num, _ = strconv.Atoi(string(s[j]))
		num %= b
		ansB[j] = ((pow*num)%b + ansB[j+1]) % b
	}

	for i := 1; i < n-1; i++ {
		if s[i] != '0' && ansA[i-1] == 0 && ansB[i] == 0 {
			fmt.Print("YES\n")
			fmt.Printf("%s\n%s", s[:i], s[i:])
			pp = true
			break
		}
	}

	if !pp {
		fmt.Println("NO")
	}

}

package main

import (
	"fmt"
	//	"math/big"
	//	"os"
)

var (
	s string
	a int64
	b int64
)

func main() {

	fmt.Scanf("%s", &s)
	fmt.Scanf("%d %d", &a, &b)
	/*
		num1 := big.NewInt(0)
		num2 := big.NewInt(0)

		ans1 := big.NewInt(0)
		ans2 := big.NewInt(0)

		intA := big.NewInt(a)
		intB := big.NewInt(b)

		zero := big.NewInt(0)
		//one := big.NewInt(1)

			for i := 1; i < len(s); i++ {
				if s[i] != '0' {
					num1.SetString(s[0:i], 10)
					num2.SetString(s[i:], 10)

					ans1 = big.NewInt(0).Mod(num1, intA)
					ans2 = big.NewInt(0).Mod(num2, intB)
					/*
						fmt.Printf("%s %s\n", num1, num2)
						fmt.Printf("%s %s\n", intA, intB)
						fmt.Printf("%s %s\n", ans1, ans2)
						fmt.Println("-----------------------")
					*
					if ans1.Cmp(zero) == 0 && ans2.Cmp(zero) == 0 {
						fmt.Println("YES")
						fmt.Printf("%s\n%s", num1, num2)

						os.Exit(0)
					}
				}
			}
	*/
	fmt.Println("NO")

}

package main

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

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	reader := bufio.NewReader(os.Stdin)

	fmt.Fscan(reader, &publicKey)
	fmt.Fscan(reader, &a, &b)

	keyLength := len(publicKey)

	digits := make([]int, keyLength)
	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[keyLength-1] = modsOfB[keyLength-1] % b

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		digits[i] = d
		modsOfA[i] = (modsOfA[i-1]*10 + d) % a
	}

	for m, i := 1, keyLength-2; i >= 0; i-- {
		m = m * 10 % b
		fmt.Println(modsOfA[i], modsOfB[i+1], publicKey[i+1])
		if modsOfA[i] == 0 && modsOfB[i+1] == 0 && publicKey[i+1] != '0' {
			res = YES
			resInd = i + 1
			break
		}
	}

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	fmt.Scan(&publicKey)
	fmt.Scan(&a, &b)

	keyLength := len(publicKey)

	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[0] = modsOfB[0] % a

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfA[i] = ((modsOfA[i-1]%a)*(10%a)%a + d%a) % a
	}

	for m, i := 1, keyLength-2; i > 0; i-- {
		m = (m % b) * (10 % b) % b
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfB[i] = ((d%b)*(m%b)%b + modsOfB[i+1]%b) % b
	}

	for i := 1; i < keyLength; i++ {
		if modsOfA[i] == 0 && modsOfB[i] == 0 && string(publicKey[i+1]) != "0" {
			res = YES
			resInd = i
			break
		}
	}

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	fmt.Scan(&publicKey)
	fmt.Scan(&a, &b)

	keyLength := len(publicKey)

	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[0] = modsOfB[0] % a

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfA[i] = ((modsOfA[i-1]%a)*(10%a)%a + d%a) % a
	}

	for m, i := 1, keyLength-2; i > 0; i-- {
		m = (m % b) * (10 % b) % b
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfB[i] = ((d%b)*(m%b)%b + modsOfB[i+1]%b) % b
	}

	for i := 1; i < keyLength-1; i++ {
		if modsOfA[i] == 0 && modsOfB[i] == 0 && string(publicKey[i+1]) != "0" {
			res = YES
			resInd = i + 1
			break
		}
	}

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	fmt.Scan(&publicKey)
	fmt.Scan(&a, &b)

	keyLength := len(publicKey)

	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[0] = modsOfB[0] % a

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfA[i] = ((modsOfA[i-1]%a)*(10%a)%a + d%a) % a
	}

	for m, i := 1, keyLength-2; i > 0; i-- {
		m = (m % b) * (10 % b) % b
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfB[i] = ((d%b)*(m%b)%b + modsOfB[i+1]%b) % b
	}

	for i := 0; i < keyLength-1; i++ {
		if modsOfA[i] == 0 && modsOfB[i] == 0 && string(publicKey[i+1]) != "0" {
			res = YES
			resInd = i + 1
			break
		}
	}

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

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

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	reader := bufio.NewReader(os.Stdin)

	fmt.Fscan(reader, &publicKey)
	fmt.Fscan(reader, &a, &b)

	keyLength := len(publicKey)

	digits := make([]int, keyLength)
	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[keyLength-1] = modsOfB[keyLength-1] % b

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		digits[i] = d
		modsOfA[i] = (modsOfA[i-1]*10 + d) % a
	}

	for m, i := 1, keyLength-2; i >= 0; i-- {
		m = m * 10 % b
		if modsOfA[i] == 0 && modsOfB[i+1] == 0 && publicKey[i+1] != '0' {
			res = YES
			resInd = i + 1
			break
		}
	}

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	fmt.Scan(&publicKey)
	fmt.Scan(&a, &b)

	keyLength := len(publicKey)

	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[keyLength-1] = modsOfB[keyLength-1] % b

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfA[i] = ((modsOfA[i-1]%a)*(10%a)%a + d%a) % a
	}

	for m, i := 1, keyLength-2; i > 0; i-- {
		m = (m % b) * (10 % b) % b
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfB[i] = ((d%b)*(m%b)%b + modsOfB[i+1]%b) % b
		if modsOfA[i-1] == 0 && modsOfB[i] == 0 && d != 0 {
			res = YES
			resInd = i
			break
		}
	}

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

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

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	reader := bufio.NewReader(os.Stdin)

	fmt.Fscan(reader, &publicKey, &a, &b)

	keyLength := len(publicKey)

	digits := make([]int, keyLength)
	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[keyLength-1] = modsOfB[keyLength-1] % b

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		digits[i] = d
		modsOfA[i] = (modsOfA[i-1]*10 + d) % a
	}

	for m, i := 1, keyLength-2; i > 0; i-- {
		m = m * 10 % b
		modsOfB[i] = (digits[i]*m + modsOfB[i+1]) % b
		if modsOfA[i] == 0 && modsOfB[i+1] == 0 && publicKey[i+1] != '0' {
			res = YES
			resInd = i + 1
			break
		}
	}

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	fmt.Scan(&publicKey)
	fmt.Scan(&a, &b)

	keyLength := len(publicKey)

	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[keyLength-1] = modsOfB[keyLength-1] % b

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfA[i] = ((modsOfA[i-1]%a)*(10%a)%a + d%a) % a
	}

	for m, i := 1, keyLength-2; i > 0; i-- {
		m = (m % b) * (10 % b) % b
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfB[i] = ((d%b)*(m%b)%b + modsOfB[i+1]%b) % b
	}

	for i := 0; i+1 < keyLength; i++ {
		if modsOfA[i] == 0 && modsOfB[i+1] == 0 && string(publicKey[i+1]) != "0" {
			res = YES
			resInd = i + 1
			break
		}
	}

	fmt.Println(modsOfA)
	fmt.Println(modsOfB)

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	const YES = "YES"
	const NO = "NO"

	var publicKey string
	var a, b int

	fmt.Scan(&publicKey)
	fmt.Scan(&a, &b)

	keyLength := len(publicKey)

	modsOfA := make([]int, keyLength)
	modsOfB := make([]int, keyLength)

	modsOfA[0], _ = strconv.Atoi(string(publicKey[0]))
	modsOfB[keyLength-1], _ = strconv.Atoi(string(publicKey[keyLength-1]))

	modsOfA[0] = modsOfA[0] % a
	modsOfB[keyLength-1] = modsOfB[keyLength-1] % a

	res := NO
	var resInd int

	for i := 1; i < keyLength-1; i++ {
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfA[i] = ((modsOfA[i-1]%a)*(10%a)%a + d%a) % a
	}

	for m, i := 1, keyLength-2; i > 0; i-- {
		m = (m % b) * (10 % b) % b
		d, _ := strconv.Atoi(string(publicKey[i]))
		modsOfB[i] = ((d%b)*(m%b)%b + modsOfB[i+1]%b) % b
	}

	for i := 0; i+1 < keyLength; i++ {
		if modsOfA[i] == 0 && modsOfB[i+1] == 0 && string(publicKey[i+1]) != "0" {
			res = YES
			resInd = i + 1
			break
		}
	}

	fmt.Println(res)

	if res == YES {
		fmt.Println(publicKey[:resInd])
		fmt.Println(publicKey[resInd:])
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol490C(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var s []byte
	var a, b int
	Fscan(in, &s, &a, &b)
	n := len(s)

	l := int(s[0] - '0')
	validPos := []int{}
	for i := 1; i < n; i++ {
		if s[i] != '0' && l%a == 0 {
			validPos = append(validPos, i)
		}
		l = 10*l + int(s[i]-'0')
	}
	if len(validPos) == 0 {
		Fprint(out, "NO")
		return
	}
	j := n - 2
	pow10 := 1
	r := int(s[n-1] - '0')
	for i := len(validPos) - 1; i >= 0; i-- {
		pos := validPos[i]
		for ; j >= pos; j-- {
			pow10 = pow10 * 10 % b
			r = (pow10*int(s[j]-'0') + r) % b
		}
		if r == 0 {
			Fprintf(out, "YES\n%s\n%s", s[:pos], s[pos:])
			return
		}
	}
	Fprint(out, "NO")
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol490C(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var s []byte
	var a, b int
	Fscan(in, &s, &a, &b)
	n := len(s)

	l := int(s[0]-'0') % a
	validPos := []int{}
	for i := 1; i < n; i++ {
		if s[i] != '0' && l == 0 {
			validPos = append(validPos, i)
		}
		l = (10*l + int(s[i]-'0')) % a
	}
	if len(validPos) == 0 {
		Fprint(out, "NO")
		return
	}
	j := n - 2
	pow10 := 1
	r := int(s[n-1] - '0')
	for i := len(validPos) - 1; i >= 0; i-- {
		pos := validPos[i]
		for ; j >= pos; j-- {
			pow10 = pow10 * 10 % b
			r = (pow10*int(s[j]-'0') + r) % b
		}
		if r == 0 {
			Fprintf(out, "YES\n%s\n%s", s[:pos], s[pos:])
			return
		}
	}
	Fprint(out, "NO")
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol490C(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var s string
	var a, b int
	Fscan(in, &s, &a, &b)
	n := len(s)

	l := int(s[0]-'0') % a
	validPos := []int{}
	for i := 1; i < n; i++ {
		if s[i] != '0' && l == 0 {
			validPos = append(validPos, i)
		}
		l = (10*l + int(s[i]-'0')) % a
	}
	if len(validPos) == 0 {
		Fprint(out, "NO")
		return
	}

	j := n - 2
	pow10 := 1
	r := int(s[n-1] - '0')
	for i := len(validPos) - 1; i >= 0; i-- {
		pos := validPos[i]
		for ; j >= pos; j-- {
			pow10 = pow10 * 10 % b
			r = (pow10*int(s[j]-'0') + r) % b
		}
		if r == 0 {
			Fprintf(out, "YES\n%s\n%s", s[:pos], s[pos:])
			return
		}
	}
	Fprint(out, "NO")
}

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


package main

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

const star = "*"
const space = " "

func make_stars(size int) string {
	var line string
	for i := 0; i < size; i++ {
		line += star
	}
	return line
}

func make_space(size int) string {
	var line string
	for i := 0; i < size; i++ {
		line += space
	}
	return line
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	lines := make([]string, 0, 1001)
	inputs := make([]string, 0, 1001)
	var block_size, input_len int
	for scanner.Scan() {
		ip := scanner.Text()
		inputs = append(inputs, ip)
		input_len = len(ip)
		if input_len > block_size {
			block_size = input_len
		}
	}
	lines = append(lines, make_stars(block_size+2))
	var line string
	var left_margin, right_margin int
	var right_align bool
	for _, ip := range inputs {
		line = ""
		input_len = len(ip)
		line += star
		margin := block_size - input_len
		if margin%2 == 0 {
			left_margin = margin / 2
			right_margin = left_margin
		} else {
			if right_align {
				right_margin = margin / 2
				left_margin = right_margin + 1
				right_align = false
			} else {
				left_margin = margin / 2
				right_margin = left_margin + 1
				right_align = true
			}
		}
		line += make_space(left_margin)
		line += ip
		line += make_space(right_margin)
		line += star
		lines = append(lines, line)
	}
	lines = append(lines, make_stars(block_size+2))
	for _, l := range lines {
		fmt.Fprintln(writer, l)
	}
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	writer := bytes.NewBuffer(make([]byte, 0, 1000000))

	s := bytes.Split(bs, []byte("\r\n"))
	maxlen := -1
	for i := 0; i < len(s); i++ {
		if maxlen < len(s[i]) {
			maxlen = len(s[i])
		}
	}

	star := make([]byte, maxlen+2)
	for i := 0; i < maxlen+2; i++ {
		star[i] = '*'
	}
	fmt.Fprintf(writer, "%s\n", string(star))

	flag := 0
	for i := 0; i < len(s); i++ {
		if i == len(s)-1 && len(s[i]) == 0 {
			continue
		}
		fmt.Fprintf(writer, "*")
		leftSpace := 0
		if (maxlen % 2) == (len(s[i]) % 2) {
			leftSpace = (maxlen - len(s[i])) / 2
		} else {
			leftSpace = (maxlen-len(s[i]))/2 + flag
			flag = 1 - flag
		}
		for j := 0; j < leftSpace; j++ {
			fmt.Fprintf(writer, " ")
		}
		fmt.Fprintf(writer, "%s", string(s[i]))
		for j := 0; j < maxlen-leftSpace-len(s[i]); j++ {
			fmt.Fprintf(writer, " ")
		}
		fmt.Fprintf(writer, "*\n")
	}
	fmt.Fprintf(writer, "%s\n", string(star))
	writer.WriteTo(os.Stdout)
}

package main

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

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	allLines := make([]string, 0, 1000)
	maxLen := 0

	for scanner.Scan() {
		line := scanner.Text()

		if len(line) > maxLen {
			maxLen = len(line)
		}

		allLines = append(allLines, line)
	}

	var buffer bytes.Buffer

	buffer.WriteString(strings.Repeat("*", maxLen+2))
	buffer.WriteByte('\n')

	moreLeft := false

	for _, line := range allLines {
		leftOver := maxLen - len(line)
		leftOverEach := int(leftOver / 2)

		paddingLeft := leftOverEach
		paddingRight := leftOverEach

		if leftOver%2 != 0 && moreLeft {
			paddingLeft = leftOverEach + 1
			paddingRight = leftOverEach
			moreLeft = !moreLeft
		} else if leftOver%2 != 0 {
			paddingLeft = leftOverEach
			paddingRight = leftOverEach + 1
			moreLeft = !moreLeft
		}

		buffer.WriteString("*")
		buffer.WriteString(strings.Repeat(" ", paddingLeft))
		buffer.WriteString(line)
		buffer.WriteString(strings.Repeat(" ", paddingRight))
		buffer.WriteString("*")
		buffer.WriteByte('\n')
	}

	buffer.WriteString(strings.Repeat("*", maxLen+2))
	buffer.WriteByte('\n')

	fmt.Println(buffer.String())
}

package main

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

var scanner *bufio.Scanner

func solve() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanLines)

	var lines []string
	mxline := 0
	for i := 0; scanner.Scan(); i++ {
		line := scanner.Text()
		lines = append(lines, line)
		if mxline < len(line) {
			mxline = len(line)
		}
	}

	fmt.Println(strings.Repeat("*", mxline+2))
	goLeft := false
	for _, line := range lines {
		aligns := mxline - len(line)
		laligns := aligns / 2
		raligns := aligns / 2
		if aligns%2 == 1 {
			if goLeft {
				goLeft = false
				laligns++
			} else {
				goLeft = true
				raligns++
			}
		}
		fmt.Print("*",
			strings.Repeat(" ", laligns),
			line,
			strings.Repeat(" ", raligns), "*\n")

	}
	fmt.Println(strings.Repeat("*", mxline+2))
}

func main() {
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

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

  lines := []string{}
  n := 0
  for {
    line, err := reader.ReadString('\n')
    if err != nil {
      break
    }
    line = strings.TrimSpace(line)
    lines = append(lines, line)
    if len(line) > n {
      n = len(line)
    }
  }
  stars := make([]byte, n+2)
  for i := 0; i < n+2; i++ {
    stars[i] = '*'
  }
  writer.WriteString(fmt.Sprintf("%s\n", string(stars)))
  padRight := true
  for _, line := range lines {
    pad := n - len(line)
    left, right := pad/2, pad/2
    if pad%2 == 1 {
      if padRight {
        right++
      } else {
        left++
      }
      padRight = !padRight
    }
    writer.WriteString("*")
    for i := 0; i < left; i++ {
      writer.WriteString(" ")
    }
    writer.WriteString(line)
    for i := 0; i < right; i++ {
      writer.WriteString(" ")
    }
    writer.WriteString("*\n")
  }
  writer.WriteString(fmt.Sprintf("%s\n", string(stars)))
}

package main

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

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func stars(n int) string {
	s := ""
	for i := 0; i < n; i++ {
		s += "*"
	}
	return s
}

func main() {
	lines := make([]string, 0)
	maxlen := 0
	line, err := nextLine()
	for err == nil {
		maxlen = max(maxlen, len(line))
		lines = append(lines, line)
		line, err = nextLine()
		if len(lines) % 100 == 0 {
			runtime.GC()
		}
	}
	lines = append([]string{stars(maxlen)}, lines...)
	lines = append(lines, stars(maxlen))
	left := true
	for i := range lines {
		if i % 100 == 0 {
			runtime.GC()
		}
		if (maxlen - len(lines[i])) % 2 != 0 {
			if left {
				lines[i] += " "
			} else {
				lines[i] = " " + lines[i]
			}
			left = !left
		}
		for len(lines[i]) != maxlen {
			lines[i] = " " + lines[i] + " "
		}
		lines[i] = "*" + lines[i] + "*"
	}
	for _, l := range lines {
		printf("%s\n", l)
	}
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

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

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)

	s := bytes.Split(bs, []byte("\n"))
	maxlen := -1
	for i := 0; i < len(s); i++ {
		if maxlen < len(s[i]) {
			maxlen = len(s[i])
		}
	}

	for i := 0; i < maxlen+2; i++ {
		fmt.Printf("*")
	}
	fmt.Printf("\n")

	flag := 0
	for i := 0; i < len(s); i++ {
		if i == len(s)-1 && len(s[i]) == 0 {
			continue
		}
		fmt.Printf("*")
		leftSpace := 0
		if (maxlen % 2) == (len(s[i]) % 2) {
			leftSpace = (maxlen - len(s[i])) / 2
		} else {
			leftSpace = (maxlen-len(s[i]))/2 + flag
			flag = 1 - flag
		}
		for j := 0; j < leftSpace; j++ {
			fmt.Printf(" ")
		}
		fmt.Printf("%s", string(s[i]))
		for j := 0; j < maxlen-leftSpace-len(s[i]); j++ {
			fmt.Printf(" ")
		}
		fmt.Printf("*\n")
	}

	for i := 0; i < maxlen+2; i++ {
		fmt.Printf("*")
	}
	fmt.Printf("\n")
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)

	s := bytes.Split(bs, []byte("\r\n"))
	maxlen := -1
	for i := 0; i < len(s); i++ {
		if maxlen < len(s[i]) {
			maxlen = len(s[i])
		}
	}

	for i := 0; i < maxlen+2; i++ {
		fmt.Printf("*")
	}
	fmt.Printf("\n")

	flag := 0
	for i := 0; i < len(s); i++ {
		fmt.Printf("*")
		leftSpace := 0
		if (maxlen % 2) == (len(s[i]) % 2) {
			leftSpace = (maxlen - len(s[i])) / 2
		} else {
			leftSpace = (maxlen-len(s[i]))/2 + flag
			flag = 1 - flag
		}
		for j := 0; j < leftSpace; j++ {
			fmt.Printf(" ")
		}
		fmt.Printf("%s", string(s[i]))
		for j := 0; j < maxlen-leftSpace-len(s[i]); j++ {
			fmt.Printf(" ")
		}
		fmt.Printf("*\n")
	}

	for i := 0; i < maxlen+2; i++ {
		fmt.Printf("*")
	}
	fmt.Printf("\n")
}

package main

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

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	allLines := make([]string, 0, 1000)
	maxLen := 0

	for scanner.Scan() {
		line := scanner.Text()

		if len(line) > maxLen {
			maxLen = len(line)
		}

		allLines = append(allLines, line)
	}

	var buffer bytes.Buffer

	buffer.WriteString(strings.Repeat("*", maxLen+2))
	buffer.WriteByte('\n')

	for _, line := range allLines {
		leftOver := maxLen - len(line)
		leftOverEach := int(leftOver / 2)

		paddingLeft := leftOverEach
		paddingRight := leftOverEach

		if leftOver%2 != 0 {
			paddingLeft = leftOverEach
			paddingRight = leftOverEach + 1
		}

		buffer.WriteString("*")
		buffer.WriteString(strings.Repeat(" ", paddingLeft))
		buffer.WriteString(line)
		buffer.WriteString(strings.Repeat(" ", paddingRight))
		buffer.WriteString("*")
		buffer.WriteByte('\n')
	}

	buffer.WriteString(strings.Repeat("*", maxLen+2))
	buffer.WriteByte('\n')

	fmt.Println(buffer.String())
}


package main

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

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

	var count, attempt int
	for i := 0; i < n; i++ {
		var x, y int
		fmt.Fscan(reader, &x, &y)

		if x > s || x == s && y > 0 {
			attempt++
			continue
		} else if y == 0 {
			continue

		}

		count = max(count, 100-y)
	}

	if attempt == n {
		fmt.Println(-1)
		return
	}

	fmt.Println(count)
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

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)

	n, s := nextInt(), nextInt()
	x, y := 0, 0
	max, dif := 0, 0
	canBuy := false

	for i := 0; i < n; i++ {
		x, y =	nextInt(), nextInt()

		if (y == 0 && x <= s) || (y > 0 &&  x + 1 <= s) {
				canBuy = true
			if y != 0 {
				dif = 100 - y

				if dif > max {
					max = dif
				}
			}
		}
	}

	if canBuy {
		println(max)
	} else {
		println(-1)
	}
}

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...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

package main

import (
	"fmt"
)

func main() {
	var n, s int
	if _, err := fmt.Scanf("%d %d\n", &n, &s); err != nil {
		return
	}

	var max_sweets int = -1
	for i := 0; i < n; i++ {
		var x, y int
		if _, err := fmt.Scanf("%d %d\n", &x, &y); err != nil {
			return
		}

		if s >= x+1 || (y == 0 && s >= x) {
			if y > 0 && 100-y > max_sweets {
				max_sweets = 100 - y
			} else if y == 0 && max_sweets < 0 {
				max_sweets = 0
			}
		}
	}

	fmt.Println(max_sweets)
}

package main

import (
	"bufio"
	"bytes"
	"errors"
	"flag"
	"fmt"
	"io"
	"log"
	"os"
	"runtime/pprof"
	"strconv"
	"time"
	"unicode/utf8"
	"math/rand"
)

// ******************************** CODE STARTS ********************************

const (
)

var (
)

func solve() {
	n := readInt()
	s	:= readInt()
	res := -1
	for i := 0; i < n; i++ {
		d := readInt()
		c := readInt()
		if c > 0 {
			d++
		}
		if d <= s && (res == -1 || res < (100 - c) % 100) {
			res = (100 - c) % 100
		}
	}
	printInt(res)
	printLine()
}
// ********************************* CODE ENDS *********************************

// IO.

var (
	scanner *Scanner
	writer  *bufio.Writer
	logger  *log.Logger
)

func main() {
	dbg := flag.Bool("dbg", false, "Equals true, if run is in debug mode.")
	opt := flag.Bool("opt", false, "Equals true, if run is in optimized mode.")
	flag.Parse()

	var (
		input  *os.File
		output *os.File
	)

	if *opt || *dbg {
		startTime := time.Now()
		defer func() {
			println(fmt.Sprintf("Time: %.5fs", time.Since(startTime).Seconds()))
		}()
		input, _ = os.Open("/home/outside/coding/workspace/go/io/input.txt")
		output, _ = os.Create("/home/outside/coding/workspace/go/io/output.txt")
		logger = log.New(output, "log: ", 0)
		if *dbg {
			cpuprofile, _ := os.Create("/home/outside/coding/workspace/go/io/cpuprofile.txt")
			pprof.StartCPUProfile(cpuprofile)
			defer cpuprofile.Close()
			defer pprof.StopCPUProfile()
		}
	} else {
		input = os.Stdin
		output = os.Stdout
		// input, _ = os.Open("")
		// output, _ = os.Create("")
	}
	defer input.Close()
	defer output.Close()

	scanner = NewScanner(input)
	scanner.Split(bufio.ScanWords)

	writer = bufio.NewWriter(output)
	defer writer.Flush()

	rand.Seed(int64(time.Now().Nanosecond()))
	solve()
}

// Read.

func readString() string {
	scanner.Scan()
	ans := scanner.Text()
	return ans
}

func readLine() string {
	scanner.Split(bufio.ScanLines)
	defer scanner.Split(bufio.ScanWords)
	return readString()
}

func readInt() int {
	ans, _ := strconv.ParseInt(readString(), 10, 0)
	return int(ans)
}

func readInt64() int64 {
	ans, _ := strconv.ParseInt(readString(), 10, 64)
	return ans
}

func readFloat64() float64 {
	ans, _ := strconv.ParseFloat(readString(), 64)
	return ans
}

// Write.

func printString(value string) {
	writer.WriteString(value)
}

func printLine() {
	printString("\n")
}

func printSpace() {
	printString(" ")
}

func printInt(value int) {
	printString(strconv.FormatInt(int64(value), 10))
}

func printInt64(value int64) {
	printString(strconv.FormatInt(value, 10))
}

func printFloat64(value float64) {
	printString(strconv.FormatFloat(value, 'f', 20, 64))
}

// Log.

func logln(value ...interface{}) {
	writer.Flush()
	logger.Println(value...)
}
func logf(format string, value ...interface{}) {
	writer.Flush()
	logger.Printf(format, value...)
}

// Tuple

type Tuple struct {
	a, b int
}

func (p Tuple) Equals(key Key) bool {
	return p.a == key.(Tuple).a
}

func (p Tuple) Less(key Key) bool {
	return p.a < key.(Tuple).a
}

type TupleSlice []Tuple

func (p TupleSlice) Len() int {
	return len(p)
}

func (p TupleSlice) Less(j, i int) bool {
	return p[j].a < p[i].a
}

func (p TupleSlice) Swap(j, i int) {
	p[j], p[i] = p[i], p[j]
}

// Min, max, abs.

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func absInt(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

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

func absInt64(a int64) int64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a < b {
		return a
	} else {
		return b
	}
}

func absFloat64(a float64) float64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

// Set Key interface implementations.

type Int int

func (p Int) Equals(key Key) bool {
	return int(p) == int(key.(Int))
}

func (p Int) Less(key Key) bool {
	return int(p) < int(key.(Int))
}

// Set.

type Key interface {
	Equals(key Key) bool
	Less(key Key) bool
}

type node struct {
	key   Key
	left  *node
	right *node
}

func newNode(key Key) *node {
	return &node{key, nil, nil}
}

type SplayTree struct {
	root *node
	tmp  *node
	len  int
}

func NewSplayTree() *SplayTree {
	return &SplayTree{nil, newNode(nil), 0}
}

func rotateLeft(x, p *node) {
	p.right = x.left
	x.left = p
}

func rotateRight(x, p *node) {
	p.left = x.right
	x.right = p
}

func (p *SplayTree) splay(x *node, key Key) *node {
	if x == nil {
		return nil
	}

	left := p.tmp
	right := p.tmp

	for {
		if key.Less(x.key) {
			y := x.left
			if y == nil {
				break
			}
			if key.Less(y.key) { // zig-zig
				rotateRight(y, x)
				x = y
				if x.left == nil {
					break
				}
			}
			// link right
			right.left = x
			right = x
			// move left
			x = x.left
		} else if x.key.Less(key) {
			y := x.right
			if y == nil {
				break
			}
			if y.key.Less(key) { // zig-zig
				rotateLeft(y, x)
				x = y
				if x.right == nil {
					break
				}
			}
			// link left
			left.right = x
			left = x
			// move right
			x = x.right
		} else {
			break
		}
	}

	left.right = x.left
	right.left = x.right
	x.left = p.tmp.right
	x.right = p.tmp.left

	return x
}

// left <= key < right
func (p *SplayTree) split(key Key) (left, right *node) {
	p.root = p.splay(p.root, key)
	if p.root.key.Equals(key) || p.root.key.Less(key) {
		right := p.root.right
		p.root.right = nil
		return p.root, right
	} else {
		left := p.root.left
		p.root.left = nil
		return left, p.root
	}
}

// keys from left tree must be less then keys from right tree
func (p *SplayTree) join(left, right *node) *node {
	if left == nil {
		return right
	} else if right == nil {
		return left
	}
	left = p.splay(left, right.key)
	left.right = right
	return left
}

type Set interface {
	Len() int
	Insert(key Key) error
	Find(key Key) bool
	Remove(key Key) error
}

func NewSet() Set {
	return Set(NewSplayTree())
}

func (p *SplayTree) Len() int {
	return p.len
}

func (p *SplayTree) Insert(key Key) error {
	if p.root == nil {
		p.root = newNode(key)
		p.len++
	} else {
		p.root = p.splay(p.root, key)
		if p.root.key.Equals(key) {
			return errors.New("Such key already exists")
		} else {
			left, right := p.split(key)
			p.root = newNode(key)
			p.root.left = left
			p.root.right = right
			p.len++
		}
	}
	return nil
}

func (p *SplayTree) Find(key Key) bool {
	if p.root == nil {
		return false
	}
	p.root = p.splay(p.root, key)
	return p.root.key.Equals(key)
}

func (p *SplayTree) Remove(key Key) error {
	p.root = p.splay(p.root, key)
	if p.root == nil || !p.root.key.Equals(key) {
		return errors.New("Such key doesn't exist")
	}
	p.root = p.join(p.split(key))
	return nil
}

// Copied scan.go
// Scanner provides a convenient interface for reading data such as
// a file of newline-delimited lines of text. Successive calls to
// the Scan method will step through the 'tokens' of a file, skipping
// the bytes between the tokens. The specification of a token is
// defined by a split function of type SplitFunc; the default split
// function breaks the input into lines with line termination stripped. Split
// functions are defined in this package for scanning a file into
// lines, bytes, UTF-8-encoded runes, and space-delimited words. The
// client may instead provide a custom split function.
//
// Scanning stops unrecoverably at EOF, the first I/O error, or a token too
// large to fit in the buffer. When a scan stops, the reader may have
// advanced arbitrarily far past the last token. Programs that need more
// control over error handling or large tokens, or must run sequential scans
// on a reader, should use bufio.Reader instead.
//
type Scanner struct {
	r            io.Reader // The reader provided by the client.
	split        SplitFunc // The function to split the tokens.
	maxTokenSize int       // Maximum size of a token; modified by tests.
	token        []byte    // Last token returned by split.
	buf          []byte    // Buffer used as argument to split.
	start        int       // First non-processed byte in buf.
	end          int       // End of data in buf.
	err          error     // Sticky error.
}

// SplitFunc is the signature of the split function used to tokenize the
// input. The arguments are an initial substring of the remaining unprocessed
// data and a flag, atEOF, that reports whether the Reader has no more data
// to give. The return values are the number of bytes to advance the input
// and the next token to return to the user, plus an error, if any. If the
// data does not yet hold a complete token, for instance if it has no newline
// while scanning lines, SplitFunc can return (0, nil, nil) to signal the
// Scanner to read more data into the slice and try again with a longer slice
// starting at the same point in the input.
//
// If the returned error is non-nil, scanning stops and the error
// is returned to the client.
//
// The function is never called with an empty data slice unless atEOF
// is true. If atEOF is true, however, data may be non-empty and,
// as always, holds unprocessed text.
type SplitFunc func(data []byte, atEOF bool) (advance int, token []byte, err error)

// Errors returned by Scanner.
var (
	ErrTooLong         = errors.New("bufio.Scanner: token too long")
	ErrNegativeAdvance = errors.New("bufio.Scanner: SplitFunc returns negative advance count")
	ErrAdvanceTooFar   = errors.New("bufio.Scanner: SplitFunc returns advance count beyond input")
)

const (
	// Maximum size used to buffer a token. The actual maximum token size
	// may be smaller as the buffer may need to include, for instance, a newline.
	MaxScanTokenSize = 1 << 20
)

// NewScanner returns a new Scanner to read from r.
// The split function defaults to ScanLines.
func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        ScanLines,
		maxTokenSize: MaxScanTokenSize,
		buf:          make([]byte, 4096), // Plausible starting size; needn't be large.
	}
}

// Err returns the first non-EOF error that was encountered by the Scanner.
func (s *Scanner) Err() error {
	if s.err == io.EOF {
		return nil
	}
	return s.err
}

// Bytes returns the most recent token generated by a call to Scan.
// The underlying array may point to data that will be overwritten
// by a subsequent call to Scan. It does no allocation.
func (s *Scanner) Bytes() []byte {
	return s.token
}

// Text returns the most recent token generated by a call to Scan
// as a newly allocated string holding its bytes.
func (s *Scanner) Text() string {
	return string(s.token)
}

// Scan advances the Scanner to the next token, which will then be
// available through the Bytes or Text method. It returns false when the
// scan stops, either by reaching the end of the input or an error.
// After Scan returns false, the Err method will return any error that
// occurred during scanning, except that if it was io.EOF, Err
// will return nil.
func (s *Scanner) Scan() bool {
	// Loop until we have a token.
	for {
		// See if we can get a token with what we already have.
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], s.err != nil)
			if err != nil {
				s.setErr(err)
				return false
			}
			if !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		// We cannot generate a token with what we are holding.
		// If we've already hit EOF or an I/O error, we are done.
		if s.err != nil {
			// Shut it down.
			s.start = 0
			s.end = 0
			return false
		}
		// Must read more data.
		// First, shift data to beginning of buffer if there's lots of empty space
		// or space is neded.
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		// Is the buffer full? If so, resize.
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				s.setErr(ErrTooLong)
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		// Finally we can read some input. Make sure we don't get stuck with
		// a misbehaving Reader. Officially we don't need to do this, but let's
		// be extra careful: Scanner is for safe, simple jobs.
		for loop := 0; ; {
			n, err := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if err != nil {
				s.setErr(err)
				break
			}
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				s.setErr(io.ErrNoProgress)
				break
			}
		}
	}
}

// advance consumes n bytes of the buffer. It reports whether the advance was legal.
func (s *Scanner) advance(n int) bool {
	if n < 0 {
		s.setErr(ErrNegativeAdvance)
		return false
	}
	if n > s.end-s.start {
		s.setErr(ErrAdvanceTooFar)
		return false
	}
	s.start += n
	return true
}

// setErr records the first error encountered.
func (s *Scanner) setErr(err error) {
	if s.err == nil || s.err == io.EOF {
		s.err = err
	}
}

// Split sets the split function for the Scanner. If called, it must be
// called before Scan. The default split function is ScanLines.
func (s *Scanner) Split(split SplitFunc) {
	s.split = split
}

// Split functions

// ScanBytes is a split function for a Scanner that returns each byte as a token.
func ScanBytes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	return 1, data[0:1], nil
}

var errorRune = []byte(string(utf8.RuneError))

// ScanRunes is a split function for a Scanner that returns each
// UTF-8-encoded rune as a token. The sequence of runes returned is
// equivalent to that from a range loop over the input as a string, which
// means that erroneous UTF-8 encodings translate to U+FFFD = "\xef\xbf\xbd".
// Because of the Scan interface, this makes it impossible for the client to
// distinguish correctly encoded replacement runes from encoding errors.
func ScanRunes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}

	// Fast path 1: ASCII.
	if data[0] < utf8.RuneSelf {
		return 1, data[0:1], nil
	}

	// Fast path 2: Correct UTF-8 decode without error.
	_, width := utf8.DecodeRune(data)
	if width > 1 {
		// It's a valid encoding. Width cannot be one for a correctly encoded
		// non-ASCII rune.
		return width, data[0:width], nil
	}

	// We know it's an error: we have width==1 and implicitly r==utf8.RuneError.
	// Is the error because there wasn't a full rune to be decoded?
	// FullRune distinguishes correctly between erroneous and incomplete encodings.
	if !atEOF && !utf8.FullRune(data) {
		// Incomplete; get more bytes.
		return 0, nil, nil
	}

	// We have a real UTF-8 encoding error. Return a properly encoded error rune
	// but advance only one byte. This matches the behavior of a range loop over
	// an incorrectly encoded string.
	return 1, errorRune, nil
}

// dropCR drops a terminal \r from the data.
func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[0 : len(data)-1]
	}
	return data
}

// ScanLines is a split function for a Scanner that returns each line of
// text, stripped of any trailing end-of-line marker. The returned line may
// be empty. The end-of-line marker is one optional carriage return followed
// by one mandatory newline. In regular expression notation, it is `\r?\n`.
// The last non-empty line of input will be returned even if it has no
// newline.
func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	if i := bytes.IndexByte(data, '\n'); i >= 0 {
		// We have a full newline-terminated line.
		return i + 1, dropCR(data[0:i]), nil
	}
	// If we're at EOF, we have a final, non-terminated line. Return it.
	if atEOF {
		return len(data), dropCR(data), nil
	}
	// Request more data.
	return 0, nil, nil
}

// isSpace reports whether the character is a Unicode white space character.
// We avoid dependency on the unicode package, but check validity of the implementation
// in the tests.
func isSpace(r rune) bool {
	if r <= '\u00FF' {
		// Obvious ASCII ones: \t through \r plus space. Plus two Latin-1 oddballs.
		switch r {
		case ' ', '\t', '\n', '\v', '\f', '\r':
			return true
		case '\u0085', '\u00A0':
			return true
		}
		return false
	}
	// High-valued ones.
	if '\u2000' <= r && r <= '\u200a' {
		return true
	}
	switch r {
	case '\u1680', '\u180e', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000':
		return true
	}
	return false
}

// ScanWords is a split function for a Scanner that returns each
// space-separated word of text, with surrounding spaces deleted. It will
// never return an empty string. The definition of space is set by
// unicode.IsSpace.
func ScanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	// Skip leading spaces.
	start := 0
	for width := 0; start < len(data); start += width {
		var r rune
		r, width = utf8.DecodeRune(data[start:])
		if !isSpace(r) {
			break
		}
	}
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	// Scan until space, marking end of word.
	for width, i := 0, start; i < len(data); i += width {
		var r rune
		r, width = utf8.DecodeRune(data[i:])
		if isSpace(r) {
			return i + width, data[start:i], nil
		}
	}
	// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	// Request more data.
	return 0, nil, nil
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, s int
	fmt.Fscan(reader, &n, &s)
	var dollors = make([]int, n)
	var cents = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &dollors[i], &cents[i])
	}
	var sweets int = -1
	for i := 0; i < n; i++ {
		var exchange = (100 - cents[i]) % 100
		if dollors[i]*100+cents[i] <= s*100 && sweets < exchange {
			sweets = exchange
		}
	}
	fmt.Println(sweets)
}

package main

import (
	"fmt"
)

func max(x, y int) int {
	if y > x {
		return y
	}
	return x
}

func main() {
	var n, s int
	var xs, ys [100]int
	fmt.Scan(&n)
	fmt.Scan(&s)
	for i := 0; i < n; i++ {
		fmt.Scan(&xs[i])
		fmt.Scan(&ys[i])
	}
	z := -1
	for i := 0; i < n; i++ {
		change := s*100 - (xs[i]*100 + ys[i])
		if change >= 0 {
			z = max(z, change%100)
		}
	}
	fmt.Println(z)
}

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)

	n, s := nextInt(), nextInt()
	x, y := 0, 0
	max, dif := 0, 0
	canBuy := false

	for i := 0; i < n; i++ {
		x, y =	nextInt(), nextInt()

		if (y == 0 && x <= s) || (y > 0 &&  x + 1 <= s) {
				canBuy = true
		}

		if canBuy && y != 0 {
			dif = 100 - y

			if dif > max {
				max = dif
			}
		}
	}

	if canBuy {
		println(max)
	} else {
		println(-1)
	}
}

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...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

package main

import (
	"fmt"
)

func main() {
	var n, s int
	if _, err := fmt.Scanf("%d %d\n", &n, &s); err != nil {
		return
	}

	var max_sweets int = -1
	for i := 0; i < n; i++ {
		var x, y int
		if _, err := fmt.Scanf("%d %d\n", &x, &y); err != nil {
			return
		}

		if s >= x+1 || (y == 0 && s >= x) {
			if y > 0 && 100-y > max_sweets {
				max_sweets = 100 - y
			}
		}
	}

	fmt.Println(max_sweets)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, s int
	fmt.Fscan(reader, &n, &s)
	var dollors = make([]int, n)
	var cents = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &dollors[i], &cents[i])
	}
	var sweets int = -1
	for i := 0; i < n; i++ {
		var exchange = (100 - cents[i]) % 100
		if dollors[i]*100+cents[i] < s*100 && sweets < exchange {
			sweets = exchange
		}
	}
	fmt.Println(sweets)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, s int
	fmt.Fscan(reader, &n, &s)
	var dollors = make([]int, n)
	var cents = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &dollors[i], &cents[i])
	}
	var sweets int = -1
	for i := 0; i < n; i++ {
		var exchange = (100 - cents[i]) % 100
		if dollors[i] < s && sweets < exchange {
			sweets = exchange
		}
	}
	fmt.Println(sweets)
}

package main

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

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

	var count, attempt int
	for i := 0; i < n; i++ {
		var x, y int
		fmt.Fscan(reader, &x, &y)

		if x > s {
			attempt++
			continue
		} else if y == 0 {
			continue

		}

		count = max(count, 100-y)
	}

	if attempt == n {
		fmt.Println(-1)
		return
	}

	fmt.Println(count)
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

package main

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

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

	var count, attempt int
	for i := 0; i < n; i++ {
		var x, y int
		fmt.Fscan(reader, &x, &y)

		if x > s || x == s && y > 0 {
			attempt++
			continue
		} else if x == s && y == 0 {
			continue

		}

		count = max(count, 100-y)
	}

	if attempt == n {
		fmt.Println(-1)
		return
	}

	fmt.Println(count)
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

package main

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

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

	var count int = -1
	for n > 0 {
		var x, y int
		fmt.Fscan(reader, &x, &y)

		if x > s || y == 0 {
			n--
			continue
		}

		count = max(count, 100-y)
		n--
	}

	fmt.Println(count)
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

package main

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

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

	var count, attempt int
	for i := 0; i < n; i++ {
		var x, y int
		fmt.Fscan(reader, &x, &y)

		if x >= s {
			attempt++
			continue
		} else if y == 0 {
			continue

		}

		count = max(count, 100-y)
	}

	if attempt == n {
		fmt.Println(-1)
		return
	}

	fmt.Println(count)
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF1003F(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	text := make([]rune, n)
	sum := make([]int, n+1)
	allSum := n - 1
	id := map[string]int{}
	for i := range text {
		var s string
		Fscan(in, &s)
		if _, ok := id[s]; !ok {
			id[s] = len(id) + 1
		}
		text[i] = rune(id[s])
		sum[i+1] = sum[i] + len(s)
		allSum += len(s)
	}

	s := string(text)
	ans := allSum
	for r := 1; r <= n; r++ {
		for l := 0; l < r; l++ {
			if c := strings.Count(s, string(text[l:r])); c > 1 {
				if s := allSum - c*(sum[r]-sum[l]-1); s < ans {
					ans = s
				}
			}
		}
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1003F(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	n, s := 0, ""
	Fscan(in, &n)
	a := make([]int, n)
	sz := make([]int, n+1)
	all := n - 1
	id := map[string]int{}
	for i := range a {
		Fscan(in, &s)
		v, ok := id[s]
		if !ok {
			v = len(id)
			id[s] = v
		}
		a[i] = v
		sz[i+1] = sz[i] + len(s)
		all += len(s)
	}

	search := func(s []int) (cnt int) {
		n := len(s)
		f := make([]int, n)
		c := 0
		for i := 1; i < n; i++ {
			b := s[i]
			for c > 0 && s[c] != b {
				c = f[c-1]
			}
			if s[c] == b {
				c++
			}
			f[i] = c
		}
		c = 0
		for _, b := range a {
			for c > 0 && s[c] != b {
				c = f[c-1]
			}
			if s[c] == b {
				c++
			}
			if c == n {
				cnt++
				c = 0
			}
		}
		return
	}
	ans := all
	for r := 1; r <= n; r++ {
		for l := 0; l < r; l++ {
			if c := search(a[l:r]); c > 1 {
				if s := all - c*(sz[r]-sz[l]-1); s < ans {
					ans = s
				}
			}
		}
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1003F(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	n, s := 0, ""
	Fscan(in, &n)
	a := make([]int, n)
	sz := make([]int, n+1)
	all := n - 1
	id := map[string]int{}
	for i := range a {
		Fscan(in, &s)
		if _, ok := id[s]; !ok {
			id[s] = len(id)
		}
		a[i] = id[s]
		sz[i+1] = sz[i] + len(s)
		all += len(s)
	}

	search := func(s []int) (cnt int) {
		n := len(s)
		f := make([]int, n)
		c := 0
		for i := 1; i < n; i++ {
			b := s[i]
			for c > 0 && s[c] != b {
				c = f[c-1]
			}
			if s[c] == b {
				c++
			}
			f[i] = c
		}
		c = 0
		for _, b := range a {
			for c > 0 && s[c] != b {
				c = f[c-1]
			}
			if s[c] == b {
				c++
			}
			if c == n {
				cnt++
				c = 0
			}
		}
		return
	}
	ans := all
	for r := 1; r <= n; r++ {
		for l := 0; l < r; l++ {
			if c := search(a[l:r]); c > 1 {
				if s := all - c*(sz[r]-sz[l]-1); s < ans {
					ans = s
				}
			}
		}
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	n,s := 0,""
	Fscan(in, &n)
	a := make([]rune, n)
	p := make([]int, n+1)
	L := n - 1
	m := map[string]int{}
	for i := range a {
		Fscan(in, &s)
		if _, ok := m[s]; !ok {
			m[s] = len(m)
		}
		a[i] = rune(m[s])
		p[i+1] = p[i] + len(s)
		L += len(s)
	}
	s = string(a)
	b := L
	for r := 1; r <= n; r++ {
		for l := 0; l < r; l++ {
			if c := Count(s, string(a[l:r])); c > 1 {
				if s := L - c*(p[r]-p[l]-1); s < b {
					b = s
				}
			}
		}
	}
	Print(b)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1003F(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	text := make([]rune, n)
	sum := make([]int, n+1)
	allSum := n - 1
	id := map[string]int{}
	for i := range text {
		var s string
		Fscan(in, &s)
		if _, ok := id[s]; !ok {
			id[s] = len(id) + 1
		}
		text[i] = rune(id[s])
		sum[i+1] = sum[i] + len(s)
		allSum += len(s)
	}

	s := string(text)
	ans := allSum
	for r := 1; r <= n; r++ {
		for l := 0; l < r; l++ {
			if c := strings.Count(s, s[l:r]); c > 1 {
				if s := allSum - c*(sum[r]-sum[l]-1); s < ans {
					ans = s
				}
			}
		}
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	n,s := 0,""
	Fscan(in, &n)
	a := make([]rune, n)
	p := make([]int, n+1)
	L := n - 1
	m := map[string]int{}
	for i := range a {
		Fscan(in, &s)
		if _, ok := m[s]; !ok {
			m[s] = len(m)
		}
		a[i] = rune(m[s])
		p[i+1] = p[i] + len(s)
		L += len(s)
	}
	s = string(a)
	b := L
	for r := 1; r <= n; r++ {
		for l := 0; l < r; l++ {
			if c := Count(s, string(a[l:r])); c > 1 {
				if s := l - c*(p[r]-p[l]-1); s < b {
					b = s
				}
			}
		}
	}
	Print(b)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	n,s := 0,""
	Fscan(in, &n)
	a := make([]rune, n)
	p := make([]int, n+1)
	l := n - 1
	m := map[string]int{}
	for i := range a {
		Fscan(in, &s)
		if _, ok := m[s]; !ok {
			m[s] = len(m)
		}
		a[i] = rune(m[s])
		p[i+1] = p[i] + len(s)
		l += len(s)
	}
	s = string(a)
	b := l
	for r := 1; r <= n; r++ {
		for l := 0; l < r; l++ {
			if c := Count(s, string(a[l:r])); c > 1 {
				if s := l - c*(p[r]-p[l]-1); s < b {
					b = s
				}
			}
		}
	}
	Print(b)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	n,s := 0,""
	Fscan(in, &n)
	a := make([]rune, n)
	p := make([]int, n+1)
	l := n - 1
	m := map[string]int{}
	for i := range a {
		Fscan(in, &s)
		if _, ok := m[s]; !ok {
			m[s] = len(m)+1
		}
		a[i] = rune(m[s])
		p[i+1] = p[i] + len(s)
		l += len(s)
	}
	s = string(a)
	b := l
	for r := 1; r <= n; r++ {
		for l := 0; l < r; l++ {
			if c := Count(s, string(a[l:r])); c > 1 {
				if s := l - c*(p[r]-p[l]-1); s < b {
					b = s
				}
			}
		}
	}
	Print(b)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1003F(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	text := make([]rune, n)
	sum := make([]int, n+1)
	allSum := n - 1
	id := map[string]int{}
	for i := range text {
		var s string
		Fscan(in, &s)
		if _, ok := id[s]; !ok {
			id[s] = len(id)
		}
		text[i] = rune(id[s])
		sum[i+1] = sum[i] + len(s)
		allSum += len(s)
	}

	s := string(text)
	ans := allSum
	for r := 1; r <= n; r++ {
		for l := 0; l < r; l++ {
			if c := strings.Count(s, s[l:r]); c > 1 {
				if s := allSum - c*(sum[r]-sum[l]-1); s < ans {
					ans = s
				}
			}
		}
	}
	Fprint(out, ans)
}

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


package main

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

var in = bufio.NewReader(os.Stdin)

func isPalindrome(t string) bool {
	if len(t) <= 1 {
		return true
	}

	n := len(t)
	for i := 0; i < n/2; i++ {
		if t[i] != t[n-1-i] {
			return false
		}
	}
	return true
}

func reverseStr(t string) string {
	n := len(t)
	tmp := make([]rune, n)
	for i, ti := range t {
		tmp[n-1-i] = ti
	}
	return string(tmp)
}

func solve() {
	var n int
	fmt.Fscan(in, &n)

	s := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &s[i])
	}

	for _, si := range s {
		if isPalindrome(si) {
			fmt.Println("YES")
			return
		}
	}

	founds := make(map[string]bool)
	for _, si := range s {
		revSi := reverseStr(si)
		if _, ok := founds[revSi]; ok {
			fmt.Println("YES")
			return
		}

		if len(si) == 2 {
			base := []rune(revSi)
			for c := 'a'; c <= 'z'; c++ {
				cur := string(append(base, c))
				if _, ok := founds[cur]; ok {
					fmt.Println("YES")
					return
				}
			}
		} else if len(si) == 3 {
			if _, ok := founds[revSi[:2]]; ok {
				fmt.Println("YES")
				return
			}
		} else {
			panic("impossible")
		}
		founds[si] = true
	}
	fmt.Println("NO")
}

func main() {
	var t int
	fmt.Fscan(in, &t)

	for i := 0; i < t; i++ {
		solve()
	}
}

package main

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

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

	t := readInt(in)
	b := strings.Builder{}
	for i := 0; i < t; i++ {
		str := solve(in)
		b.WriteString(str + "\n")
	}
	fmt.Println(b.String())
}

func solve(in *bufio.Reader) string {
	n := readInt(in)
	scenes := make([]string, n)
	tot := map[string]int{}
	l2 := map[string]int{}
	l3 := map[string]int{}

	for i := 0; i < n; i++ {
		str, _ := in.ReadString('\n')
		str = strings.ReplaceAll(str, "\r", "")
		str = strings.ReplaceAll(str, "\n", "")
		scenes[i] = str
		tot[scenes[i]]++
	}

	for i := 0; i < n; i++ {
		str := scenes[i]
		if len(str) == 1 {
			return "YES"
		}
		if isPalindrome(str) {
			return "YES"
		}
		tot[str]--
		rev := reverse(str)
		if val := tot[rev]; val != 0 {
			return "YES"
		}

		if len(str) == 2 {
			l2[str]++
			rev2 := reverse(str)
			if val := l3[rev2]; val != 0 {
				return "YES"
			}
		} else {
			l3[str[:2]]++
			rev3 := reverse(str[:2])
			if val := tot[rev3]; val != 0 {
				return "YES"
			}
			rev3 = reverse(str[1:])
			if val := l2[rev3]; val != 0 {
				return "YES"
			}
		}
	}

	return "NO"
}

func reverse(str string) string {
	b := strings.Builder{}
	for i := 0; i < len(str); i++ {
		b.WriteByte(str[len(str) - 1 - i])
	}
	return b.String()
}

func isPalindrome(str string) bool {
	for i := 0; i < len(str)/2; i++ {
		if str[i] != str[len(str) - 1 - i] {
			return false
		}
	}
	return true
}

func readInt(in *bufio.Reader) int {
nStr, _ := in.ReadString('\n')
nStr = strings.ReplaceAll(nStr, "\r", "")
nStr = strings.ReplaceAll(nStr, "\n", "")
n, _ := strconv.Atoi(nStr)
return n
}

func readLineNumbs(in *bufio.Reader) []string {
line, _ := in.ReadString('\n')
line = strings.ReplaceAll(line, "\r", "")
line = strings.ReplaceAll(line, "\n", "")
numbs := strings.Split(line, " ")
return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

package main

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n int
		var found bool
		fmt.Fscan(r, &n)

		pf := make(map[string]bool)

		for i := 0; i < n; i++ {
			var t string
			fmt.Fscan(r, &t)

			if found {
				continue
			} else if t[0] == t[len(t)-1] {
				found = true
			} else if len(t) == 2 {
				for j := 'a'; j <= 'z'; j++ {
					if pf[string([]byte{t[1],t[0]}) + string(j)] {
						found = true
						break
					} else {
						pf[t + string(j)] = true
					}
				}
			} else {
				if pf[string([]byte{t[2],t[1],t[0]})] {
					found = true
				} else {
					pf[t] = true
				}
			}
		}

		if found {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}
	}

}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }

func isPal(s []byte) bool {
	for i := 0; i < len(s)-i-1; i++ {
		if s[i] != s[len(s)-i-1] {
			return false
		}
	}
	return true
}

func solveCase() bool {
	var n int
	scan(&n)
	var foundPal = false
	a := make([][]byte, n)
	for i := 0; i < n; i++ {
		scan(&a[i])
		foundPal = foundPal || isPal(a[i])
	}
	if foundPal {
		return true
	}

	seen := make(map[string]bool)
	seen2 := make(map[string]bool)
	for _, s := range a {
		if len(s) == 2 {
			// ab ba
			if seen[string([]byte{s[1], s[0]})] {
				return true
			}
			// abc ba
			if seen2[string([]byte{s[1], s[0]})] {
				return true
			}
		} else if len(s) == 3 {
			// abc cba
			if seen[string([]byte{s[2], s[1], s[0]})] {
				return true
			}
			// ab cba
			if seen[string([]byte{s[2], s[1]})] {
				return true
			}
			seen2[string([]byte{s[0], s[1]})] = true
		}
		seen[string(s)] = true
	}
	return false
}

func main() {
	defer out.Flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		if solveCase() {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

package main

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

//-----------------------------------------------

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

func scan(a ...interface{})    { fmt.Fscan(reader, a...) }
func print(a ...interface{})   { fmt.Fprint(writer, a...) }
func println(a ...interface{}) { fmt.Fprintln(writer, a...) }

//-----------------------------------------------

func isPal(s string) bool {
	i := 0
	j := len(s) - 1
	for i < j {
		if s[i] != s[j] {
			return false
		}
		i++
		j--
	}
	return true
}

func revStr(s string) string {
	rev := make([]byte, 0)
	l := len(s)
	for i := l - 1; i >= 0; i-- {
		rev = append(rev, s[i])
	}
	return string(rev)
}

//bac ab
//ab cba
//abc cba
func foo(arr []string, n int) bool {
	mp := make(map[string]struct{}, 0)
	mp2 := make(map[string]struct{}, 0)
	for i := 0; i < n; i++ {
		s := arr[i]
		if isPal(s) {
			return true
		}
		rev := revStr(s)
		if _, ok := mp[rev]; ok {
			return true
		}
		if len(s) == 2 {
			if _, ok := mp2[rev]; ok {
				return true
			}
		} else {
			if _, ok := mp[rev[0:2]]; ok {
				return true
			}
			mp2[s[0:2]] = struct{}{}
		}
		mp[s] = struct{}{}
	}
	return false
}

func output(f bool) string {
	if f {
		return "YES"
	}
	return "NO"
}

var arr []string

func main() {
	defer writer.Flush()
	var t, n int
	scan(&t)
	arr = make([]string, 100005)
	for i := 0; i < t; i++ {
		scan(&n)

		for i := 0; i < n; i++ {
			scan(&arr[i])
		}
		println(output(foo(arr, n)))
	}
}

package main

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

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

func reverse(s string) (res string) {
	for _, v := range s {
		res = string(v) + res
	}
	return res
}

var T, N int
var S []string

func solve() string {
	mp := map[string]int{}
	for i := 0; i < N; i++ {
		if S[i] == reverse(S[i]) {
			return "YES"
		}
	}

	for i := 0; i < N; i++ {
		s := S[i]
		rs := reverse(s)

		if _, ok := mp[rs]; ok {
			return "YES"
		}

		if len(s) == 2 {
			for a := 'a'; a <= 'z'; a++ {
				if _, ok := mp[rs + string(a)]; ok {
					return "YES";
				}
			}

		} else if len(s) == 3 {
			if _, ok := mp[reverse(s[1:])]; ok {
				return "YES"
			}
		}
		mp[s] = 1
	}

	return "NO"
}

func main(){
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &T)
	for ; T > 0; T-- {
		fmt.Fscan(in, &N)
		S = make([]string, N)
		for i := 0; i < N; i++ {
			fmt.Fscan(in, &S[i])
		}

		fmt.Println(solve())
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1628B(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var T, n int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		ok, s2, s3 := false, [26]int{}, [26][26]int{}
		for Fscan(in, &n); n > 0; n-- {
			if Fscan(in, &s); ok {
			} else if len(s) == 1 || s[0] == s[len(s)-1] {
				ok = true
			} else if len(s) == 2 {
				x, y := s[0]-'a', s[1]-'a'
				if s2[y]>>x&1 > 0 || s3[y][x] > 0 {
					ok = true
				}
				s2[x] |= 1 << y
			} else {
				x, y, z := s[0]-'a', s[1]-'a', s[2]-'a'
				if s2[z]>>y&1 > 0 || s3[z][y]>>x&1 > 0 {
					ok = true
				}
				s3[x][y] |= 1 << z
			}
		}
		if ok {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1628B(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var T, n int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		ok, s2, s3 := false, [26]int{}, [26][26]int{}
		for Fscan(in, &n); n > 0; n-- {
			if Fscan(in, &s); ok {
			} else if len(s) == 1 || s[0] == s[len(s)-1] {
				ok = true
			} else if len(s) == 2 {
				x, y := s[0]-'a', s[1]-'a'
				if s2[y]>>x&1 > 0 || s3[y][x] > 0 {
					ok = true
				}
				s2[x] |= 1 << y
			} else {
				x, y, z := s[0]-'a', s[1]-'a', s[2]-'a'
				if s2[z]>>y&1 > 0 || s3[z][y]>>x&1 > 0 {
					ok = true
				}
				s3[x][y] |= 1 << z
			}
		}
		if ok {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

package main

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

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

	t := readInt(in)
	b := strings.Builder{}
	for i := 0; i < t; i++ {
		str := solve(in)
		b.WriteString(str + "\n")
	}
	fmt.Println(b.String())
}

func solve(in *bufio.Reader) string {
	n := readInt(in)
	scenes := make([]string, n)
	tot := map[string]int{}
	l2 := map[string]int{}
	l3 := map[string]int{}

	for i := 0; i < n; i++ {
		str, _ := in.ReadString('\n')
		str = strings.ReplaceAll(str, "\r", "")
		str = strings.ReplaceAll(str, "\n", "")
		scenes[i] = str
		tot[scenes[i]]++
	}

	// 1. check if in right we have reverse(str)
	// 2. len(str) == 2
	//    check if in left3 we have reverse(str)
	// 3. len(str) == 3
	//	  check if in left2 we have reverse(str[1:])
	for i := 0; i < n; i++ {
		str := scenes[i]
		if len(str) == 1 {
			return "YES"
		}
		tot[str]--
		rev := reverse(str)
		if val := tot[rev]; val != 0 {
			return "YES"
		}

		if len(str) == 2 {
			l2[str]++
			rev2 := reverse(str)
			if val := l3[rev2]; val != 0 {
				return "YES"
			}
		} else {
			l3[str[:2]]++
			rev3 := reverse(str[:2])
			if val := tot[rev3]; val != 0 {
				return "YES"
			}
			rev3 = reverse(str[1:])
			if val := l2[rev3]; val != 0 {
				return "YES"
			}
		}
	}

	return "NO"
}

func reverse(str string) string {
	b := strings.Builder{}
	for i := 0; i < len(str); i++ {
		b.WriteByte(str[len(str) - 1 - i])
	}
	return b.String()
}

func isPalindrome(str string) bool {
	for i := 0; i < len(str)/2; i++ {
		if str[i] != str[len(str) - 1 - i] {
			return false
		}
	}
	return true
}

func readInt(in *bufio.Reader) int {
nStr, _ := in.ReadString('\n')
nStr = strings.ReplaceAll(nStr, "\r", "")
nStr = strings.ReplaceAll(nStr, "\n", "")
n, _ := strconv.Atoi(nStr)
return n
}

func readLineNumbs(in *bufio.Reader) []string {
line, _ := in.ReadString('\n')
line = strings.ReplaceAll(line, "\r", "")
line = strings.ReplaceAll(line, "\n", "")
numbs := strings.Split(line, " ")
return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

package main

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

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

	t := readInt(in)
	b := strings.Builder{}
	for i := 0; i < t; i++ {
		str := solve(in)
		b.WriteString(str + "\n")
	}
	fmt.Println(b.String())
}

func solve(in *bufio.Reader) string {
	n := readInt(in)
	scenes := make([]string, n)
	tot := map[string]int{}
	l2 := map[string]int{}
	l3 := map[string]int{}

	for i := 0; i < n; i++ {
		str, _ := in.ReadString('\n')
		str = strings.ReplaceAll(str, "\r", "")
		str = strings.ReplaceAll(str, "\n", "")
		scenes[i] = str
		tot[scenes[i]]++
	}

	// 1. check if in right we have reverse(str)
	// 2. len(str) == 2
	//    check if in left3 we have reverse(str)
	// 3. len(str) == 3
	//	  check if in left2 we have reverse(str[1:])
	for i := 0; i < n; i++ {
		str := scenes[i]
		if len(str) == 1 {
			return "YES"
		}
		tot[str]--
		rev := reverse(str)
		if val := tot[rev]; val != 0 {
			return "YES"
		}

		if len(str) == 2 {
			l2[str]++
			rev2 := reverse(str)
			if val := l3[rev2]; val != 0 {
				return "YES"
			}
		} else {
			l3[str[:2]]++
			rev3 := reverse(str[1:])
			if val := l2[rev3]; val != 0 {
				return "YES"
			}
		}
	}

	return "NO"
}

func reverse(str string) string {
	b := strings.Builder{}
	for i := 0; i < len(str); i++ {
		b.WriteByte(str[len(str) - 1 - i])
	}
	return b.String()
}

func isPalindrome(str string) bool {
	for i := 0; i < len(str)/2; i++ {
		if str[i] != str[len(str) - 1 - i] {
			return false
		}
	}
	return true
}

func readInt(in *bufio.Reader) int {
nStr, _ := in.ReadString('\n')
nStr = strings.ReplaceAll(nStr, "\r", "")
nStr = strings.ReplaceAll(nStr, "\n", "")
n, _ := strconv.Atoi(nStr)
return n
}

func readLineNumbs(in *bufio.Reader) []string {
line, _ := in.ReadString('\n')
line = strings.ReplaceAll(line, "\r", "")
line = strings.ReplaceAll(line, "\n", "")
numbs := strings.Split(line, " ")
return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

package main

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

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

	t := readInt(in)
	b := strings.Builder{}
	for i := 0; i < t; i++ {
		str := solve(in)
		b.WriteString(str + "\n")
	}
	fmt.Println(b.String())
}

func solve(in *bufio.Reader) string {
	n := readInt(in)
	scenes := make([]string, n)
	mp := map[string]int{}
	mp2 := map[string]int{}
	mp3 := map[string]int{}

	ret := false
	for i := 0; i < n; i++ {
		str, _ := in.ReadString('\n')
		str = strings.ReplaceAll(str, "\r", "")
		str = strings.ReplaceAll(str, "\n", "")
		scenes[i] = str
		if len(scenes[i]) == 1 {
			ret = true
		}
		mp[scenes[i]]++
	}
	if ret {
		return "YES"
	}

	for i := 0; i < n; i++ {
		str := scenes[i]
		mp[str]--
		if isPalindrome(str) {
			return "YES"
		}
		if val := mp[reverse(str)]; val != 0 {
			return "YES"
		}

		if len(str) == 3 {
			mp3[str[:2]]++
			rstr := str[1:]
			if val := mp2[reverse(rstr)]; val != 0 {
				return "YES"
			}
			lstr := str[:2]
			if val := mp[reverse(lstr)]; val != 0 {
				return "YES'"
			}
		} else {
			mp2[str]++
			if val := mp3[reverse(str)]; val != 0 {
				return "YES"
			}
		}
	}

	return "NO"
}

func reverse(str string) string {
	b := strings.Builder{}
	for i := 0; i < len(str); i++ {
		b.WriteByte(str[len(str) - 1 - i])
	}
	return b.String()
}

func isPalindrome(str string) bool {
	for i := 0; i < len(str)/2; i++ {
		if str[i] != str[len(str) - 1 - i] {
			return false
		}
	}
	return true
}

func readInt(in *bufio.Reader) int {
nStr, _ := in.ReadString('\n')
nStr = strings.ReplaceAll(nStr, "\r", "")
nStr = strings.ReplaceAll(nStr, "\n", "")
n, _ := strconv.Atoi(nStr)
return n
}

func readLineNumbs(in *bufio.Reader) []string {
line, _ := in.ReadString('\n')
line = strings.ReplaceAll(line, "\r", "")
line = strings.ReplaceAll(line, "\n", "")
numbs := strings.Split(line, " ")
return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

package main

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

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

	t := readInt(in)
	b := strings.Builder{}
	for i := 0; i < t; i++ {
		str := solve(in)
		b.WriteString(str + "\n")
	}
	fmt.Println(b.String())
}

func solve(in *bufio.Reader) string {
	n := readInt(in)
	scenes := make([]string, n)
	mp := map[string]int{}
	mp2 := map[string]int{}

	ret := false
	for i := 0; i < n; i++ {
		str, _ := in.ReadString('\n')
		str = strings.ReplaceAll(str, "\r", "")
		str = strings.ReplaceAll(str, "\n", "")
		scenes[i] = str
		if len(scenes[i]) == 1 {
			ret = true
		}
		mp[scenes[i]]++
	}
	if ret {
		return "YES"
	}

	for i := 0; i < n; i++ {
		str := scenes[i]
		if isPalindrome(str) {
			return "YES"
		}
		if _, ok := mp[reverse(str)]; ok {
			return "YES"
		}

		if len(str) == 3 {
			rstr := str[1:]
			if _, ok := mp[reverse(rstr)]; ok {
				return "YES"
			}
			mp2[reverse(str[:2])]++
		} else {
			if _, ok := mp2[str]; ok {
				return "YES"
			}
		}
	}

	return "NO"
}

func reverse(str string) string {
	b := strings.Builder{}
	for i := 0; i < len(str); i++ {
		b.WriteByte(str[len(str) - 1 - i])
	}
	return b.String()
}

func isPalindrome(str string) bool {
	for i := 0; i < len(str)/2; i++ {
		if str[i] != str[len(str) - 1 - i] {
			return false
		}
	}
	return true
}

func readInt(in *bufio.Reader) int {
nStr, _ := in.ReadString('\n')
nStr = strings.ReplaceAll(nStr, "\r", "")
nStr = strings.ReplaceAll(nStr, "\n", "")
n, _ := strconv.Atoi(nStr)
return n
}

func readLineNumbs(in *bufio.Reader) []string {
line, _ := in.ReadString('\n')
line = strings.ReplaceAll(line, "\r", "")
line = strings.ReplaceAll(line, "\n", "")
numbs := strings.Split(line, " ")
return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

package main

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

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

	t := readInt(in)
	b := strings.Builder{}
	for i := 0; i < t; i++ {
		str := solve(in)
		b.WriteString(str + "\n")
	}
	fmt.Println(b.String())
}

func solve(in *bufio.Reader) string {
	n := readInt(in)
	scenes := make([]string, n)
	mp := map[string]int{}

	ret := false
	for i := 0; i < n; i++ {
		str, _ := in.ReadString('\n')
		str = strings.ReplaceAll(str, "\r", "")
		str = strings.ReplaceAll(str, "\n", "")
		scenes[i] = str
		if len(scenes[i]) == 1 {
			ret = true
		}
		mp[scenes[i]] = i
	}
	if ret {
		return "YES"
	}

	for i := 0; i < n; i++ {
		str := scenes[i]
		pal := isPalindrome(str)
		if pal {
			return "YES"
		}
		if len(str) == 2 {
			if _, ok := mp[reverse(str)]; ok {
				return "YES"
			}
		} else {
			l := str[:2]
			r := str[1:]
			rl := reverse(l)
			vall, okl := mp[rl]
			if vall > i && okl {
				return "YES"
			}
			rr := reverse(r)
			valr, okr := mp[rr]
			if valr < i && okr {
				return "YES"
			}
		}
	}

	return "NO"
}

func reverse(str string) string {
	b := strings.Builder{}
	for i := 0; i < len(str); i++ {
		b.WriteByte(str[len(str) - 1 - i])
	}
	return b.String()
}

func isPalindrome(str string) bool {
	for i := 0; i < len(str)/2; i++ {
		if str[i] != str[len(str) - 1 - i] {
			return false
		}
	}
	return true
}

func readInt(in *bufio.Reader) int {
nStr, _ := in.ReadString('\n')
nStr = strings.ReplaceAll(nStr, "\r", "")
nStr = strings.ReplaceAll(nStr, "\n", "")
n, _ := strconv.Atoi(nStr)
return n
}

func readLineNumbs(in *bufio.Reader) []string {
line, _ := in.ReadString('\n')
line = strings.ReplaceAll(line, "\r", "")
line = strings.ReplaceAll(line, "\n", "")
numbs := strings.Split(line, " ")
return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

package main

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

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

	t := readInt(in)
	b := strings.Builder{}
	for i := 0; i < t; i++ {
		b.WriteString(solve(in) + "\n")
	}
	fmt.Println(b.String())
}

func solve(in *bufio.Reader) string {
	n := readInt(in)
	scenes := make([]string, n)
	mp := map[string]struct{}{}

	for i := 0; i < n; i++ {
		str, _ := in.ReadString('\n')
		str = strings.ReplaceAll(str, "\r", "")
		str = strings.ReplaceAll(str, "\n", "")
		scenes[i] = str
		if len(scenes[i]) == 1 {
			return "YES"
		}
		mp[scenes[i]] = struct{}{}
	}

	for i := 0; i < n - 1; i++ {
		str1 := scenes[i]
		for j := i + 1; j < n; j++ {
			str2 := scenes[j]
			if isPalindrome(str1 + str2) {
				return "YES"
			}
		}
	}

	return "NO"
}

func isPalindrome(str string) bool {
	for i := 0; i < len(str)/2; i++ {
		if str[i] != str[len(str) - 1 - i] {
			return false
		}
	}
	return true
}

func readInt(in *bufio.Reader) int {
nStr, _ := in.ReadString('\n')
nStr = strings.ReplaceAll(nStr, "\r", "")
nStr = strings.ReplaceAll(nStr, "\n", "")
n, _ := strconv.Atoi(nStr)
return n
}

func readLineNumbs(in *bufio.Reader) []string {
line, _ := in.ReadString('\n')
line = strings.ReplaceAll(line, "\r", "")
line = strings.ReplaceAll(line, "\n", "")
numbs := strings.Split(line, " ")
return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

package main

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n int
		var found bool
		fmt.Fscan(r, &n)

		m := make(map[string]bool)

		for i := 0; i < n; i++ {
			var t string
			fmt.Fscan(r, &t)

			if m[t] || (len(t) == 3 && m[t[1:]]) || len(t) == 1 { found = true }
			var s string

			for i := range t { s += string(t[len(t)-1-i]) }
			// fmt.Fprintln(w, "*** s ", s) // **
			m[s] = true
			if len(s) == 3 { m[s[:2]] = true }
		}

		if found {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}
	}

}

package main

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n int
		var found bool
		fmt.Fscan(r, &n)

		m := make(map[string]bool)

		for i := 0; i < n; i++ {
			var t string
			fmt.Fscan(r, &t)

			if m[t] || (len(t) == 3 && m[t[1:]]) || len(t) == 1 { found = true }
			var s string

			for i := range t { s += string(t[len(t)-1-i]) }
			// fmt.Fprintln(w, "*** s ", s) // **
			m[s] = true
			if len(s) == 3 { m[s[1:]] = true }
		}

		if found {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}
	}

}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }

func isPal(s []byte) bool {
	for i := 0; i < len(s)-i-1; i++ {
		if s[i] != s[len(s)-i-1] {
			return false
		}
	}
	return true
}

func solveCase() bool {
	var n int
	scan(&n)
	var foundPal = false
	a := make([][]byte, n)
	for i := 0; i < n; i++ {
		scan(&a[i])
		foundPal = foundPal || isPal(a[i])
	}
	if foundPal {
		return true
	}

	seen := make(map[string]bool)
	seen2 := make(map[string]bool)
	for _, s := range a {
		if len(s) == 2 {
			// ab ba
			if seen[string([]byte{s[1], s[0]})] {
				return true
			}
			// abc ba
			if seen2[string([]byte{s[1], s[0]})] {
				return true
			}
		} else if len(s) == 3 {
			// abc cba
			if seen[string([]byte{s[2], s[1], s[0]})] {
				return true
			}
			// ab cba
			if seen[string([]byte{s[2], s[1]})] {
				return true
			}
			seen[string([]byte{s[2], s[1]})] = true
		}
		seen[string(s)] = true
	}
	return false
}

func main() {
	defer out.Flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		if solveCase() {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

package main

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

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

func reverse(s string) (res string) {
	for _, v := range s {
		res = string(v) + res
	}
	return res
}

var T, N int
var S []string

func solve() string {
	mp := map[string]int{}
	for i := 0; i < N; i++ {
		mp[S[i]] = 1
		if len(S[i]) == 1 || S[i] == reverse(S[i]) {
			return "YES"
		}
	}

	for i := 0; i < N; i++ {
		s := S[i]
		rs := reverse(s)

		if _, ok := mp[rs]; ok {
			return "YES"
		}

		for a := 'a'; a <= 'z'; a++ {
			if _, ok := mp[string(a) + rs]; ok {
				return "YES"
			}
		}
	}

	return "NO"
}

func main(){
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &T)
	for ; T > 0; T-- {
		fmt.Fscan(in, &N)
		S = make([]string, N)
		for i := 0; i < N; i++ {
			fmt.Fscan(in, &S[i])
		}

		fmt.Println(solve())
	}
}