You are given two binary strings $$$a$$$ and $$$b$$$ of the same length. You can perform the following two operations on the string $$$a$$$:  Swap any two bits at indices $$$i$$$ and $$$j$$$ respectively ($$$1 \le i, j \le n$$$), the cost of this operation is $$$|i - j|$$$, that is, the absolute difference between $$$i$$$ and $$$j$$$.  Select any arbitrary index $$$i$$$ ($$$1 \le i \le n$$$) and flip (change $$$0$$$ to $$$1$$$ or $$$1$$$ to $$$0$$$) the bit at this index. The cost of this operation is $$$1$$$. Find the minimum cost to make the string $$$a$$$ equal to $$$b$$$. It is not allowed to modify string $$$b$$$.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — the length of the strings $$$a$$$ and $$$b$$$. The second and third lines contain strings $$$a$$$ and $$$b$$$ respectively. Both strings $$$a$$$ and $$$b$$$ have length $$$n$$$ and contain only '0' and '1'.

Output the minimum cost to make the string $$$a$$$ equal to $$$b$$$.

NoteIn the first example, one of the optimal solutions is to flip index $$$1$$$ and index $$$3$$$, the string $$$a$$$ changes in the following way: "100" $$$\to$$$ "000" $$$\to$$$ "001". The cost is $$$1 + 1 = 2$$$.The other optimal solution is to swap bits and indices $$$1$$$ and $$$3$$$, the string $$$a$$$ changes then "100" $$$\to$$$ "001", the cost is also $$$|1 - 3| = 2$$$.In the second example, the optimal solution is to swap bits at indices $$$2$$$ and $$$3$$$, the string $$$a$$$ changes as "0101" $$$\to$$$ "0011". The cost is $$$|2 - 3| = 1$$$.

package main

import."fmt"
import"bufio"
import"os"

func main(){
	in:=bufio.NewReader(os.Stdin)
	var n int
	var a,b string
	Fscan(in,&n,&a,&b)

	if n==1{
		if a==b{
			Print(0)
		}else{
			Print(1)
		}
		return
	}
	cnt:=0
	prev:=byte('x')
	if a[0]!=b[0]{
		cnt=1
		prev=a[0]
	}
	for i:=1;i<n;i++{
		if a[i]==b[i]{
			prev='x'
			continue
		}
		if prev=='x'||prev==a[i]{
			cnt++
			if prev=='x'{
				prev=a[i]
			}
			continue
		}
		prev='x'
	}
	Print(cnt)
}

package main

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

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

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

var n int
var a, b string

func main() {
	fmt.Fscan(reader, &n, &a, &b)
	ans := 0
	for i := 0; i < n; i++ {
		if a[i] != b[i] {
			if i == n-1 {
				ans++
			} else if a[i] == b[i+1] && a[i+1] == b[i] {
				ans++
				i++
			} else {
				ans++
			}
		}
	}
	fmt.Println(ans)
}

package main

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

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 min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	defer writer.Flush()
	var n int
	scanf("%d\n", &n)
	var a, b string
	scanf("%s\n", &a)
	scanf("%s\n", &b)
	var aa, bb []byte
	aa = []byte(a)
	bb = []byte(b)
	swaps := 0
	toggles := 0
	for i := 0; i < n; i++ {
		if aa[i] != bb[i] {
			for j := i + 1; j < n; j++ {
				if aa[j] == bb[i] {
					aa[j] = aa[i]
					//	printf("%d %d\n", j, i)
					swaps += (j - i)
					break
				}
			}
		}
	}
	//printf("%v %v\n", aa, bb)
	//printf("%d %d\n", toggles, swaps)
	for i := 0; i < n; i++ {
		if a[i] != b[i] {
			toggles++
		}
	}
	printf("%d\n", min(toggles, swaps))
	// dp := make([][]int, n)
	// for i := 0; i < n; i++ {
	// 	dp[i] = make([]int, 2)
	// }
	// if a[0] == b[0] {
	// 	if a[0] == 0 {
	// 		dp[0][0] = 0
	// 		dp[0][1] = 1
	// 	} else {
	// 		dp[0][0] = 1
	// 		dp[0][1] = 0
	// 	}
	// }
	// for i := 1; i < n; i++ {
	// 	dp[i][0] = 1000
	// 	dp[i][1] = 1000
	// 	swap := 1000
	// 	if a[i] == b[i] {
	// 		if a[i] == 0 {
	// 			dp[i][0] = min(dp[i-1][0], dp[i-1][1])
	// 			dp[i][1] = min(dp[i-1][0], dp[i-1][1]) + 1
	// 		} else {
	// 			dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + 1
	// 			dp[i][1] = min(dp[i-1][0], dp[i-1][1])
	// 		}
	// 	}
	// 	for j := 0; j <= i; j++ {
	// 		if a[i] == 1 {
	// 			swap = min(swap, dp[j][1]+abs(j-i))
	// 		} else {
	// 			swap = min(swap, dp[j][0]+abs(j-i))
	// 		}
	// 		if a[j] != b[i] {
	// 			printf("(%v, %v) %v\n", i, j, swap)
	// 			if a[j] == 1 {
	// 				dp[i][1] = min(dp[i][1], swap+1)
	// 				dp[i][0] = min(dp[i][0], swap+0)
	// 			} else {
	// 				dp[i][1] = min(dp[i][1], swap+0)
	// 				dp[i][0] = min(dp[i][0], swap+1)
	// 			}
	// 		}
	// 	}
	// 	printf("swap=%v\n", swap)
	// }
	// printf("%v\n", dp)
	// printf("%d\n", min(dp[n-1][0], dp[n-1][1]))
}

package main

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

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 min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	defer writer.Flush()
	var n int
	scanf("%d\n", &n)
	var a, b string
	scanf("%s\n", &a)
	scanf("%s\n", &b)
	var aa, bb []byte
	aa = []byte(a)
	bb = []byte(b)
	swaps := 0
	toggles := 0
	for i := 0; i < n; i++ {
		if aa[i] != bb[i] {
			for j := i + 1; j < n; j++ {
				if aa[j] == bb[i] && aa[i] == bb[j] {
					aa[j] = aa[i]
					//printf("%d %d\n", j, i)
					swaps += (j - i)
					break
				}
			}
		}
	}
	if swaps == 0 {
		swaps = 1000000
	}
	//printf("%v %v\n", aa, bb)
	//printf("%d %d\n", toggles, swaps)
	for i := 0; i < n; i++ {
		if a[i] != b[i] {
			toggles++
		}
	}
	printf("%d\n", min(toggles, swaps))
	// dp := make([][]int, n)
	// for i := 0; i < n; i++ {
	// 	dp[i] = make([]int, 2)
	// }
	// if a[0] == b[0] {
	// 	if a[0] == 0 {
	// 		dp[0][0] = 0
	// 		dp[0][1] = 1
	// 	} else {
	// 		dp[0][0] = 1
	// 		dp[0][1] = 0
	// 	}
	// }
	// for i := 1; i < n; i++ {
	// 	dp[i][0] = 1000
	// 	dp[i][1] = 1000
	// 	swap := 1000
	// 	if a[i] == b[i] {
	// 		if a[i] == 0 {
	// 			dp[i][0] = min(dp[i-1][0], dp[i-1][1])
	// 			dp[i][1] = min(dp[i-1][0], dp[i-1][1]) + 1
	// 		} else {
	// 			dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + 1
	// 			dp[i][1] = min(dp[i-1][0], dp[i-1][1])
	// 		}
	// 	}
	// 	for j := 0; j <= i; j++ {
	// 		if a[i] == 1 {
	// 			swap = min(swap, dp[j][1]+abs(j-i))
	// 		} else {
	// 			swap = min(swap, dp[j][0]+abs(j-i))
	// 		}
	// 		if a[j] != b[i] {
	// 			printf("(%v, %v) %v\n", i, j, swap)
	// 			if a[j] == 1 {
	// 				dp[i][1] = min(dp[i][1], swap+1)
	// 				dp[i][0] = min(dp[i][0], swap+0)
	// 			} else {
	// 				dp[i][1] = min(dp[i][1], swap+0)
	// 				dp[i][0] = min(dp[i][0], swap+1)
	// 			}
	// 		}
	// 	}
	// 	printf("swap=%v\n", swap)
	// }
	// printf("%v\n", dp)
	// printf("%d\n", min(dp[n-1][0], dp[n-1][1]))
}


You want to perform the combo on your opponent in one popular fighting game. The combo is the string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in $$$s$$$. I.e. if $$$s=$$$"abca" then you have to press 'a', then 'b', 'c' and 'a' again.You know that you will spend $$$m$$$ wrong tries to perform the combo and during the $$$i$$$-th try you will make a mistake right after $$$p_i$$$-th button ($$$1 \le p_i < n$$$) (i.e. you will press first $$$p_i$$$ buttons right and start performing the combo from the beginning). It is guaranteed that during the $$$m+1$$$-th try you press all buttons right and finally perform the combo.I.e. if $$$s=$$$"abca", $$$m=2$$$ and $$$p = [1, 3]$$$ then the sequence of pressed buttons will be 'a' (here you're making a mistake and start performing the combo from the beginning), 'a', 'b', 'c', (here you're making a mistake and start performing the combo from the beginning), 'a' (note that at this point you will not perform the combo because of the mistake), 'b', 'c', 'a'.Your task is to calculate for each button (letter) the number of times you'll press it.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$1 \le m \le 2 \cdot 10^5$$$) — the length of $$$s$$$ and the number of tries correspondingly. The second line of each test case contains the string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. The third line of each test case contains $$$m$$$ integers $$$p_1, p_2, \dots, p_m$$$ ($$$1 \le p_i < n$$$) — the number of characters pressed right during the $$$i$$$-th try. It is guaranteed that the sum of $$$n$$$ and the sum of $$$m$$$ both does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$, $$$\sum m \le 2 \cdot 10^5$$$). It is guaranteed that the answer for each letter does not exceed $$$2 \cdot 10^9$$$.

For each test case, print the answer — $$$26$$$ integers: the number of times you press the button 'a', the number of times you press the button 'b', $$$\dots$$$, the number of times you press the button 'z'.

3
4 2
abca
1 3
10 5
codeforces
2 8 3 2 9
26 10
qwertyuioplkjhgfdsazxcvbnm
20 10 1 2 3 5 10 5 9 4

NoteThe first test case is described in the problem statement. Wrong tries are "a", "abc" and the final try is "abca". The number of times you press 'a' is $$$4$$$, 'b' is $$$2$$$ and 'c' is $$$2$$$.In the second test case, there are five wrong tries: "co", "codeforc", "cod", "co", "codeforce" and the final try is "codeforces". The number of times you press 'c' is $$$9$$$, 'd' is $$$4$$$, 'e' is $$$5$$$, 'f' is $$$3$$$, 'o' is $$$9$$$, 'r' is $$$3$$$ and 's' is $$$1$$$.

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
	"sync"
)

func main() {

	// var t int
	// fmt.Scan(&t)
	t := ScanInt()
	for ; t > 0; t-- {
		a, b := ScanInt(), ScanInt()
		// var s1 string
		// fmt.Scan(&s1)
		s1 := ScanWord()
		count := make([]int, a)
		p := ScanIntSlice(b)
		for i := 0; i < b; i++ {
			count[p[i]-1]++
		}
		for i := a - 2; i >= 0; i-- {
			count[i] += count[i+1]
		}
		alpha := make([]int, 26)
		for i := 0; i < a; i++ {
			alpha[s1[i]-'a'] += count[i]
		}
		for _, c := range s1 {
			alpha[c-'a']++
		}
		for i := 0; i < 26; i++ {
			fmt.Print(alpha[i], " ")

		}

	}
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

const MAXN = 200010

var f [MAXN]int
var cnt, res [26]int
var s string

func main() {
	var t int
	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d\n", &t)
	for test := 1; test <= t; test++ {
		s := readLine(reader)
		ss := strings.Split(string(s), " ")
		n, _ := strconv.Atoi(ss[0])
		m, _ := strconv.Atoi(ss[1])

		str := readLine(reader)

		s = readLine(reader)
		ss = strings.Split(string(s), " ")

		for i := 1; i <= n; i++ {
			f[i] = 0
		}
		for i := 0; i < m; i++ {
			x, _ := strconv.Atoi(ss[i])
			f[x]++
		}
		f[n]++

		for i := 0; i < 26; i++ {
			cnt[i] = 0
			res[i] = 0
		}

		for i := 1; i <= n; i++ {
			cnt[str[i-1]-'a']++
			if f[i] > 0 {
				for j := 0; j < 26; j++ {
					res[j] += f[i] * cnt[j]
				}
			}
		}

		for i := 0; i < 26; i++ {
			fmt.Printf("%d ", res[i])
		}
		fmt.Println()
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			// fmt.Println(string(result))
			break
		}
	}
	return result
}

/**
 * Copyright shopee
 * @Author : Yuxiang.Lei
 * @MailBox: Yuxiang.Lei@shopee.com
 * @Date : 2020-02-24
 * @Version: v2.4
 **/

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		s := readLine(reader)
		ss := strings.Split(string(s), " ")
		n, _ := strconv.Atoi(ss[0])
		m, _ := strconv.Atoi(ss[1])
		str := readLine(reader)
		s = readLine(reader)
		ss = strings.Split(string(s), " ")
		nums := make([]int, 0)
		mnums := make(map[int]int)
		result := make([]int, 26)
		for i := 0; i < m; i++ {
			temp, _ := strconv.Atoi(ss[i])
			if count, ok := mnums[temp-1]; ok {
				count++
				mnums[temp-1] = count
			} else {
				nums = append(nums, temp-1)
				mnums[temp-1] = 1
			}
		}
		sort.Ints(nums)
		j, wloc, times :=0, nums[0], mnums[nums[0]]
		sum := m
		// fmt.Println(nums, mnums)
		for i:=0;i<n;i++ {
			// fmt.Println(result)
			index := str[i] - 'a'
			if i < wloc {
				result[index] += sum + 1
				continue
			}
			if i<= wloc {
				result[index] += sum + 1
				j++
				if j < len(nums) {
					sum -= times
					wloc = nums[j]
					times = mnums[wloc]
				}
				// fmt.Println(j, wloc, times, sum)
				continue
			}
			result[index]++

		}
		for i:=0;i<len(result);i++ {
			fmt.Printf("%d ", result[i])
		}
		fmt.Println()
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			// fmt.Println(string(result))
			break
		}
	}
	return result
}

/*
URL:
https://codeforces.com/problemset/problem/1311/C
*/

package main

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

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

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

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

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

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

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

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t    int
	n, m int
	S    []rune
	P    []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, m = ReadInt2()
		S = ReadRuneSlice()
		P = ReadIntSlice(m)

		solve()
	}
}

func solve() {
	B := [30][]int{}
	pref := [30][]int{}
	for i := 0; i < ALPHABET_NUM; i++ {
		B[i] = make([]int, n)
		pref[i] = make([]int, n+1)
	}

	for i := 0; i < n; i++ {
		B[S[i]-'a'][i]++
	}

	for i := 0; i < ALPHABET_NUM; i++ {
		for j := 0; j < n; j++ {
			pref[i][j+1] = pref[i][j] + B[i][j]
		}
	}

	answers := [30]int64{}

	for i := 0; i < m; i++ {
		p := P[i]
		for j := 0; j < ALPHABET_NUM; j++ {
			answers[j] += int64(pref[j][p])
		}
	}
	for j := 0; j < ALPHABET_NUM; j++ {
		answers[j] += int64(pref[j][n])
	}

	fmt.Println(PrintInts64Line(answers[:ALPHABET_NUM]...))
}

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

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

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T, n, m, v int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m, &s)
		d := make([]int, n)
		for d[0] = m; m > 0; m-- {
			Fscan(in, &v)
			d[v]--
		}
		cnt, c := [26]int{}, 0
		for i, v := range d {
			c += v
			cnt[s[i]-'a'] += c + 1
		}
		for _, v := range cnt {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
	"sync"
)

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, m := ScanInt(), ScanInt()
		stringValue := ScanWord()
		pArray := ScanIntSlice(m)
		answerArray := make([]int, 26)
		processArray := make([]int, n+1)
		sum := 1
		stringValue = "." + stringValue

		//for i := 1; i<= n; i++{
		//	processArray[i] = 0
		//}
		//
		//for i := 0; i < 26; i++{
		//	answerArray[i] = 0
		//}

		for i := 1; i <= m; i++{
			processArray[1]++
			processArray[pArray[i-1]+1]--
		}

		for i := 1; i <= n; i++{
			sum += processArray[i]
			answerArray[stringValue[i] - 'a'] += sum
		}

		for i := 0; i < 26; i++{
			fmt.Print(answerArray[i]," ")

		}

		fmt.Println()
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
	"sync"
)

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, m := ScanInt(), ScanInt()
		stringValue := ScanWord()
		pArray := ScanIntSlice(m)
		answerArray := make([]int, 26)
		processArray := make([]int, n+1)
		sum := 1
		stringValue = "." + stringValue

		for i := 1; i<= n; i++{
			processArray[i] = 0
		}

		for i := 0; i < 26; i++{
			answerArray[i] = 0
		}

		for i := 1; i <= m; i++{
			processArray[1]++
			processArray[pArray[i-1]+1]--
		}

		for i := 1; i <= n; i++{
			sum += processArray[i]
			answerArray[stringValue[i] - 'a'] += sum
		}

		for i := 0; i < 26; i++{
			fmt.Print(answerArray[i]," ")

		}

		fmt.Println()
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}


Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice!Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drink only. After they ran out of the first barrel of juice, they decided to play a simple game. All n people who came to the barbecue sat in a circle (thus each person received a unique index bi from 0 to n - 1). The person number 0 started the game (this time it was Vasya). All turns in the game were numbered by integers starting from 1. If the j-th turn was made by the person with index bi, then this person acted like that:  he pointed at the person with index (bi + 1) mod n either with an elbow or with a nod (x mod y is the remainder after dividing x by y);  if j ≥ 4 and the players who had turns number j - 1, j - 2, j - 3, made during their turns the same moves as player bi on the current turn, then he had drunk a glass of juice;  the turn went to person number (bi + 1) mod n. The person who was pointed on the last turn did not make any actions.The problem was, Vasya's drunk too much juice and can't remember the goal of the game. However, Vasya's got the recorded sequence of all the participants' actions (including himself). Now Vasya wants to find out the maximum amount of juice he could drink if he played optimally well (the other players' actions do not change). Help him.You can assume that in any scenario, there is enough juice for everybody.

The first line contains a single integer n (4 ≤ n ≤ 2000) — the number of participants in the game. The second line describes the actual game: the i-th character of this line equals 'a', if the participant who moved i-th pointed at the next person with his elbow, and 'b', if the participant pointed with a nod. The game continued for at least 1 and at most 2000 turns.

Print a single integer — the number of glasses of juice Vasya could have drunk if he had played optimally well.

NoteIn both samples Vasya has got two turns — 1 and 5. In the first sample, Vasya could have drunk a glass of juice during the fifth turn if he had pointed at the next person with a nod. In this case, the sequence of moves would look like "abbbb". In the second sample Vasya wouldn't drink a single glass of juice as the moves performed during turns 3 and 4 are different.

package main
import (
	"fmt"
	//"sort"
	"unicode/utf8"
)
func main() {
	var n,hsl int
	var s string
	fmt.Scan(&n,&s)
	d:=utf8.RuneCountInString(s)
	for i:=n;i<d;i+=n {
		if s[i-3]==s[i-2] && s[i-2]==s[i-1] {
			hsl++
		}
	}
	fmt.Println(hsl)
}

package main

import "fmt"

func main() {
	var input string
	var num, ans int = 0, 0
	fmt.Scan(&num, &input)
	for i:=0; i<len(input); i++ {
		if (i%num==0) && (i>=3) && (input[i-1] == input[i-2]) && (input[i-1] == input[i-3]){
			ans++
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"

func main() {
    var n int
    var s string
    fmt.Scan(&n)
    fmt.Scan(&s)
    ans, cnt, prev, b := 0, 0, byte(0), 0
    for i := 0; i < len(s); i++ {
        if b == 0 {
            if cnt >= 3 { ans++ }
            if prev == 0 { prev = s[i] }
        } else {
            if s[i] == prev {
                cnt++
            } else {
                prev = s[i]
                cnt = 1
            }
        }
        b = (b+1)%n
    }
    fmt.Println(ans)
}

package main

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

type Scanner struct {
  r            io.Reader
  split        bufio.SplitFunc
  maxTokenSize int
  token, buf   []byte
  start, end   int
}

func NewScanner(r io.Reader) *Scanner {
  return &Scanner{
    r:            r,
    split:        bufio.ScanWords,
    maxTokenSize: 16777216,
    buf:          make([]byte, 4096),
  }
}

func (s *Scanner) advance(n int) bool {
  if n < 0 || n > s.end-s.start {
    return false
  }
  s.start += n
  return true
}

func (s *Scanner) Text() string {
  return string(s.token)
}

func (s *Scanner) Scan() bool {
  for {
    if s.end > s.start {
      advance, token, err := s.split(s.buf[s.start:s.end], false)
      if err != nil || !s.advance(advance) {
        return false
      }
      s.token = token
      if token != nil {
        return true
      }
    }
    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
    }
    if s.end == len(s.buf) {
      if len(s.buf) >= s.maxTokenSize {
        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
    }
    for loop := 0; ; {
      n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
      s.end += n
      if n > 0 {
        break
      }
      loop++
      if loop > 100 {
        break
      }
    }
  }
}

func (s *Scanner) Split(split bufio.SplitFunc) {
  s.split = split
}

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var sc *Scanner = NewScanner(os.Stdin)

func next() string { sc.Scan(); return sc.Text() }

func ni32() int {
  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())
  return n
}

func ni64() int64 {
  sc.Scan()
  n, _ := strconv.ParseInt(sc.Text(), 10, 64)
  return n
}

func pri32(i int)   { w.WriteString(strconv.Itoa(i)) }
func pri64(i int64) { w.WriteString(strconv.FormatInt(i, 10)) }
func sp()           { w.WriteByte(' ') }
func endl()         { w.WriteByte('\n') }

func main() {
  n := ni32()
  s := next()
  m := len(s)
  who := make([]int, m)
  who[0] = 0
  for i := 1; i < m; i++ {
    who[i] = (who[i-1] + 1) % n
  }
  ans := 0
  for i := 3; i < m; i++ {
    if who[i] == 0 {
      if s[i-1] == s[i-2] && s[i-1] == s[i-3] {
        ans++
      }
    }
  }
  pri32(ans)
  w.Flush()
}

// 332A-mic
package main

import (
    "fmt"
)

func main() {
    var n, q, j int
    var s string
    fmt.Scan(&n)
    fmt.Scan(&s)
    if len(s) < 4 {
        fmt.Println("0")
        return
    }

    for q = n; q < len(s); q += n {
        if s[q-1] == s[q-2] {
            if s[q-2] == s[q-3] {
                j++
            }
        }
    }
    fmt.Println(j)
}

package main

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

type Scanner struct {
  r            io.Reader
  split        bufio.SplitFunc
  maxTokenSize int
  token, buf   []byte
  start, end   int
}

func NewScanner(r io.Reader) *Scanner {
  return &Scanner{
    r:            r,
    split:        bufio.ScanWords,
    maxTokenSize: 16777216,
    buf:          make([]byte, 4096),
  }
}

func (s *Scanner) advance(n int) bool {
  if n < 0 || n > s.end-s.start {
    return false
  }
  s.start += n
  return true
}

func (s *Scanner) Text() string {
  return string(s.token)
}

func (s *Scanner) Scan() bool {
  for {
    if s.end > s.start {
      advance, token, err := s.split(s.buf[s.start:s.end], false)
      if err != nil || !s.advance(advance) {
        return false
      }
      s.token = token
      if token != nil {
        return true
      }
    }
    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
    }
    if s.end == len(s.buf) {
      if len(s.buf) >= s.maxTokenSize {
        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
    }
    for loop := 0; ; {
      n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
      s.end += n
      if n > 0 {
        break
      }
      loop++
      if loop > 100 {
        break
      }
    }
  }
}

func (s *Scanner) Split(split bufio.SplitFunc) {
  s.split = split
}

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var sc *Scanner = NewScanner(os.Stdin)

func next() string { sc.Scan(); return sc.Text() }

func ni32() int {
  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())
  return n
}

func ni64() int64 {
  sc.Scan()
  n, _ := strconv.ParseInt(sc.Text(), 10, 64)
  return n
}

func pri32(i int)   { w.WriteString(strconv.Itoa(i)) }
func pri64(i int64) { w.WriteString(strconv.FormatInt(i, 10)) }
func sp()           { w.WriteByte(' ') }
func endl()         { w.WriteByte('\n') }

func main() {
  n := ni32()
  s := next()
  m := len(s)
  who := make([]int, m)
  who[0] = 0
  for i := 1; i < m; i++ {
    who[i] = (who[i-1] + 1) % n
  }
  ans := 0
  for i := 3; i < m; i++ {
    if who[i] == 0 {
      if who[i-1] == 0 {
        if who[i-2] == 0 || who[i-3] == 0 || s[who[i-2]] == s[who[i-3]] {
          ans++
        }
      } else if who[i-2] == 0 {
        if who[i-1] == 0 || who[i-3] == 0 || s[who[i-1]] == s[who[i-3]] {
          ans++
        }
      } else if who[i-3] == 0 {
        if who[i-1] == 0 || who[i-2] == 0 || s[who[i-1]] == s[who[i-2]] {
          ans++
        }
      } else if s[who[i-1]] == s[who[i-2]] && s[who[i-1]] == s[who[i-3]] {
        ans++
      }
    }
  }
  pri32(ans)
  w.Flush()
}

package main

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

type Scanner struct {
  r            io.Reader
  split        bufio.SplitFunc
  maxTokenSize int
  token, buf   []byte
  start, end   int
}

func NewScanner(r io.Reader) *Scanner {
  return &Scanner{
    r:            r,
    split:        bufio.ScanWords,
    maxTokenSize: 16777216,
    buf:          make([]byte, 4096),
  }
}

func (s *Scanner) advance(n int) bool {
  if n < 0 || n > s.end-s.start {
    return false
  }
  s.start += n
  return true
}

func (s *Scanner) Text() string {
  return string(s.token)
}

func (s *Scanner) Scan() bool {
  for {
    if s.end > s.start {
      advance, token, err := s.split(s.buf[s.start:s.end], false)
      if err != nil || !s.advance(advance) {
        return false
      }
      s.token = token
      if token != nil {
        return true
      }
    }
    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
    }
    if s.end == len(s.buf) {
      if len(s.buf) >= s.maxTokenSize {
        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
    }
    for loop := 0; ; {
      n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
      s.end += n
      if n > 0 {
        break
      }
      loop++
      if loop > 100 {
        break
      }
    }
  }
}

func (s *Scanner) Split(split bufio.SplitFunc) {
  s.split = split
}

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var sc *Scanner = NewScanner(os.Stdin)

func next() string { sc.Scan(); return sc.Text() }

func ni32() int {
  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())
  return n
}

func ni64() int64 {
  sc.Scan()
  n, _ := strconv.ParseInt(sc.Text(), 10, 64)
  return n
}

func pri32(i int)   { w.WriteString(strconv.Itoa(i)) }
func pri64(i int64) { w.WriteString(strconv.FormatInt(i, 10)) }
func sp()           { w.WriteByte(' ') }
func endl()         { w.WriteByte('\n') }

func main() {
  n := ni32()
  s := next()
  m := len(s)
  who := make([]int, m)
  for i := 1; i < m; i++ {
    who[i] = (who[i-1] + 1) % n
  }
  ans := 0
  for i := 3; i < m; i++ {
    if who[i] == 0 {
      if s[who[i-1]] == s[who[i-2]] && s[who[i-1]] == s[who[i-3]] {
        ans++
      }
    }
  }
  pri32(ans)
  w.Flush()
}


There is a binary string $$$a$$$ of length $$$n$$$. In one operation, you can select any prefix of $$$a$$$ with an equal number of $$$0$$$ and $$$1$$$ symbols. Then all symbols in the prefix are inverted: each $$$0$$$ becomes $$$1$$$ and each $$$1$$$ becomes $$$0$$$.For example, suppose $$$a=0111010000$$$.   In the first operation, we can select the prefix of length $$$8$$$ since it has four $$$0$$$'s and four $$$1$$$'s: $$$[01110100]00\to [10001011]00$$$.  In the second operation, we can select the prefix of length $$$2$$$ since it has one $$$0$$$ and one $$$1$$$: $$$[10]00101100\to [01]00101100$$$.  It is illegal to select the prefix of length $$$4$$$ for the third operation, because it has three $$$0$$$'s and one $$$1$$$. Can you transform the string $$$a$$$ into the string $$$b$$$ using some finite number of operations (possibly, none)?

The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1\le n\le 3\cdot 10^5$$$) — the length of the strings $$$a$$$ and $$$b$$$. The following two lines contain strings $$$a$$$ and $$$b$$$ of length $$$n$$$, consisting of symbols $$$0$$$ and $$$1$$$. The sum of $$$n$$$ across all test cases does not exceed $$$3\cdot 10^5$$$.

For each test case, output "YES" if it is possible to transform $$$a$$$ into $$$b$$$, or "NO" if it is impossible. You can print each letter in any case (upper or lower).

NoteThe first test case is shown in the statement.In the second test case, we transform $$$a$$$ into $$$b$$$ by using zero operations.In the third test case, there is no legal operation, so it is impossible to transform $$$a$$$ into $$$b$$$.In the fourth test case, here is one such transformation:   Select the length $$$2$$$ prefix to get $$$100101010101$$$.  Select the length $$$12$$$ prefix to get $$$011010101010$$$.  Select the length $$$8$$$ prefix to get $$$100101011010$$$.  Select the length $$$4$$$ prefix to get $$$011001011010$$$.  Select the length $$$6$$$ prefix to get $$$100110011010$$$. In the fifth test case, the only legal operation is to transform $$$a$$$ into $$$111000$$$. From there, the only legal operation is to return to the string we started with, so we cannot transform $$$a$$$ into $$$b$$$.

package main

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

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

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

func main() {
	defer writer.Flush()
	var n int
	_, err := scanf("%d\n", &n)
	if err != nil {
		panic(err)
	}

	for i := 0; i < n; i++ {
		var l int
		_, err := scanf("%d\n", &l)
		if err != nil {
			panic(err)
		}
		a, err := get_slice()
		if err != nil {
			panic(err)
		}
		b, err := get_slice()
		if err != nil {
			panic(err)
		}
		if t := can_transform(a, b); t {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

func get_slice() ([]bool, error) {
	var s string
	_, err := scanf("%s\n", &s)
	if err != nil {
		return nil, err
	}
	a := make([]bool, len(s))
	for j := 0; j < len(s); j++ {
		a[j] = s[j] == '1'
	}
	return a, nil
}

func can_transform(a, b []bool) bool {
	swap_locs := swap_locations(a)
	flip := false
	for i := len(a) - 1; i >= 0; i-- {
		if (a[i] != flip) == b[i] {
			continue
		}
		if !swap_locs[i] {
			return false
		}
		flip = !flip
	}
	return true
}

func swap_locations(a []bool) []bool {
	score := 0
	locs := make([]bool, len(a))
	for i := 0; i < len(a); i++ {
		if a[i] {
			score++
		} else {
			score--
		}
		locs[i] = score == 0
	}
	return locs
}

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		a, b := make([]byte, n), make([]byte, n)
		Fscan(in, &a, &b)

		nums := make([][2]int, n + 1)
		for i := 1; i <= n; i++ {
			if a[i - 1] == '1' {
				nums[i][0], nums[i][1] = nums[i-1][0], nums[i-1][1]+1
			} else {
				nums[i][0], nums[i][1] = nums[i-1][0] + 1, nums[i-1][1]
			}
		}

		var pos []int
		left, right := 0, 0
		for left < n && right < n {
			for left < n && a[left] == b[left] {
				left++
			}
			right = left
			if left < n && left >= 1 {
				pos = append(pos, left)
			}
			for right < n && a[right] != b[right] {
				right++
			}
			if right <= n && right > left {
				pos = append(pos, right)
			}
			left = right
		}

		//Fprintln(out, "pos: ", pos)
		flag := true
		for _, val := range pos {
			if nums[val][0] != nums[val][1] {
				flag = false
				Fprintln(out, "NO")
				break
			}
		}
		if flag {
			Fprintln(out, "YES")
		}
	}
}

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

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

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

func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

package main

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

var in = NewIn()
var out = NewOut()

func main() {
	defer out.flush()

	cases()
	// solve()
}

/* --- Solution B --- */
func solve() {
	n := in.nextInt()

	from := in.next()
	to := in.next()

	if n == 1 && from != to {
		out.println("NO")
		return
	}

	ok := true
	zeros, ones := 0, 0
	eq, diff := 0, 0
	for i := 0; i < n; i++ {
		if from[i] == '0' {
			zeros++
		} else {
			ones++
		}
		if from[i] == to[i] {
			eq++
		} else {
			diff++
		}

		if zeros == ones {
			if diff*eq != 0 {
				ok = false
				break
			}
			eq, diff = 0, 0
			zeros, ones = 0, 0
		}
	}

	if ok && diff == 0 {
		out.println("YES")
	} else {
		out.println("NO")
	}
}

func cases() {
	t := in.nextInt()
	for ; t > 0; t-- {
		solve()
	}
}

/* --- I/O --- */
const BUF_MAX_CAP int = 1e6

type In struct {
	scanner *bufio.Scanner
}

func NewIn() *In {
	scn := bufio.NewScanner(os.Stdin)

	buf := make([]byte, BUF_MAX_CAP)
	scn.Buffer(buf, BUF_MAX_CAP)
	scn.Split(bufio.ScanWords)

	return &In{scn}
}

func (in *In) nextInt() int {
	in.scanner.Scan()
	i, _ := strconv.Atoi(in.scanner.Text())
	return i
}

func (in *In) nextLong() int64 {
	in.scanner.Scan()
	i, _ := strconv.ParseInt(in.scanner.Text(), 10, 64)
	return i
}

func (in *In) next() string {
	in.scanner.Scan()
	return in.scanner.Text()
}

type Out struct {
	writer *bufio.Writer
}

func NewOut() *Out {
	out := Out{bufio.NewWriter(os.Stdout)}
	return &out
}

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

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

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

func (out *Out) flush() {
	out.writer.Flush()
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(input, &n)
		A := make([]byte, 0)
		B := make([]byte, 0)
		DIFFERENET := make([]int, n+1)
		ANOTHER := make([]int, 0)
		ALLOWED := make([]int, n+1)
		fmt.Fscan(input, &A)
		fmt.Fscan(input, &B)
		ZEROS := 0
		ONES := 0
		for i := 0; i < n; i++ {
			if string(A[i]) == "1" {
				ONES++

			} else {
				ZEROS++
			}
			if string(A[i]) != string(B[i]) {
				DIFFERENET[i+1] = 1
			}
			if ONES == ZEROS {
				ALLOWED[i+1] = 1
			}
		}
		DIFFERENET = append(DIFFERENET, 0)

		for q := 1; q < n+1; q++ {
			if (DIFFERENET[q] + DIFFERENET[q+1]) == 1 {
				ANOTHER = append(ANOTHER, q)
			}
		}
		k := len(ANOTHER)

		jj := 0
		for i := 0; i < k; i++ {
			if ALLOWED[ANOTHER[i]] == 0 {
				fmt.Println("NO")
				jj = 1
				break
			}
		}
		if jj == 0 {

			fmt.Println("YES")
		}

	}
}

package main

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

/*
1
10
0111010000
0100101100
---
YES
=========
1
2
10
00
---
NO
*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	bld := strings.Builder{}

	var t int
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		var a, b string
		scanf("%s\n%s\n", &a, &b)

		if n%2 != 0 && a[n-1] != b[n-1] {
			fmt.Fprintf(&bld, "NO\n")
			continue
		}

		possible := true

		flipCnt := 0
		oneCnt := strings.Count(a, "1")

		for i := n - 1; i >= 0; i-- {
			ai := a[i]
			if flipCnt%2 != 0 {
				if ai == '0' {
					ai = '1'
				} else {
					ai = '0'
				}
			}

			ok := ai == b[i]
			if ok {
				if ai == '1' {
					oneCnt--
				}
				continue
			}

			zeroCnt := i - oneCnt + 1
			flippable := oneCnt == zeroCnt

			if flippable {
				if b[i] == '1' {
					oneCnt--
				}
				flipCnt++
			} else {
				possible = false
				break
			}
		}

		if possible {
			fmt.Fprintf(&bld, "YES\n")
		} else {
			fmt.Fprintf(&bld, "NO\n")
		}
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

//goland:noinspection GoUnusedType
type pair struct {
	fst rune
	snd int
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//goland:noinspection GoUnusedFunction
func isPrime(n int) bool {
	if n == 2 || n == 3 {
		return true
	}

	if n <= 1 || n%2 == 0 || n%3 == 0 {
		return false
	}

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(i+2) == 0 {
			return false
		}
	}

	return true
}

package main

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

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

	var T, n int
	var s, t []byte
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &s, &t)
		for ; n > 0 && s[n-1] == t[n-1]; n-- {
		}
		c := [2]int{}
		for i, b := range s[:n] {
			if c[0] != c[1] && b == t[i] != (s[i-1] == t[i-1]) {
				break
			}
			c[b&1]++
		}
		if c[0] != c[1] {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
		}
	}
}

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

package main

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

func check(str1, str2 string, l, r int) bool {
	cnt := 0
	for i := l; i <= r; i++ {
		if str1[i] == str2[i] {
			cnt++
		}
	}
	if cnt == 0 || cnt == r-l+1 {
		return true
	}
	return false
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscanf(in, "%d\n", &t)
	for case_idx := 0; case_idx < t; case_idx++ {
		var len int
		var s1, s2 string
		fmt.Fscanf(in, "%d\n%s\n%s\n", &len, &s1, &s2)
		one_cnt := 0
		zero_cnt := 0
		l := 0
		r := 0
		success := true
		for i := 0; i < len; i++ {
			if s1[i] == '0' {
				zero_cnt++
			} else {
				one_cnt++
			}
			if one_cnt == zero_cnt {
				r = i
				success = check(s1, s2, l, r)
				if !success {
					break
				}
				l = r + 1
			}
		}
		if r <= l && r != len {
			for i := l; i < len; i++ {
				if s1[i] != s2[i] {
					success = false
					break
				}
			}
		}
		if success {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
	out.Flush()
}

package main

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

func binSearchLE(arr []int, target int) int {
	start := 0
	end := len(arr) - 1
	ans := -1
	for start <= end {
		mid := (start + end) / 2
		if arr[mid] <= target {
			start = mid + 1
		}
		if arr[mid] > target {
			ans = mid
			end = mid - 1
		}
	}
	if ans == -1 {
		if end == len(arr)-1 {
			return len(arr)
		} else {
			return 0
		}
	}
	return ans
}

func sol(a, b string) string {
	if a == b {
		return "YES"
	}
	counts0 := make([]int, len(a))
	counts1 := make([]int, len(a))

	c0, c1 := 0, 0
	for i := range a {
		if a[i] == '0' {
			c0++
		} else {
			c1++
		}
		counts0[i] = c0
		counts1[i] = c1
	}

	flipped := false
	for i := len(a)-1; i >= 0; i-- {
		if !flipped {
			if a[i] == b[i] {
				continue
			}
		} else {
			if a[i] != b[i] {
				continue
			}
		}

		if counts0[i] != counts1[i] {
			return "NO"
		}
		//log.Println("flip at:", i)
		flipped = !flipped
	}

	return "YES"
}

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

//func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(os.Stdout, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanIntsArr(arrLen int) []int {
	arr := make([]int, arrLen)
	for i := 0; i < len(arr); i++ {
		scanf("%d", &arr[i])
	}
	scanf("\n")
	return arr
}
func scanIntsArr64(arrLen int) []int64 {
	arr := make([]int64, arrLen)
	for i := 0; i < len(arr); i++ {
		scanf("%d", &arr[i])
	}
	scanf("\n")
	return arr
}
func scanIntsLines(arrLen int) []int {
	arr := make([]int, arrLen)
	for i := 0; i < len(arr); i++ {
		scanf("%d\n", &arr[i])
	}
	return arr
}
func printIntsLines(arr []int) {
	for i := 0; i < len(arr); i++ {
		printf("%d\n", arr[i])
	}
}
func scanStrsLines(arrLen int) []string {
	arr := make([]string, arrLen)
	for i := 0; i < len(arr); i++ {
		scanf("%s\n", &arr[i])
	}
	return arr
}
func printStrsLines(arr []string) {
	for i := 0; i < len(arr); i++ {
		printf("%s\n", arr[i])
	}
}

func main() {
	n := 0
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		m := 0
		a, b := "", ""
		scanf("%d\n", &m)
		scanf("%s\n", &a)
		scanf("%s\n", &b)
		printf("%s\n", sol(a, b))
	}
}

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}

func (s *Scanner) next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}

func (s *Scanner) nextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}

func (s *Scanner) nextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

func (s *Scanner) nextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}

func max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func main() {
	sc := NewScanner()
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	TC := sc.nextInt()
	for tc := 0; tc < TC; tc++ {
		N := sc.nextInt()
		a := sc.next()
		b := sc.next()

		mask := make([]int, N)
		for i := 0; i < N; i++ {
			mask[i] = 0
			if a[i] != b[i] {
				mask[i] = 1
			}
		}

		prefixSum := make([]int, N)
		prefixSum[0] = int(a[0] - '0')
		for i := 1; i < N; i++ {
			prefixSum[i] = prefixSum[i-1] + int(a[i]-'0')
		}

		curFlip := 0
		canTransform := true
		for i := N - 1; i >= 0 && canTransform; i-- {
			if mask[i]^curFlip == 1 {
				// it's even range and #1 == #0
				if i%2 == 1 && 2*prefixSum[i] == i+1 {
					curFlip ^= 1
				} else {
					canTransform = false
				}
			}
		}
		if canTransform {
			fmt.Fprintln(wr, "YES")
		} else {
			fmt.Fprintln(wr, "NO")
		}
	}

}

package main

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

var reader *bufio.Reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

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

type Pair struct {
	x, y int
}

type Pairs []Pair

func (a Pairs) Len() int           { return len(a) }
func (a Pairs) Less(i, j int) bool { return a[i].x < a[j].x }
func (a Pairs) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

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

func flip(s *[]rune) {
	for i, j := 0, len(*s)-1; i < len(*s)/2; {
		if (*s)[i] == 1 {
			(*s)[i] = 0
		} else {
			(*s)[i] = 1
		}
		if (*s)[j] == 1 {
			(*s)[i] = 0
		} else {
			(*s)[i] = 1
		}
		i++
		j--
	}
}

func reverseRune(s *[]rune) {
	for i, j := 0, len(*s)-1; i < len(*s)/2; {
		(*s)[i], (*s)[j] = (*s)[j], (*s)[i]
		i++
		j--
	}
}

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	for t > 0 {
		var n int
		scanf("%d\n", &n)
		var a, b string
		f := true
		scanf("%s\n%s\n", &a, &b)
		a, b = a+"0", b+"0"
		cnt := 0
		for i := 0; i < n; i++ {
			if a[i] == '1' {
				cnt++
			} else {
				cnt--
			}
			if (a[i] == b[i]) != (a[i+1] == b[i+1]) && cnt != 0 {
				printf("%s\n", "NO")
				f = false
				break
			}
		}
		if f == true {
			printf("%s\n", "YES")
		}
		t--
	}
}

package main

import (
	"fmt"
)

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

	for i := 0; i < n; i++ {
		var l int
		var s string
		_, err := fmt.Scanf("%d\n", &l)
		if err != nil {
			panic(err)
		}
		a := make([]bool, l)
		_, err = fmt.Scanln(&s)
		if err != nil {
			panic(err)
		}
		for j := 0; j < l; j++ {
			a[j] = s[j] == '1'
		}
		b := make([]bool, l)
		_, err = fmt.Scanln(&s)
		if err != nil {
			panic(err)
		}
		for j := 0; j < l; j++ {
			b[j] = s[j] == '1'
		}
		if t := can_transform(a, b, make(map[string]bool)); t {
			println("YES")
		} else {
			println("NO")
		}
	}
}

func equal(a, b []bool) bool {
	for i := range a {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func flip_first(n int, a []bool) []bool {
	var new []bool
	for i := 0; i < n; i++ {
		new = append(new, !a[i])
	}
	for i := n; i < len(a); i++ {
		new = append(new, a[i])
	}
	return new
}

func can_transform(a, b []bool, seen map[string]bool) bool {
	if have_seen := seen[fmt.Sprint(a)]; have_seen {
		return false
	}
	seen[fmt.Sprint(a)] = true
	if equal(a, b) {
		return true
	}
	score := 0
	for i := 0; i < len(a); i++ {
		if a[i] {
			score++
		} else {
			score--
		}
		if score == 0 {
			new_a := flip_first(i+1, a)
			rec := can_transform(new_a, b, seen)
			if rec {
				return true
			}
		}
	}
	return false
}

package main

import (
	"fmt"
)

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

	for i := 0; i < n; i++ {
		var l int
		var s string
		_, err := fmt.Scanf("%d\n", &l)
		if err != nil {
			panic(err)
		}
		a := make([]bool, l)
		fmt.Scanln(&s)
		for j := 0; j < l; j++ {
			a[j] = s[j] == '1'
		}
		b := make([]bool, l)
		fmt.Scanln(&s)
		for j := 0; j < l; j++ {
			b[j] = s[j] == '1'
		}
		if t := can_transform(a, b, make(map[string]bool)); t {
			println("YES")
		} else {
			println("NO")
		}
	}
}

func equal(a, b []bool) bool {
	for i := range a {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func flip_first(n int, a []bool) []bool {
	var new []bool
	for i := 0; i < n; i++ {
		new = append(new, !a[i])
	}
	for i := n; i < len(a); i++ {
		new = append(new, a[i])
	}
	return new
}

func can_transform(a, b []bool, seen map[string]bool) bool {
	if have_seen := seen[fmt.Sprint(a)]; have_seen {
		return false
	}
	seen[fmt.Sprint(a)] = true
	if equal(a, b) {
		return true
	}
	score := 0
	for i := 0; i < len(a); i++ {
		if a[i] {
			score++
		} else {
			score--
		}
		if score == 0 {
			new_a := flip_first(i+1, a)
			rec := can_transform(new_a, b, seen)
			if rec {
				return true
			}
		}
	}
	return false
}

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		a, b := make([]byte, n), make([]byte, n)
		Fscan(in, &a, &b)

		nums := make([][2]int, n + 1)
		for i := 1; i <= n; i++ {
			if a[i - 1] == '1' {
				nums[i][0], nums[i][1] = nums[i-1][0], nums[i-1][1]+1
			} else {
				nums[i][0], nums[i][1] = nums[i-1][0] + 1, nums[i-1][1]
			}
		}

		var pos []int
		left, right := 0, 0
		for left < n && right < n {
			for left < n && a[left] == b[left] {
				left++
			}
			right = left
			if left < n && left > 1 {
				pos = append(pos, left)
			}
			for right < n && a[right] != b[right] {
				right++
			}
			if right <= n && right > left {
				pos = append(pos, right)
			}
			left = right
		}

		flag := true
		for _, val := range pos {
			if nums[val][0] != nums[val][1] {
				flag = false
				Fprintln(out, "NO")
				break
			}
		}
		if flag {
			Fprintln(out, "YES")
		}
	}
}

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

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

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

func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		a, b := make([]byte, n), make([]byte, n)
		Fscan(in, &a, &b)

		nums := make([][2]int, n + 1)
		for i := 1; i <= n; i++ {
			if a[i - 1] == '1' {
				nums[i][0], nums[i][1] = nums[i-1][0], nums[i-1][1]+1
			} else {
				nums[i][0], nums[i][1] = nums[i-1][0] + 1, nums[i-1][1]
			}
		}

		var pos []int
		left, right := 0, 0
		for left < n && right < n {
			for left < n && a[left] == b[left] {
				left++
			}
			right = left
			if left < n && left > 1 {
				pos = append(pos, left)
			}
			for right < n && a[right] != b[right] {
				right++
			}
			if right <= n {
				pos = append(pos, right)
			}
			left = right
		}

		flag := true
		for _, val := range pos {
			if nums[val][0] != nums[val][1] {
				flag = false
				Fprintln(out, "NO")
				break
			}
		}
		if flag {
			Fprintln(out, "YES")
		}
	}
}

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

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

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

func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		a, b := make([]byte, n), make([]byte, n)
		Fscan(in, &a, &b)

		nums := make([][2]int, n + 1)
		for i := 1; i <= n; i++ {
			if a[i - 1] == '1' {
				nums[i][0], nums[i][1] = nums[i-1][0], nums[i-1][1]+1
			} else {
				nums[i][0], nums[i][1] = nums[i-1][0] + 1, nums[i-1][1]
			}
		}

		var pos []int
		left, right := 0, 0
		for left < n && right < n {
			for left < n && a[left] == b[left] {
				left++
			}
			right = left
			if left < n && left > 1 {
				pos = append(pos, left)
			}
			for right < n && a[right] != b[right] {
				right++
			}
			if right < n {
				pos = append(pos, right)
			}
			left = right
		}

		flag := true
		for _, val := range pos {
			if nums[val][0] != nums[val][1] {
				flag = false
				Fprintln(out, "NO")
				break
			}
		}
		if flag {
			Fprintln(out, "YES")
		}
	}
}

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

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

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

func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

package main

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

var in = NewIn()
var out = NewOut()

func main() {
	defer out.flush()

	cases()
	// solve()
}

/* --- Solution B --- */
func solve() {
	n := in.nextInt()

	from := in.next()
	to := in.next()

	if n == 1 && from != to {
		out.println("NO")
		return
	}

	ok := true
	zeros, ones := 0, 0
	eq, diff := 0, 0
	for i := 0; i < n; i++ {
		if from[i] == '0' {
			zeros++
		} else {
			ones++
		}
		if from[i] == to[i] {
			eq++
		} else {
			diff++
		}

		if zeros == ones {
			if diff*eq != 0 {
				ok = false
				break
			}
			eq, diff = 0, 0
			zeros, ones = 0, 0
		}
	}

	if ok && diff*eq == 0 {
		out.println("YES")
	} else {
		out.println("NO")
	}
}

func cases() {
	t := in.nextInt()
	for ; t > 0; t-- {
		solve()
	}
}

/* --- I/O --- */
const BUF_MAX_CAP = 200_043

type In struct {
	scanner *bufio.Scanner
}

func NewIn() *In {
	scn := bufio.NewScanner(os.Stdin)

	buf := make([]byte, BUF_MAX_CAP)
	scn.Buffer(buf, BUF_MAX_CAP)
	scn.Split(bufio.ScanWords)

	return &In{scn}
}

func (in *In) nextInt() int {
	in.scanner.Scan()
	i, _ := strconv.Atoi(in.scanner.Text())
	return i
}

func (in *In) nextLong() int64 {
	in.scanner.Scan()
	i, _ := strconv.ParseInt(in.scanner.Text(), 10, 64)
	return i
}

func (in *In) next() string {
	in.scanner.Scan()
	return in.scanner.Text()
}

type Out struct {
	writer *bufio.Writer
}

func NewOut() *Out {
	out := Out{bufio.NewWriter(os.Stdout)}
	return &out
}

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

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

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

func (out *Out) flush() {
	out.writer.Flush()
}

package main

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

var in = NewIn()
var out = NewOut()

func main() {
	defer out.flush()

	cases()
	// solve()
}

/* --- Solution B --- */
func solve() {
	n := in.nextInt()

	from := in.next()
	to := in.next()

	ok := true
	zeros, ones := 0, 0
	eq, diff := 0, 0
	for i := 0; i < n; i++ {
		if from[i] == '0' {
			zeros++
		} else {
			ones++
		}
		if from[i] == to[i] {
			eq++
		} else {
			diff++
		}

		if zeros == ones {
			if diff*eq != 0 {
				ok = false
				break
			}
			eq, diff = 0, 0
			zeros, ones = 0, 0
		}
	}

	if ok && diff*eq == 0 {
		out.println("YES")
	} else {
		out.println("NO")
	}
}

func cases() {
	t := in.nextInt()
	for ; t > 0; t-- {
		solve()
	}
}

/* --- I/O --- */
const BUF_MAX_CAP = 200_043

type In struct {
	scanner *bufio.Scanner
}

func NewIn() *In {
	scn := bufio.NewScanner(os.Stdin)

	buf := make([]byte, BUF_MAX_CAP)
	scn.Buffer(buf, BUF_MAX_CAP)
	scn.Split(bufio.ScanWords)

	return &In{scn}
}

func (in *In) nextInt() int {
	in.scanner.Scan()
	i, _ := strconv.Atoi(in.scanner.Text())
	return i
}

func (in *In) nextLong() int64 {
	in.scanner.Scan()
	i, _ := strconv.ParseInt(in.scanner.Text(), 10, 64)
	return i
}

func (in *In) next() string {
	in.scanner.Scan()
	return in.scanner.Text()
}

type Out struct {
	writer *bufio.Writer
}

func NewOut() *Out {
	out := Out{bufio.NewWriter(os.Stdout)}
	return &out
}

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

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

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

func (out *Out) flush() {
	out.writer.Flush()
}

package main

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

/*
1
10
0111010000
0100101100
---
YES
=========
*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	bld := strings.Builder{}

	var t int
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		var a, b string
		scanf("%s\n%s\n", &a, &b)

		if n%2 != 0 && a[n-1] != b[n-1] {
			fmt.Fprintf(&bld, "NO\n")
			continue
		}

		possible := true

		flipCnt := 0
		oneCnt := strings.Count(a, "1")

		for i := n - 1; i > 0; i-- {
			ai := a[i]
			if flipCnt%2 != 0 {
				if ai == '0' {
					ai = '1'
				} else {
					ai = '0'
				}
			}

			ok := ai == b[i]
			if ok {
				if ai == '1' {
					oneCnt--
				}
				continue
			}

			zeroCnt := i - oneCnt + 1
			flippable := oneCnt == zeroCnt

			if flippable {
				if b[i] == '1' {
					oneCnt--
				}
				flipCnt++
			} else {
				possible = false
				break
			}
		}

		if possible {
			fmt.Fprintf(&bld, "YES\n")
		} else {
			fmt.Fprintf(&bld, "NO\n")
		}
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

//goland:noinspection GoUnusedType
type pair struct {
	fst rune
	snd int
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//goland:noinspection GoUnusedFunction
func isPrime(n int) bool {
	if n == 2 || n == 3 {
		return true
	}

	if n <= 1 || n%2 == 0 || n%3 == 0 {
		return false
	}

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(i+2) == 0 {
			return false
		}
	}

	return true
}

package main

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

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

	var T, n int
	var s, t []byte
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &s, &t)
		c := [2]int{}
		for i, b := range s {
			if b != t[i] {
				c[b&1]++
			} else if c[0] != c[1] {
				break
			}
		}
		if c[0] != c[1] {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
		}
	}
}

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

package main

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

func check(str1, str2 string, l, r int) bool {
	cnt := 0
	for i := l; i <= r; i++ {
		if str1[i] == str2[i] {
			cnt++
		}
	}
	if cnt == 0 || cnt == r-l+1 {
		return true
	}
	return false
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscanf(in, "%d\n", &t)
	for case_idx := 0; case_idx < t; case_idx++ {
		var len int
		var s1, s2 string
		fmt.Fscanf(in, "%d\n%s\n%s\n", &len, &s1, &s2)
		one_cnt := 0
		zero_cnt := 0
		l := 0
		r := 0
		var success bool
		for i := 0; i < len; i++ {
			if s1[i] == '0' {
				zero_cnt++
			} else {
				one_cnt++
			}
			if one_cnt == zero_cnt {
				r = i
				success = check(s1, s2, l, r)
				if !success {
					break
				}
				l = r + 1
			}
		}
		if s1 == s2 {
			fmt.Fprintln(out, "YES")
		} else if success {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
	out.Flush()
}


Ashish has a string $$$s$$$ of length $$$n$$$ containing only characters 'a', 'b' and 'c'.He wants to find the length of the smallest substring, which satisfies the following conditions:   Length of the substring is at least $$$2$$$  'a' occurs strictly more times in this substring than 'b'  'a' occurs strictly more times in this substring than 'c'  Ashish is busy planning his next Codeforces round. Help him solve the problem.A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

The first line contains a single integer $$$t$$$ $$$(1 \le t \le 10^{5})$$$  — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ $$$(2 \le n \le 10^{6})$$$  — the length of the string $$$s$$$. The second line of each test case contains a string $$$s$$$ consisting only of characters 'a', 'b' and 'c'. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^{6}$$$.

For each test case, output the length of the smallest substring which satisfies the given conditions or print $$$-1$$$ if there is no such substring.

NoteConsider the first test case. In the substring "aa", 'a' occurs twice, while 'b' and 'c' occur zero times. Since 'a' occurs strictly more times than 'b' and 'c', the substring "aa" satisfies the condition and the answer is $$$2$$$. The substring "a" also satisfies this condition, however its length is not at least $$$2$$$.In the second test case, it can be shown that in none of the substrings of "cbabb" does 'a' occur strictly more times than 'b' and 'c' each.In the third test case, "cacabccc", the length of the smallest substring that satisfies the conditions is $$$3$$$.

package main

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

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

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

	str := []string{"aa", "aba", "aca", "abca", "acba", "abbacca", "accabba"}

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var s string
		fmt.Fscan(in, &n, &s)

		ans := -1
	Loop:
		for _, s2 := range str {
			for i := 0; i < n-len(s2)+1; i++ {
				if s[i:i+len(s2)] == s2 {
					ans = len(s2)
					break Loop
				}
			}
		}
		fmt.Fprintln(out, ans)
	}
}

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 printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
// 	redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n int
	scan(&n)
	var s string
	scan(&s)
	var ans = 1 << 30
	for l := 2; l <= 10; l++ {
		for i := 0; i+l-1 < len(s); i++ {
			cnt := [3]int{}
			ss := s[i : i+l]
			for j := range ss {
				cnt[ss[j]-'a']++
			}
			if cnt[0] > cnt[1] && cnt[0] > cnt[2] && ans > l {
				ans = l
			}
		}
	}
	if ans == 1<<30 {
		ans = -1
	}
	printf("%v\n", ans)
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var tc int
	fmt.Fscan(in, &tc)
	for ; tc > 0; tc-- {
		var n int
		var s string
		fmt.Fscan(in, &n, &s)
		mn := 12
		for i := 0; i < n-1; i++ {
			cnt := [3]int{}
			cnt[s[i]-'a']++
			for j := 1; j < mn && i+j < n; j++ {
				cnt[s[i+j]-'a']++
				if cnt[0] > cnt[1] && cnt[0] > cnt[2] {
					mn = j
				}
			}
		}
		if mn == 12 {
			out.WriteString("-1\n")
		} else {
			fmt.Fprintln(out, mn+1)
		}
	}
}

package main

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

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

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

	str := []string{"aa", "aba", "aca", "abca", "acba", "abbacca", "accabba"}

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var s string
		fmt.Fscan(in, &n, &s)

		ans := -1
		for _, s2 := range str {
			for i := 0; i < n-len(s2)+1; i++ {
				if s[i:i+len(s2)] == s2 {
					ans = len(s2)
					break
				}
			}
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var s string
		fmt.Fscan(in, &n, &s)

		ans := math.MaxInt32
		for i, ch := range s {
			if ch == 'a' {
				if i < n-1 && s[i+1] == 'a' {
					ans = 2
					break
				} else if i < n-2 && s[i+2] == 'a' {
					ans = min(ans, 3)
				} else if i < n-3 && (s[i:i+4] == "abca" || s[i:i+4] == "acba") {
					ans = min(ans, 4)
				}
			}
		}

		if ans == math.MaxInt32 {
			fmt.Fprintln(out, -1)
		} else {
			fmt.Fprintln(out, ans)
		}
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var s string
		fmt.Fscan(in, &n, &s)

		l, r := -1, -1
		var b, c int
		min := math.MaxInt32
		for i, ch := range s {
			if ch == 'a' {
				if l < 0 {
					l = i
				} else if r < 0 {
					r = i
				} else {
					l, r = r, i
				}

				if r > 0 && r-l+1 < min && r-l+1 > b && r-l+1 > c {
					min = r - l + 1
				}
				b, c = 0, 0
			} else if ch == 'b' {
				b++
			} else {
				c++
			}
		}

		if min == math.MaxInt32 {
			fmt.Fprintln(out, -1)
		} else {
			fmt.Fprintln(out, min)
		}
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var s string
		fmt.Fscan(in, &n, &s)

		a, b := -1, -1
		min := math.MaxInt32
		for i, ch := range s {
			if ch == 'a' {
				if a < 0 {
					a = i
				} else if b < 0 {
					b = i
				} else {
					a, b = b, i
				}

				if b > 0 && b-a+1 < min {
					min = b - a + 1
				}
			}
		}

		if min == math.MaxInt32 {
			fmt.Fprintln(out, -1)
		} else {
			fmt.Fprintln(out, min)
		}
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var s string
		fmt.Fscan(in, &n, &s)

		a, b := -1, -1
		min := -1
		for i, ch := range s {
			if ch == 'a' {
				if a < 0 {
					a = i
				} else if b < 0 {
					b = i
				} else {
					a, b = b, i
				}

				if b > 0 && b-a+1 < min {
					min = b - a + 1
				}
			}
		}

		fmt.Fprintln(out, min)
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var s string
		fmt.Fscan(in, &n, &s)

		a, b := -1, -1
		min := -1
		for i, ch := range s {
			if ch == 'a' {
				if a < 0 {
					a = i
				} else if b < 0 {
					b = i
				} else {
					a, b = b, i
				}

				if b > 0 && b-a+1 > min {
					min = b - a + 1
				}
			}
		}

		fmt.Fprintln(out, min)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for u:=1;u<=t;u++{
		var n int
		fmt.Fscan(in,&n)
		var b []byte
		fmt.Fscan(in,&b)
		ans:=-1
		for i:=0;i<=len(b)-1;i++{
			if b[i]=='a'{
				if i-1>=0{
					if b[i-1]=='a'{
						ans=2
					}
				}
				if i+1<=len(b)-1{
					if b[i+1]=='a'{
						ans=2
					}
				}
			}
		}
		if ans==2{
			fmt.Fprintln(out,ans)
			continue
		}
		for i:=0;i<=len(b)-1;i++{
			if b[i]=='a'{
				if i-2>=0{
					if b[i-2]=='a'{
						ans=3
					}
				}
				if i+2<=len(b)-1{
					if b[i+2]=='a'{
						ans=3
					}
				}
			}
		}
		if ans==3{
			fmt.Fprintln(out,ans)
			continue
		}
		for i:=0;i<len(b);i++{
			if i+3<=len(b)-1&&b[i]=='a'&&b[i+3]=='a'{
				if b[i+1]=='b'&&b[i+2]=='c'{
					ans=4
				}
				if b[i+1]=='c'&&b[i+2]=='b'{
					ans=4
				}
			}
		}
		fmt.Fprintln(out,ans)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for u:=1;u<=t;u++{
		var n int
		fmt.Fscan(in,&n)
		var b []byte
		fmt.Fscan(in,&b)
		ans:=-1
		for i:=0;i<=len(b)-1;i++{
			if b[i]=='a'{
				if i-1>=0{
					if b[i-1]=='a'{
						ans=2
					}
				}
				if i+1<=len(b)-1{
					if b[i+1]=='a'{
						ans=2
					}
				}
			}
		}
		if ans==2{
			fmt.Fprintln(out,ans)
			continue
		}
		for i:=0;i<=len(b)-1;i++{
			if b[i]=='a'{
				if i-2>=0{
					if b[i-2]=='a'{
						ans=3
					}
				}
				if i+2<=len(b)-1{
					if b[i+2]=='a'{
						ans=3
					}
				}
			}
		}
		if ans==3{
			fmt.Fprintln(out,ans)
			continue
		}
		fmt.Fprintln(out,ans)
	}
}


Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times:  Arrange all the rangers in a straight line in the order of increasing strengths. Take the bitwise XOR (is written as ) of the strength of each alternate ranger with x and update it's strength. Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following:  The strength of first ranger is updated to , i.e. 7. The strength of second ranger remains the same, i.e. 7. The strength of third ranger is updated to , i.e. 11. The strength of fourth ranger remains the same, i.e. 11. The strength of fifth ranger is updated to , i.e. 13. The new strengths of the 5 rangers are [7, 7, 11, 11, 13]Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him?

First line consists of three integers n, k, x (1 ≤ n ≤ 105, 0 ≤ k ≤ 105, 0 ≤ x ≤ 103) — number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively. Second line consists of n integers representing the strengths of the rangers a1, a2, ..., an (0 ≤ ai ≤ 103).

Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times.

package main

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

func solve(n, k, xval int, a []int) (l int, r int) {
	m := 1024
	b := make([]int, m)
	c := make([]int, m)
	for _, x := range a {
		b[x] += 1
	}
	for step := 0; step < k; step++ {
		for i := 0; i < m; i++ {
			c[i] = 0
		}
		s := 1
		for i := 0; i < m; i++ {
			c[i ^ xval] += (b[i] + s) / 2
			c[i] += (b[i] + 1 - s) / 2
			s = (s + b[i]) % 2
		}
		b, c = c, b
	}
	l, r = -1, -1
	for i, x := range b {
		if x > 0 {
			if l == -1 {
				l = i
			}
			r = i
		}
	}
	return
}

func main() {
	cin := NewParser(bufio.NewReaderSize(os.Stdin, 1<<16))
	n := cin.nextInt()
	k := cin.nextInt()
	x := cin.nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = cin.nextInt()
	}
	l, r := solve(n, k, x, a)
	fmt.Printf("%d %d\n", r, l)
}

// some io

type ParserReader struct {
	r   io.ByteReader
	err error
	c   byte
}

func NewParser(r io.ByteReader) *ParserReader {
	return &ParserReader{r, nil, 0}
}

func (p *ParserReader) next() error {
	p.c, p.err = p.r.ReadByte()
	return p.err
}

func isDigit(c byte) bool {
	return '0' <= c && c <= '9'
}

func (p *ParserReader) nextUInt64() uint64 {
	for !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var r uint64
	for isDigit(p.c) && p.err == nil {
		r = r*10 + uint64(p.c - '0')
		p.next()
	}
	return r
}

func (p *ParserReader) nextUInt() uint {
	for !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var r uint
	for isDigit(p.c) && p.err == nil {
		r = r*10 + uint(p.c - '0')
		p.next()
	}
	return r
}

func (p *ParserReader) nextInt64() int64 {
	for p.c != '-' && !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var sign bool
	if p.c == '-' {
		sign = true
	}
	r := int64(p.nextUInt64())
	if sign {
		return -r
	}
	return r
}

func (p *ParserReader) nextInt() int {
	for p.c != '-' && !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var sign bool
	if p.c == '-' {
		sign = true
	}
	r := int(p.nextUInt())
	if sign {
		return -r
	}
	return r
}

package main

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

func solve(n, k, xval int, a []int) (l int, r int) {
	m := 1024
	b := make([]int, m)
	c := make([]int, m)
	for _, x := range a {
		b[x] += 1
	}
	for step := 0; step < k; step++ {
		for i := 0; i < m; i++ {
			c[i] = 0
		}
		s := 1
		for i := 0; i < m; i++ {
			c[i ^ xval] += (b[i] + s) / 2
			c[i] += (b[i] + 1 - s) / 2
			s = (s + b[i]) % 2
		}
		b, c = c, b
	}
	l, r = -1, -1
	for i, x := range b {
		if x > 0 {
			if l == -1 {
				l = i
			}
			r = i
		}
	}
	return
}

func main() {
	f, _ := os.Open("c.in")
	cin := NewParser(bufio.NewReaderSize(f, 1<<16))
	// cin := NewParser(bufio.NewReaderSize(os.Stdin, 1<<16))
	n := cin.nextInt()
	k := cin.nextInt()
	x := cin.nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = cin.nextInt()
	}
	l, r := solve(n, k, x, a)
	fmt.Printf("%d %d\n", r, l)
}

// some io

type ParserReader struct {
	r   io.ByteReader
	err error
	c   byte
}

func NewParser(r io.ByteReader) *ParserReader {
	return &ParserReader{r, nil, 0}
}

func (p *ParserReader) next() error {
	p.c, p.err = p.r.ReadByte()
	return p.err
}

func isDigit(c byte) bool {
	return '0' <= c && c <= '9'
}

func (p *ParserReader) nextUInt64() uint64 {
	for !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var r uint64
	for isDigit(p.c) && p.err == nil {
		r = r*10 + uint64(p.c - '0')
		p.next()
	}
	return r
}

func (p *ParserReader) nextUInt() uint {
	for !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var r uint
	for isDigit(p.c) && p.err == nil {
		r = r*10 + uint(p.c - '0')
		p.next()
	}
	return r
}

func (p *ParserReader) nextInt64() int64 {
	for p.c != '-' && !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var sign bool
	if p.c == '-' {
		sign = true
	}
	r := int64(p.nextUInt64())
	if sign {
		return -r
	}
	return r
}

func (p *ParserReader) nextInt() int {
	for p.c != '-' && !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var sign bool
	if p.c == '-' {
		sign = true
	}
	r := int(p.nextUInt())
	if sign {
		return -r
	}
	return r
}