package main

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var ntests int
	fmt.Fscan(scanner, &ntests)
	for iter := 0; iter < ntests; iter++ {
		var n int
		fmt.Fscan(scanner, &n)
		var s string
		fmt.Fscan(scanner, &s)
		b := []byte(s)
		m := n / 2
		el := b[m]
		res := 0
		if n%2 == 1 {
			res++
		}
		for i := m - 1; i >= 0; i-- {
			if b[i] == el {
				res += 2
			} else {
				break
			}
		}
		fmt.Fprintln(writer, res)
	}
}

package main

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

const maxn = 2e5 + 7

func slove(n int ,s string) int{
	ans:=0
	var (
		m1 int
		m2 int
	)
	m1 = n/2
	if n%2==0{
		m2 = m1
	}else{
		m2 = m1 + 1
	}

	for ;m1>=0&&s[m1]==s[n/2];m1-- {

	}
	for ;m2<n&&s[m2]==s[n/2];m2++ {

	}
//	fmt.Println(m1)
	//fmt.Println(m2)
	ans = m2 - m1  -1 ;

	return ans
}

func main() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var _q int

	Fscan(in,&_q)
	for ; _q>0 ;_q--{
		var n int
		Fscan(in,&n)
		var s string
		Fscan(in,&s)
		Fprintln(out,slove(n,s))

	}

}

package main

import "fmt"

const maxn = 2e5 + 7

func slove(n int ,s string) int{
	ans:=0
	var (
		m1 int
		m2 int
	)
	m1 = n/2
	if n%2==0{
		m2 = m1
	}else{
		m2 = m1 + 1
	}

	for ;m1>=0&&s[m1]==s[n/2];m1-- {

	}
	for ;m2<n&&s[m2]==s[n/2];m2++ {

	}
//	fmt.Println(m1)
	//fmt.Println(m2)
	ans = m2 - m1  -1 ;

	return ans
}

func main() {

	var _q int
	fmt.Scan(&_q)
	for ; _q>0 ;_q--{

		var n int
		fmt.Scan(&n)

		var s string
		fmt.Scan(&s)

		fmt.Println(slove(n,s))

	}

}

package main

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

type CF1682A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1682A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1682A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1682A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1682A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1682A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1682A
Date: 29/05/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1682/A
Problem: CF1682A
**/
func (in *CF1682A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		str := in.NextString()
		mid := int(math.Floor(float64(n) / 2.))

		left := mid
		for i := mid; i >= 0; i-- {
			if str[mid] == str[i] {
				left = i
			} else {
				break
			}
		}

		right := mid
		for i := mid; i < n; i++ {
			if str[mid] == str[i] {
				right = i
			} else {
				break
			}
		}
		fmt.Println((right - left) + 1)

	}
}

func NewCF1682A(r *bufio.Reader) *CF1682A {
	return &CF1682A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1682A(bufio.NewReader(os.Stdin)).Run()
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		var s string
		fmt.Fscan(in,&n,&s)
		if n & 1 != 1 {
			n--
		}
		var count int = 1
		for j:=1;j<=n/2;j++{
			if string(s[j]) == string(s[j-1]) {
				count++
			} else {
				count = 1
			}
		}
		if len(s) & 1 == 1 {
			fmt.Fprintln(out,count*2-1)
		} else {
			fmt.Fprintln(out,count*2)
		}
	}
}

// string guarenteed to be palindrome, look for change
// start a count and reset with every new letter, stop halfway
// if len even * 2
// if len odd, if count 1, return 1, else return count * 2 - 1
// -->    <--
// a[j]		a[n-1-j]

// https://codeforces.com/problemset/problem/1682/A

// 1682A - Palindromic Indices

// You are given a palindromic string s of length n.
// You have to count the number of indices i (1≤i≤n) such that the string after removing si from s still remains a palindrome.
// For example, consider s = "aba"
//  1. If we remove s1 from s, the string becomes "ba" which is not a palindrome.
//  2. If we remove s2 from s, the string becomes "aa" which is a palindrome.
//  3. If we remove s3 from s, the string becomes "ab" which is not a palindrome.
// A palindrome is a string that reads the same backward as forward. For example, "abba", "a", "fef" are palindromes whereas "codeforces", "acd", "xy" are not.

// Input
// The input consists of multiple test cases. The first line of the input contains a single integer t (1≤t≤10^3)  — the number of test cases. Description of the test cases follows.
// The first line of each testcase contains a single integer n (2≤n≤10^5)  — the length of string s.
// The second line of each test case contains a string s consisting of lowercase English letters. It is guaranteed that s is a palindrome.
// It is guaranteed that sum of n over all test cases does not exceed 2⋅10^5.

// Output
// For each test case, output a single integer  — the number of indices i (1≤i≤n) such that the string after removing si from s still remains a palindrome.

// Example
// input
// 3
// 3
// aba
// 8
// acaaaaca
// 2
// dd
// output
// 1
// 4
// 2

// Note

// The first test case is described in the statement.
// In the second test case, the indices i that result in palindrome after removing si are 3,4,5,6. Hence the answer is 4.
// In the third test case, removal of any of the indices results in "d" which is a palindrome. Hence the answer is 2.

// Hint

// Read the statement carefully!! The given string is a palindrome.

// Tutorial

// Let's remove some index i from the first half of s and check whether the resulting string is a palindrome or not, the other half has the same approach. The prefix of length i−1 already matches with the suffix of the same length because the initial string was a palindrome, so we just need to check if t=s[i+1…n−i+1] is a palindrome.
// For t to be a palindrome, sn−i+1 should be equal to si+1 which was initially equal to sn−i, again which should be equal to si+2 and this goes on. Here we can see that si=si+1…=sn−i+1. So the answer is simply equal to the number of contiguous same characters in the center of the string which can be calculated in O(n).

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c, n, i int
	var t, cnt uint
	var s string

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			fmt.Fscan(reader, &n, &s)

			cnt = 0

			for i = (n - 1) >> 1; i >= 0; i-- {
				if s[i] == s[(n-1)>>1] {
					cnt++
				} else {
					break
				}
			}

			cnt <<= 1

			if n&1 == 1 {
				cnt--
			}

			fmt.Fprintln(writer, cnt)
		}
	}

	writer.Flush()
}

package main

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

func main() {
	var T int
	var N int
	var s string
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &T)
	for T > 0 {
		fmt.Fscan(in, &N)
		fmt.Fscan(in, &s)
		mid := N / 2
		midChar := s[mid]
		cnt := 0
		for i := mid; i >= 0; i-- {
			if s[i] == midChar {
				cnt++
			} else {
				break
			}
		}
		for i := mid; i < N; i++ {
			if s[i] == midChar {
				cnt++
			} else {
				break
			}
		}

		fmt.Println(cnt - 1)
		T--
	}
}

package main

import (
	"fmt"
)

// var in = bufio.NewReader(os.Stdin)

// func readInt() int {
// 	res := 0
// 	for c, _ := in.ReadByte(); c >= '0' && c <= '9'; c, _ = in.ReadByte() {
// 		res = res*10 + int(c-'0')
// 	}
// 	return res
// }

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n int
		fmt.Scan(&n)
		var s string
		fmt.Scan(&s)
		ans := 0
		for i := (n - 1) / 2; i >= 0; i-- {
			if s[i] != s[n/2] {
				break
			}
			if i != n-1-i {
				ans += 2
			} else {
				ans++
			}
		}
		fmt.Println(ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N := gi(); S := gs()
		c := S[N/2]; cnt := 0
		for i:=N/2;i<N;i++ { if S[i] != c { break }; cnt++ }
		for i:=N/2-1;i>=0;i-- { if S[i] != c { break}; cnt++ }
		fmt.Fprintln(wrtr,cnt)
	}
}

package main

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

func A() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		/*
			T_C
			var n int
			Fscan(in, &n)
			a := make([]int, n)
			Map := make(map[int]int, 0)
			for i := 0; i < n; i++ {
				Fscan(in, &a[i])
				Map[a[i]]++
			}
			var cnt, cnt2 int
			for _, v := range Map {
				if v == 1 {
					cnt++
				} else {
					cnt2++
				}
			}
			Fprintln(out, cnt2+(cnt+1)/2) */
		/* T_A */
		var s string
		var n int
		Fscan(in, &n)
		Fscan(in, &s)
		var j, k int
		for j = n / 2; j >= 0 && s[j] == s[n/2]; j-- {

		}
		for k = n / 2; k < n && s[k] == s[n/2]; k++ {

		}
		Fprintln(out, k-j-1)
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A() }

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"math"
	"os"
)

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var s string
		var n int
		Fscan(in, &n, &s)
		lg := len(s)

		var l, r, mid int
		if lg%2 == 0 {
			l = lg/2 - 1
			mid = l
			r = l + 1

		} else {
			l = (lg+1)/2 - 1
			mid = l
			r = l
		}

		ans := 0
		for l >= 0 && r < lg {
			if s[l] != s[mid] {
				break
			}
			if s[l] == s[r] && s[l] == s[mid] {
				ans++
			}
			if s[l] == s[r] && s[l] == s[mid] && l != r {
				ans++
			}
			l--
			r++
		}
		Fprintln(out, ans)

	}

}

func MakeGrid(h, w int) [][]Int {
	index := make([][]Int, h)
	data := make([]Int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    Int // The value of the item; arbitrary.
	priority Int // The priority of the item in the queue.
	indices  Int
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func NewItem(value, priority Int) *Item {
	return &Item{
		value:    value,
		priority: priority,
		index:    -1,
	}

}

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority < pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value Int, priority Int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

type SegTree struct {
	st []Segment
}

type Segment struct {
	l, r, val, add, minIndex Int
}

func newSegTree(n Int) SegTree {
	segTree := SegTree{make([]Segment, n<<2)}
	segTree.Build(1, 1, n)
	return segTree
}

func (segTree SegTree) Build(x, l, r Int) {
	segTree.st[x].l = l
	segTree.st[x].r = r
	if l == r {
		segTree.st[x].minIndex = l
		return
	}
	mid := (l + r) >> 1
	segTree.Build(x<<1, l, mid)
	segTree.Build(x<<1|1, mid+1, r)
}

func (segTree SegTree) push(x Int) {
	if segTree.st[x].add != 0 {
		segTree.modifyOne(x<<1, segTree.st[x].add)
		segTree.modifyOne(x<<1|1, segTree.st[x].add)
		segTree.st[x].add = 0
	}
}

func (segTree SegTree) update(x Int) {
	if segTree.st[x<<1].val < segTree.st[x<<1|1].val {
		segTree.st[x].val = segTree.st[x<<1].val
		segTree.st[x].minIndex = segTree.st[x<<1].minIndex
	} else {
		segTree.st[x].val = segTree.st[x<<1|1].val
		segTree.st[x].minIndex = segTree.st[x<<1|1].minIndex
	}
}

func (segTree SegTree) modifyOne(x, add Int) {
	segTree.st[x].val += add
	if segTree.st[x].l != segTree.st[x].r {
		segTree.st[x].add += add
	}
}

func (segTree SegTree) Modify(x, l, r, add Int) {
	if segTree.st[x].l >= l && segTree.st[x].r <= r {
		segTree.modifyOne(x, add)
		return
	}
	segTree.push(x)
	mid := (segTree.st[x].l + segTree.st[x].r) >> 1
	if mid >= l {
		segTree.Modify(x<<1, l, r, add)
	}
	if mid < r {
		segTree.Modify(x<<1|1, l, r, add)
	}
	segTree.update(x)
}

func updateRes(cRes, cIndex, res, index Int) (Int, Int) {
	if cRes > res {
		return res, index
	}
	return cRes, cIndex
}

func (segTree SegTree) Query(x, l, r Int) (Int, Int) {
	res := Int(math.MaxInt64)
	resInd := -L1
	if segTree.st[x].l >= l && segTree.st[x].r <= r {
		res, resInd = updateRes(res, resInd, segTree.st[x].val, segTree.st[x].minIndex)
		return res, resInd
	}
	mid := (segTree.st[x].l + segTree.st[x].r) >> 1
	if mid >= l {
		sonRes, sonInd := segTree.Query(x<<1, l, r)
		res, resInd = updateRes(res, resInd, sonRes, sonInd)
	}
	if mid < r {
		sonRes, sonInd := segTree.Query(x<<1|1, l, r)
		res, resInd = updateRes(res, resInd, sonRes, sonInd)
	}
	return res, resInd
}

type Graph struct {
	nodeSize Int
	edges    []Edge
	head     []Int
	dis      []Int
	vis      []bool
	nCnt     Int
	ans      []Int
}

type Edge struct {
	u, v, c, indices, next Int
}

func NewGraph(nodeSize Int) *Graph {
	return &Graph{
		nodeSize: nodeSize,
		edges:    make([]Edge, (2e5+10)<<2),
		head:     make([]Int, nodeSize+100),
		dis:      make([]Int, nodeSize+100),
		vis:      make([]bool, nodeSize+100),
		nCnt:     L1,
		ans:      make([]Int, nodeSize),
	}
}

func (g *Graph) addEdge(u Int, v Int, cost Int, indices Int) {
	g.nCnt++
	g.edges[g.nCnt] = Edge{u, v, cost, indices, g.head[u]}
	g.head[u] = g.nCnt
}

func (g *Graph) Dijkstra(begin Int) {
	for i := L1; i <= g.nodeSize; i++ {
		g.dis[i] = math.MaxInt64
	}
	pq := make(PriorityQueue, 0)
	heap.Init(&pq)

	g.dis[begin] = 0
	heap.Push(&pq, &Item{begin, 0, -1, -1})

	id := L0

	for len(pq) > 0 {
		it := heap.Pop(&pq).(*Item)
		u := it.value
		if g.vis[u] {
			continue
		}
		g.vis[u] = true

		if it.indices != -1 && id < g.nodeSize-1 {
			g.ans[id] = it.indices
			id++
		}

		for i := g.head[u]; i != 0; i = g.edges[i].next {
			v := g.edges[i].v
			if g.dis[v] > g.dis[u]+g.edges[i].c {
				g.dis[v] = g.dis[u] + g.edges[i].c

				heap.Push(&pq, &Item{v, g.dis[v], g.edges[i].indices, -1})
			}
		}
	}
}

package main

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

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

func a1682(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int
	var n int
	var s string

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		Fscan(in, &s)
		mi := n/2
		ans := 0
		for i := mi; i < n; i++ {
			if s[mi] == s[i] {
				ans++
			} else {
				break
			}
		}
		for i := mi-1; i>= 0; i-- {
			if s[mi] == s[i] {
				ans++
			} else {
				break
			}
		}

		Fprintln(out, ans)
	}
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	_, _ = fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	_, _ = fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	_, _ = fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	_, _ = fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	_, _ = fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	_, _ = fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	_, _ = fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	for t := io.ReadInt(); t > 0; t-- {
		_ = io.ReadInt()
		s := io.ReadString()
		mid := len(s) / 2
		var ans int
		for i := mid; i < len(s); i++ {
			if s[i] == s[mid] {
				ans++
			} else {
				break
			}
		}
		for i := mid - 1; i >= 0; i-- {
			if s[i] == s[mid] {
				ans++
			} else {
				break
			}
		}
		fmt.Println(ans)
	}
}

package main

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

const maxn = 2e5 + 7

func slove(n int ,s string) int{
	ans:=0
	var (
		m1 int
		m2 int
	)
	m1 = n/2
	if n%2==0{
		m2 = m1
	}else{
		m2 = m1 + 1
	}

	for ;m1>=0&&s[m1]==s[n/2];m1-- {

	}
	for ;m2<n&&s[m2]==s[n/2];m2++ {

	}
//	fmt.Println(m1)
	//fmt.Println(m2)
	ans = m2 - m1  -1 ;

	return ans
}

func main() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	var _q int

	Fscan(in,&_q)
	for ; _q>0 ;_q--{
		var n int
		Fscan(in,&n)
		var s string
		Fscan(in,&s)
		Fprintln(out,slove(n,s))

	}

}

package main

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var ntests int
	fmt.Fscan(scanner, &ntests)
	for iter := 0; iter < ntests; iter++ {
		var n int
		fmt.Fscan(scanner, &n)
		var s string
		fmt.Fscan(scanner, &s)
		b := []byte(s)
		m := n / 2
		el := b[m]
		res := 0
		for i := 0; i <= m; i++ {
			if b[i] == el {
				res++
			}
		}
		fmt.Fprintln(writer, res)
	}
}

package main

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

type CF1682A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1682A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1682A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1682A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1682A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1682A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1682A
Date: 29/05/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1682/A
Problem: CF1682A
**/
func (in *CF1682A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		str := in.NextString()
		mid := int(math.Floor(float64(n)/2.)) - 1

		left := mid
		for i := mid; i >= 0; i-- {
			if str[mid] == str[i] {
				left = i
			} else {
				break
			}
		}

		right := mid
		for i := mid; i < n; i++ {
			if str[mid] == str[i] {
				right = i
			} else {
				break
			}
		}

		fmt.Println((right - left) + 1)

	}
}

func NewCF1682A(r *bufio.Reader) *CF1682A {
	return &CF1682A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1682A(bufio.NewReader(os.Stdin)).Run()
}


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 print(a ...interface{})            { fmt.Fprint(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()
	////////////////////
	var n, q int
	var count int = 0
	scan(&n, &q)
	a := make([]int, n)
	var k, m int
	for i := 0; i < n; i++ {
		t := 0
		scan(&t)
		a[i] = t
		if a[i] == 1 {
			count++
		}
	}
	for i := 0; i < q; i++ {
		scan(&k, &m)
		if k == 1 {
			if a[m-1] == 0 {
				count++
			} else {
				count--
			}
			a[m-1] = 1 - a[m-1]
		} else {
			if m <= count {
				printf("1\n")
			} else {
				printf("0\n")
			}
		}
	}
}

package main

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

var (
	reader         = bufio.NewReader(os.Stdin)
	n, q, t, param int
	count          [2]int
)

func main() {
	fmt.Fscan(reader, &n, &q)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i])
		count[a[i]]++
	}
	for ; q > 0; q-- {
		fmt.Fscan(reader, &t, &param)
		if t == 1 {
			w := a[param-1]
			count[w]--
			count[1-w]++
			a[param-1] = 1 - w
		} else {
			if count[1] < param {
				fmt.Println(0)
			} else {
				fmt.Println(1)
			}
		}
	}
}

package main

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

var (
	reader         = bufio.NewReader(os.Stdin)
	n, q, t, param int
	count          [2]int
)

func solve(n, k int, a []int) int {
	sort.Ints(a)
	var count int
	for i := 1; i < n; i++ {
		count += (k - a[i]) / a[0]
	}
	return count
}

func main() {
	fmt.Fscan(reader, &n, &q)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i])
		count[a[i]]++
	}
	for ; q > 0; q-- {
		fmt.Fscan(reader, &t, &param)
		if t == 1 {
			count[a[param-1]]--
			count[1-a[param-1]]++
			a[param-1] = 1 - a[param-1]
		} else {
			if count[1] < param {
				fmt.Println(0)
			} else {
				fmt.Println(1)
			}
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1491A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var n, q, s, op, x int
	Fscan(in, &n, &q)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
		s += a[i]
	}
	for ; q > 0; q-- {
		Fscan(in, &op, &x)
		x--
		if op == 1 {
			a[x] ^= 1
			s += 2*a[x] - 1
		} else if x < s {
			Fprintln(out, 1)
		} else {
			Fprintln(out, 0)
		}
	}
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n, q, n0, n1, num, q1, q2 int
	var queue []int
	Fscan(in, &n)
	Fscan(in, &q)
	for i := 0; i < n; i++ {
		Fscan(in, &num)
		queue = append(queue, num)
		if num == 0 {
			n0++
		} else {
			n1++
		}
	}
	for i := 0; i < q; i++ {
		Fscan(in, &q1)
		Fscan(in, &q2)
		if q1 == 1 {
			if queue[q2-1] == 0 {
				n1++
				n0--
				queue[q2-1] = 1
			} else {
				n0++
				n1--
				queue[q2-1] = 0
			}
		}
		if q1 == 2 {
			if q2 > n1 {
				Fprintln(out, 0)
			} else {
				Fprintln(out, 1)
			}
		}
	}

}

package main

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

type CF1491A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1491A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1491A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1491A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1491A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1491A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1491A
Date: 18/03/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1491/A
Problem: CF1491A
**/
func (in *CF1491A) Run() {
	n, q := in.NextInt(), in.NextInt()

	ones := 0
	zeros := 0
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = in.NextInt()
		if arr[i] == 1 {
			ones++
		} else {
			zeros++
		}
	}
	var ans strings.Builder
	for i := 0; i < q; i++ {
		t := in.NextInt()
		x := in.NextInt()
		if t == 1 {
			value := 1 - arr[x-1]
			if value == 0 {
				zeros++
			} else {
				ones++
			}
			if arr[x-1] == 0 {
				zeros--
			} else {
				ones--
			}
			arr[x-1] = value
		} else {
			if x > ones {
				ans.WriteString("0\n")
			}else {
				ans.WriteString("1\n")
			}
		}
	}

	fmt.Print(ans.String())

}

func NewCF1491A(r *bufio.Reader) *CF1491A {
	return &CF1491A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1491A(bufio.NewReader(os.Stdin)).Run()
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
	"strings"
)

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func ScanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func ScanInt() int {
	return int(ScanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	n, q := ScanInt(), ScanInt()
	a := make([]int, n)

	cnt := map[int]int{}

	for i := range a {
		a[i] = ScanInt()
		cnt[a[i]]++
	}

	for i := 0; i < q; i++ {
		t := ScanInt()

		switch t {
		case 1:
			x := ScanInt() - 1
			cnt[a[x]]--
			a[x] = 1 - a[x]
			cnt[a[x]]++
		case 2:
			k := ScanInt()

			if cnt[1] >= k {
				fmt.Println(1)
			} else {
				fmt.Println(0)
			}
		}
	}
}

package main

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

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

	for tc := 0; tc < tcs; tc++ {
		var n, q, ans int
		_, _ = fmt.Fscan(in, &n, &q)

		a := make([]int, n)
		for i := 0; i < n; i++ {
			_, _ = fmt.Fscan(in, &a[i])
			ans += a[i]
		}

		for i := 0; i < q; i++ {
			var kind, temp int
			_, _ = fmt.Fscan(in, &kind, &temp)

			if kind == 1 {
				a[temp-1] ^= 1
				if a[temp-1] == 0 {
					ans--
				} else {
					ans++
				}
			} else {
				if ans >= temp {
					fmt.Println(1)
				} else {
					fmt.Println(0)
				}
			}
		}
	}
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

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

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

func sstring() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	n := sint64()
	q := sint64()
	a := sint64s(n)
	counts := []int64{0, 0}
	for _, i := range a {
		counts[i]++
	}
	for i := q; i > 0; i-- {
		t := sint64()
		x := sint64() // or k
		switch t {
		case 1:
			cur := a[x-1]
			counts[1-cur]++
			counts[cur]--
			a[x-1] = 1 - a[x-1]
		case 2:
			if counts[1] >= x {
				printf("1\n")
			} else {
				printf("0\n")
			}
		default:
			panic("unexpected t")
		}
	}
}

package main

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

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

	var n, q int
	fmt.Fscan(in, &n, &q)
	a := make([]int, n)
	ones := 0
	for i := range a {
		fmt.Fscan(in, &a[i])
		if a[i] == 1 {
			ones++
		}
	}

	var t, x int
	for i := 0; i < q; i++ {
		fmt.Fscan(in, &t, &x)
		if t == 1 {
			x--
			a[x] = 1 - a[x]
			if a[x] == 1 {
				ones++
			} else {
				ones--
			}
		} else {
			if ones >= x {
				fmt.Fprintln(out, 1)
			} else {
				fmt.Fprintln(out, 0)
			}
		}
	}
	out.Flush()
}

package main

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

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

func MAX(x, y int) int {
	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 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]
// })

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	var n int
	var q int
	fmt.Fscan(input, &n)
	fmt.Fscan(input, &q)

	// STRING := make([]byte, 0)
	// fmt.Fscan(input, &STRING)
	ARRAY := make([]int, n)
	var Ones int
	var zeros int
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &ARRAY[i])
		if ARRAY[i] == 0 {
			zeros = zeros + 1
		} else {
			Ones = Ones + 1
		}
	}

	for k := 0; k < q; k++ {
		var a, b int
		fmt.Fscan(input, &a)
		fmt.Fscan(input, &b)

		if a == 1 {
			if ARRAY[b-1] == 0 {
				zeros = zeros - 1
				Ones = Ones + 1
			} else {
				zeros = zeros + 1
				Ones = Ones - 1
			}
			ARRAY[b-1] = 1 - ARRAY[b-1]
		} else {
			if b > Ones {
				fmt.Println(0)
			} else {
				fmt.Println(1)
			}
		}
	}

}

package main
import (
    "os"
    "fmt"
    "bufio"
)
var rd = bufio.NewReader(os.Stdin)
func main() {
    n, q := 0, 0
    fmt.Fscan(rd, &n, &q)
    a := make([]int, n)
    cur := 0
    for i := range a {
        fmt.Fscan(rd, &a[i])
        cur += a[i]
    }
    for i := 0; i < q; i++ {
        t, x := 0, 0
        fmt.Fscan(rd, &t, &x)
        if t == 1 {
            x--
            a[x] ^= 1
            cur += 2 * a[x] - 1
        } else {
            if cur >= x {
                fmt.Println(1)
            } else {
                fmt.Println(0)
            }
        }
    }
}

package main

import (
	"bufio"
	"log"
	"os"
	"fmt"
)
// sortable struct      sort.Sort(ByStrength(drags))
type dragon struct {
	strength int
	bonus    int
}
// ByStrength returns
type ByStrength []dragon

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

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int
	n = 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return - n
	}
	return n
}

//========== Implement Algorithm =======================
func solution(t,k int, list []dragon, oneCount int) int {
	// swapped := false
	// fmt.Println("list",list)
	// fmt.Println("sorted",sortedList)
	// fmt.Println(t,"t ",k,"k ",oneCount, "oc")
	if t != 2 {
		val := list[k-1].strength
		p := &list[k-1]
		p.strength = 1-val
		if val == 1{
			oneCount--
		}else{
			oneCount++
		}
		// for i := 0; i < len(sortedList); i++ {
		// 	if sortedList[i].strength == 1{

		// 		p2 := &sortedList[i]
		// 		p2.strength = 1-val
		// 		swapped = true
		// 		break
		// 	}
		// }
		// if !swapped{
		// 	p3 := &sortedList[len(sortedList)-1]
		// 	p3.strength = 1-p3.strength
		// }
	}else{
		if oneCount >= k {
			fmt.Println(1)
		}else{
			fmt.Println(0)
		}
		// fmt.Println(sortedList[(len(sortedList))-k].strength)

	}
	return oneCount

}

func main() {

	scanner := bufio.NewReader(os.Stdin)

	//================== Variables used ====================
	var n,q,t,k int

	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewReader(file)
		defer file.Close()

	}
	// scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	fmt.Fscan(scanner, &n, &q)
	list := make([]dragon,n)
	// sortedList := make([]dragon,n)
	var in,oneCount int
	for i := 0; i < n; i++ {

		fmt.Fscan(scanner, &in)
		// scanner.Scan()
		// inval := fastGetInt(scanner.Bytes())
		val := dragon{in,0}
		if in == 1{
			oneCount++
		}
		list[i] = val
		// sortedList[i] = val
	}

	// sort.Sort(ByStrength(sortedList))

	for i := 0; i < q; i++ {
		fmt.Fscan(scanner, &t, &k)
		oneCount = solution(t,k,list,oneCount)
	}

	//======================================================

	//==================== OUTPUT ==========================

}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func solve() {
	n, q := getI(), getI()
	var ones, zeroes int64
	a := make([]int64, n)
	for i := int64(0); i < n; i++ {
		a[i] = getI()
		if a[i] == 1 {
			ones++
		} else {
			zeroes++
		}
	}

	for i := int64(0); i < q; i++ {
		t, v := getI(), getI()
		if t == 1 {
			if a[v-1] == 1 {
				zeroes++
				ones--
				a[v-1] = 0
			} else {
				ones++
				zeroes--
				a[v-1] = 1
			}
		} else {
			if ones >= v {
				out(1)
			} else {
				out(0)
			}
		}
	}
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	solve()
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func nsort(data ...int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

func asub(a, b int64) int64 {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

import "fmt"

func main() {
	var n, q int
	var count int = 0
	fmt.Scanf("%d %d", &n, &q)
	a := make([]int, n)
	var k, m int
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		if a[i] == 1 {
			count++
		}
	}
	for i := 0; i < q; i++ {
		fmt.Scanf("%d %d", &k, &m)
		if k == 1 {
			if a[m-1] == 0 {
				count++
			} else {
				count--
			}
			a[m-1] = 1 - a[m-1]
		} else {
			if m <= count {
				fmt.Println(1)
			} else {
				fmt.Println(0)
			}
		}
	}
}

package main

import "fmt"

func main() {
	var n, q int
	var count int = 0
	fmt.Scanf("%d %d", &n, &q)
	var a [100001]int
	var k, m int
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		if a[i] == 1 {
			count++
		}
	}
	for i := 0; i < q; i++ {
		fmt.Scanf("%d %d", &k, &m)
		if k == 1 {
			if a[m-1] == 0 {
				count++
			} else {
				count--
			}
			a[m-1] = 1 - a[m-1]
		} else {
			if m <= count {
				fmt.Println(1)
			} else {
				fmt.Println(0)
			}
		}
	}
}

package main

import "fmt"

func main() {
	var n, q int
	var count int = 0
	fmt.Scanf("%d %d", &n, &q)
	var a [100001]int
	var k, m int
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		if a[i] == 1 {
			count++
		}
	}
	for i := 0; i < q; i++ {
		fmt.Scanf("%d %d", &k, &m)
		if k == 1 {
			if a[m-1] == 0 {
				count++
			} else {
				count--
			}
			a[m-1] = 1 - a[m-1]
		} else {
			if m <= count {
				fmt.Printf("%d\n", 1)
			} else {
				fmt.Printf("%d\n", 0)
			}
		}
	}
}

package main

import "fmt"

func main() {
	var n, q int
	var count int = 0
	fmt.Scanf("%d %d", &n, &q)
	a := make([]int, n)
	var k, m int
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		if a[i] == 1 {
			count++
		}
	}
	for i := 0; i < q; i++ {
		fmt.Scanf("%d %d", &k, &m)
		if k == 1 {
			if a[m-1] == 0 {
				count++
			} else {
				count--
			}
			a[m-1] = 1 - a[m-1]
		} else {
			if m <= count {
				fmt.Printf("%d\n", 1)
			} else {
				fmt.Printf("%d\n", 0)
			}
		}
	}
}

package main
import (
    "os"
    "fmt"
    "bufio"
)
var rd = bufio.NewReader(os.Stdin)
func main() {
    n, q := 0, 0
    fmt.Fscan(rd, &n, &q)
    a := make([]int, n)
    cur := 0
    for i := range a {
        fmt.Fscan(rd, &a[i])
        cur += a[i]
    }
    for i := 0; i < q; i++ {
        t, x := 0, 0
        fmt.Fscan(rd, &t, &x)
        if t == 1 {
            x--
            if a[x] == 1 {
                cur--
            } else {
                cur++
            }
        } else {
            if cur >= x {
                fmt.Println(1)
            } else {
                fmt.Println(0)
            }
        }
    }
}

package main
import (
    "os"
    "fmt"
    "bufio"
)
var rd = bufio.NewReader(os.Stdin)
func main() {
    n, q := 0, 0
    fmt.Fscan(rd, &n, &q)
    a := make([]int, n)
    cur := 0
    for i := range a {
        fmt.Fscan(rd, &a[i])
        cur += a[i]
    }
    for i := 0; i < q; i++ {
        t, x := 0, 0
        fmt.Fscan(rd, &t, &x)
        if t == 1 {
            x--
            if a[i] == 1 {
                cur--
            } else {
                cur++
            }
        } else {
            if cur >= x {
                fmt.Println(1)
            } else {
                fmt.Println(0)
            }
        }
    }
}

package main
import (
    "os"
    "fmt"
    "bufio"
)
var rd = bufio.NewReader(os.Stdin)
func main() {
    tc := 0
    fmt.Fscan(rd, &tc)
    for ct := 0; ct < tc; ct++ {
        n, q := 0, 0
        fmt.Fscan(rd, &n, &q)
        a := make([]int, n)
        cur := 0
        for i := range a {
            fmt.Fscan(rd, &a[i])
            cur += a[i]
        }
        for i := 0; i < q; i++ {
            t, x := 0, 0
            fmt.Fscan(rd, &t, &x)
            if t == 1 {
                x--
                if (a[x] == 1) {
                    cur--
                } else {
                    cur++
                }
            } else {
                if (cur >= x) {
                    fmt.Println(1)
                } else {
                    fmt.Println(0)
                }
            }
        }
    }
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func solve() {
	n, q := getI(), getI()
	var ones, zeroes int64
	a := make([]int64, n)
	for i := int64(0); i < n; i++ {
		a[i] = getI()
		if a[i] == 1 {
			ones++
		} else {
			zeroes++
		}
	}

	for i := int64(0); i < q; i++ {
		t, v := getI(), getI()
		if t == 1 {
			if a[v-1] == 1 {
				zeroes++
				ones--
			} else {
				ones++
				zeroes--
			}
		} else {
			if ones >= v {
				out(1)
			} else {
				out(0)
			}
		}
	}
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	solve()
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func nsort(data ...int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

func asub(a, b int64) int64 {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n, q, n0, n1, num, q1, q2 int
	var queue []int
	Fscan(in, &n)
	Fscan(in, &q)
	for i := 0; i < n; i++ {
		Fscan(in, &num)
		queue = append(queue, num)
		if num == 0 {
			n0++
		} else {
			n1++
		}
	}
	for i := 0; i < q; i++ {
		Fscan(in, &q1)
		Fscan(in, &q2)
		if q1 == 1 {
			if queue[q2-1] == 0 {
				n1++
				n0--
			} else {
				n0++
				n1--
			}
		}
		if q1 == 2 {
			if q2 > n1 {
				Fprintln(out, 0)
			} else {
				Fprintln(out, 1)
			}
		}
	}

}


package main

import (
    "fmt"
)

func main() {
    var n, m int
    fmt.Scanf("%d %d\n", &n, &m)
    ans := 0
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            a := 0
            b := 0
            fmt.Scanf("%d %d", &a, &b)
            if a != 0 || b != 0 {
                ans++
            }
        }
        fmt.Scanf("\n")
    }
    fmt.Println(ans)
}

package main

import (
	"fmt"
)

func fun(x int, y int) int {
	if x == 1 || y == 1 {
		return 1
	} else {
		return 0
	}
}

func main() {
	var a, b, c, d, e int
	fmt.Scan(&a, &b)
	for i := 0; i < a*b; i++ {
		fmt.Scan(&d, &e)
		c += fun(d, e)
	}
	fmt.Println(c)
}

// cf595a project main.go
package main

import (
	"fmt"
)

func main() {
	var n, m int
	f := 0
	fmt.Scan(&n, &m)
	for i := 0; i < n; i++ {
		for j := 0; j < 2*m; j += 2 {
			var a, b int
			fmt.Scan(&a, &b)
			if a > 0 || b > 0 {
				f++
			}
		}
	}
	fmt.Println(f)
}

package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	//fmt.Scanf("%d%d", &n, &m)
	ans := 0
	for i := 0; i < n; i++ {
		var x, y int
		for j := 0; j < m; j++ {
			//fmt.Scanf("%d%d", &x, &y)
			fmt.Scan(&x, &y)
			if x != 0 || y != 0 {
				ans++
			}
		}
	}
	fmt.Println(ans)
}

// A. Vitaly and Night
/*
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.

Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.

Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.

Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively.

Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.

Output
Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.

Examples
Input
2 2
0 0 0 1
1 0 1 1

Output
3

Input
1 3
1 1 0 1 0 0

Output
2

Note
In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.

In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _ := reader.ReadString('\n')
	arr1 := strings.Split(strings.TrimSpace(input1), " ")
	n, _ := strconv.Atoi(arr1[0])
	m, _ := strconv.Atoi(arr1[1])

	result := 0
	for ; n > 0; n-- {
		input2, _ := reader.ReadString('\n')
		arr2 := strings.Split(strings.TrimSpace(input2), " ")

		for i := 0; i < m; i++ {
			if arr2[2*i] == "1" || arr2[2*i+1] == "1" {
				result++
			}
		}
	}
	fmt.Print(result)
}

package main

import (
    "fmt"
)

func main() {
    var n, m int
    fmt.Scan(&n, &m)
    ans := 0
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            a := 0
            b := 0
            fmt.Scan( &a, &b)
            if a != 0 || b != 0 {
                ans++
            }
        }
    }
    fmt.Println(ans)
}

package main

import (
	"fmt"
)

const N int = 3e5 + 100

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	// fmt.Printf("%d %d\n", n, m)

	ans := 0
	for i := 0; i < n; i ++ {
		for j := 0; j < m; j ++ {
			var a, b int
			fmt.Scan(&a, &b)
			if a + b > 0 {
				ans ++;
			}
		}
	}
	fmt.Printf("%d\n", ans)
}

package main

import (
  "fmt"
)

func main() {
  var n, m int
  fmt.Scan(&n, &m)
  ans := 0
  for i := 0; i < n; i++ {
    for j := 0; j < m; j++ {
      a := 0
      b := 0
      fmt.Scan(&a, &b)
      if a != 0 || b != 0 {
        ans++
      }
    }
  }
  fmt.Println(ans)
}

package main

import (
	"fmt"
)

func isSleep(x int, y int) int {
	if x == 1 || y == 1 {
		return 1
	} else {
		return 0
	}
}

func main() {
	var n int
	var m int
	var on1 int
	var on2 int
	var res int
	fmt.Scan(&n, &m)
	for i := 0; i < n*m; i++ {
		fmt.Scan(&on1, &on2)
		res += isSleep(on1, on2)
	}
	fmt.Println(res)
}

package main

import "fmt"

func main() {
	var n, m int
	r := 0
	fmt.Scan(&n, &m)
	for i:=0;i<n*m;i++ {
		var a, b int
		fmt.Scan(&a,&b)
		if a+b>0 {
			r++
		}
	}
	fmt.Print(r)
}

package main

import "fmt"

func main() {
    var n, m int
    fmt.Scanf("%d %d\n", &n, &m)
    var win [110][210]int
    for i := 0; i < n; i++ {
        for j := 0; j < m*2; j++ {
            fmt.Scanf("%d", &win[i][j])
        }
        fmt.Scanf("\n")
    }
    ans := 0
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            if win[i][j*2] == 1 || win[i][j*2+1] == 1 {
                ans++
            }
        }
    }
    fmt.Printf("%d\n", ans)
}

package main

import "fmt"

func main() {
    var n, m int
    fmt.Scanf("%d %d\n", &n, &m)
    var win [][]int = make([][]int, n)
    for i := 0; i < n; i++ {
        win[i] = make([]int, m*2)
    }
    for i := 0; i < n; i++ {
        for j := 0; j < m*2; j++ {
            fmt.Scanf("%d", &win[i][j])
        }
        fmt.Scanf("\n")
    }
    ans := 0
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            if win[i][j*2] == 1 || win[i][j*2+1] == 1 {
                ans++
            }
        }
    }
    fmt.Printf("%d\n", ans)
}

package main

import "fmt"

func main() {
    var n, m int
    fmt.Scanf("%d %d\n", &n, &m)
    var win [][]int = make([][]int, n)
    for i := 0; i < n; i++ {
        win[i] = make([]int, m*2)
    }
    for i := 0; i < n; i++ {
        for j := 0; j < m*2; j++ {
            fmt.Scanf("%d", &win[i][j])
        }
        fmt.Scanf("%d\n")
    }
    ans := 0
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            if win[i][j*2] == 1 || win[i][j*2+1] == 1 {
                ans++
            }
        }
    }
    fmt.Printf("%d\n", ans)
}

package main

import "fmt"

func run(arr []int, ch chan int) {
	length := len(arr) / 2
	ret := 0
	for i := 0; i < length; i++ {
		if arr[i*2]+arr[i*2+1] > 0 {
			ret++
		}
	}
	ch <- ret
}

func main() {
	var n, m int
	fmt.Scanf("%d %d\n", &n, &m)
	var win [][]int = make([][]int, n)
	for i := 0; i < n; i++ {
		win[i] = make([]int, m*2)
	}
	ch := make(chan int)
	for i := 0; i < n; i++ {
		for j := 0; j < m*2; j++ {
			fmt.Scanf("%d", &win[i][j])
		}
		fmt.Scanf("\n")
		go run(win[i], ch)
	}
	ans := 0
	for i := 0; i < n; i++ {
		ans += <-ch
		//fmt.Println(ans)
	}
	fmt.Printf("%d\n", ans)
}

package main

import (
    "fmt"
)

func main() {
    var n, m int;
    sum := 0;
    fmt.Scan(&n, &m);
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++{
            var a, b int;
            fmt.Scan(&a, &b);
            if a != 0 || b != 0 {
                sum += 1;
            }
        }
    }

    fmt.Println(sum);
}

package main

import (
	"fmt"
)

func solve(first int, second int) int {
	if first == 1 || second == 1 {
		return 1
	} else {
		return 0
	}
}

func main() {
	var n, m, a, b int
	var count = 0
	fmt.Scan(&n, &m)
	for i := 0; i < n*m; i++ {
		fmt.Scan(&a, &b)
		count += solve(a, b)
	}
	fmt.Println(count)
}

package main

import "fmt"

func main() {
	var n, m int
	fmt.Scanf("%d%d", &n, &m)
	ans := 0
	for i := 0; i < n; i++ {
		var x, y int
		for j := 0; j < m; j++ {
			fmt.Scanf("%d%d", &x, &y)
			if x != 0 || y != 0 {
				ans++
			}
		}
	}
	fmt.Printf("%d", ans)
}

package main

import "fmt"

func main() {
	var n, m int
	fmt.Scanf("%d%d", &n, &m)
	ans := 0
	for i := 0; i < n; i++ {
		var x, y int
		for j := 0; j < m; j++ {
			fmt.Scanf("%d%d", &x, &y)
			if x != 0 || y != 0 {
				ans++
			}
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"

func main() {
	var n, m int
	fmt.Scanf("%d%d", &n, &m)
	ans := 0
	for i := 0; i < n; i++ {
		var x, y int
		for j := 0; j < m; j++ {
			fmt.Scanf("%d%d", &x, &y)
			if x != 0 || y != 0 {
				ans++
			}
		}
	}
	fmt.Println("%d", ans)
}

package main

import (
    "fmt"
)

func main() {
    var n, m int
    fmt.Scanf("%d %d", &n, &m)
    ans := 0
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            a := 0
            b := 0
            fmt.Scanf("%d %d ", &a, &b)
            if a != 0 || b != 0 {
                ans++
            }
        }
    }
    fmt.Println(ans)
}

package main

import "fmt"

const N int = 3e5 + 100

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

	ans := 0
	for i := 0; i < n; i ++ {
		for j := 0; j < m; j ++ {
			var a, b int
			fmt.Scanf("%d%d", &a, &b)
			if a + b > 0 {
				ans ++;
			}
		}
	}
	fmt.Printf("%d\n", ans)
}

package main

import "fmt"

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	var win [][]int = make([][]int, n)
	for i := 0; i < n; i++ {
		win[i] = make([]int, m*2)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m*2; j++ {
			fmt.Scanf("%d", &win[i][j])
		}
	}
	ans := 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if win[i][j*2] == 1 || win[i][j*2+1] == 1 {
				ans++
			}
		}
	}
	fmt.Printf("%d\n", ans)
}

package main

import "fmt"

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	var win [][]int = make([][]int, n)
	for i := 0; i < n; i++ {
		win[i] = make([]int, m*2)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m*2; j++ {
			fmt.Scanf("%d", &win[i][j])
		}
	}
	ans := 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if win[i][j*2] == 1 || win[i][j*2+1] == 1 {
				ans++
			}
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"

func main() {
    var n, m int
    fmt.Scanf("%d %d", &n, &m)
    var win [][]int = make([][]int, n)
    for i := 0; i < n; i++ {
        win[i] = make([]int, m*2)
    }
    for i := 0; i < n; i++ {
        for j := 0; j < m*2; j++ {
            fmt.Scanf("%d", &win[i][j])
        }
    }
    ans := 0
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            if win[i][j*2]+win[i][j*2+1] > 0 {
                ans++
            }
        }
    }
    fmt.Println(ans)
}

package main

import (
    "fmt"
)

func main() {
    var n, m int
    fmt.Scanf("%d %d\n", &n, &m)
    ans := 0
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            a := 0
            b := 0
            fmt.Scanf("%d %d", &a, &b)
            fmt.Println(a, b)
            if a != 0 || b != 0 {
                ans++
            }
        }
        fmt.Scanf("\n")
    }
    fmt.Println(ans)
}

package main

import (
    "fmt"
)

func main() {
    var n, m int
    fmt.Scanf("%d %d", &n, &m)
    ans := 0
    for i := 0; i < n; i++ {
        for j := 0; j < n; j++ {
            a := 0
            b := 0
            fmt.Scanf("%d %d ", &a, &b)
            if a != 0 || b != 0 {
                ans++
            }
        }
    }
    fmt.Println(ans)
}

package main

import (
    "fmt"
)

func main() {
    var n, m int
    fmt.Scanf("%d%d", &n, &m)
    ans := 0
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            a := 0
            b := 0
            fmt.Scanf("%d%d ", &a, &b)
            if a != 0 || b != 0 {
                ans++
            }
        }
    }
    fmt.Println(ans)
}

package main

import (
	"fmt"
)

func solve(first int, second int) int {
	if first == 1 || second == 1 {
		return first
	} else {
		return 0
	}
}

func main() {
	var n, m, a, b int
	var count = 0
	fmt.Scan(&n, &m)
	for i := 0; i < n*m; i++ {
		fmt.Scan(&a, &b)
		count += solve(a, b)
	}
	fmt.Println(count)
}


package main

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

type Node struct {
	parent  int
	childes []int
	index int
	size int
	answer int
}

func (curr *Node) countSize (nodes []Node) {
	curr.size = 1

	for _, v := range curr.childes {
		nodes[v].countSize(nodes)
		curr.size += nodes[v].size
	}
}

func (curr *Node) computeAnswers (nodes []Node) {
	if len(curr.childes) == 0 {
		curr.answer = curr.index
		return
	}

	for _, child := range curr.childes {
		nodes[child].computeAnswers(nodes)
	}

	candidate := nodes[nodes[findMaxSize(curr.childes, nodes)].answer]
	for ; 2 * candidate.size < curr.size; candidate = nodes[candidate.parent] {}

	curr.answer = candidate.index
}

func findMaxSize(indices []int, nodes []Node) int {
	result := 0
	for _, index := range indices {
		if nodes[index].size > nodes[result].size {
			result = index
		}
	}
	return result
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)

	scanner.Split(bufio.ScanWords)
	scanner.Scan()

	size, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	queries, _ := strconv.Atoi(scanner.Text())

	nodes := make([]Node, size+1)
	nodes[1].index = 1

	for i := 2; i < size+1; i++ {
		nodes[i].index = i
		scanner.Scan()
		nodes[i].parent, _ = strconv.Atoi(scanner.Text())
		nodes[nodes[i].parent].childes = append(nodes[nodes[i].parent].childes, i)
	}

	nodes[1].countSize(nodes)
	nodes[1].computeAnswers(nodes)

	for i := 0; i < queries; i++ {
		scanner.Scan()
		query, _ := strconv.Atoi(scanner.Text())
		writer.WriteString(strconv.Itoa(nodes[query].answer)+"\n")
	}
	writer.Flush()

}

package main

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

var g = make([][]int, 300001)
var n, q int
var sum = make([]int, 300001)
var p = make([]int, 300001)
var h = make([]int, 300001)

func pre(u int, f int) {
	sum[u] = 1
	for _,chd := range g[u] {
		if chd != f {
			pre(chd, u)
			sum[u] += sum[chd]
		}
	}
}

func dfs(u int, f int) int {
	var hv int
	for _, chd := range g[u] {
		if f != chd {
			tmp := dfs(chd, u)
			if sum[chd] * 2 >= sum[u] {
				hv = tmp
				for {
					if 2 * sum[hv] >= sum[u] {
						break
					}
					hv = p[hv]
				}
			}
		}
	}
	if hv == 0 {
		h[u] = u
		return u
	}
	h[u] = hv
	return hv
}

func main() {
	fmt.Scanf("%d %d\n", &n, &q)
	reader := bufio.NewReaderSize(os.Stdin, 10000000)
	bytes, _, _ := reader.ReadLine()
	strs := strings.Split(string(bytes), " ")
	for i:=2 ; i<=n ; i++ {
		to ,_:=strconv.Atoi(strs[i-2])
		p[i] = to
		g[i] = append(g[i], to)
		g[to] = append(g[to], i)
	}
	pre(1, 1)
	dfs(1, 1)
	for i:=0; i< q; i++ {
		bytes, _, _ := reader.ReadLine()
		to ,_:=strconv.Atoi(string(bytes))
		fmt.Println(h[to])
	}
}

package main

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

type Node struct {
	parent  int
	childes []int
	index int
	size int
	answer int
}

func (curr *Node) countSize (nodes []Node) {
	curr.size = 1

	for _, v := range curr.childes {
		nodes[v].countSize(nodes)
		curr.size += nodes[v].size
	}
}

func (curr *Node) computeAnswers (nodes []Node) {
	if len(curr.childes) == 0 {
		curr.answer = curr.index
		return
	}

	for _, child := range curr.childes {
		nodes[child].computeAnswers(nodes)
	}

	candidate := nodes[nodes[findMaxSize(curr.childes, nodes)].answer]
	for ; 2 * candidate.size < curr.size; candidate = nodes[candidate.parent] {}

	curr.answer = candidate.index
}

func findMaxSize(indices []int, nodes []Node) int {
	result := 0
	for _, index := range indices {
		if nodes[index].size > nodes[result].size {
			result = index
		}
	}
	return result
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)

	scanner.Split(bufio.ScanWords)
	scanner.Scan()

	size, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	queries, _ := strconv.Atoi(scanner.Text())

	nodes := make([]Node, size+1)
	nodes[1].index = 1

	for i := 2; i < size+1; i++ {
		nodes[i].index = i
		scanner.Scan()
		nodes[i].parent, _ = strconv.Atoi(scanner.Text())
		nodes[nodes[i].parent].childes = append(nodes[nodes[i].parent].childes, i)
	}

	nodes[1].countSize(nodes)
	nodes[1].computeAnswers(nodes)

	for i := 0; i < queries; i++ {
		scanner.Scan()
		query, _ := strconv.Atoi(scanner.Text())
		writer.WriteString(strconv.Itoa(nodes[query].answer)+"\n")
	}

}