Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length. Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1 ≤ i ≤ n). Help Polycarpus determine the length of the city phone code.

The first line of the input contains an integer n (2 ≤ n ≤ 3·104) — the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn — the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.

Print the number of digits in the city phone code.

NoteA prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".In the first sample the city phone code is string "00".In the second sample the city phone code is an empty string.In the third sample the city phone code is string "770123456789".

package main
import (
	"fmt"
	//"sort"
	"unicode/utf8"
	"bufio"
	"os"
)
func main() {
	var n,j int
	var p,a string
	fmt.Scan(&n,&p)
	ma := utf8.RuneCountInString(p)
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	for i:=0;i<n-1;i++ {
		input.Scan()
		a=input.Text()
		//fmt.Scan(&a)
		lena:=utf8.RuneCountInString(a)
		j=0
		for ;j<lena && a[j]==p[j]; {
			j++
		}
		if j<ma {
			ma=j
		}
		p=a
	}
	fmt.Println(ma)
}

package main

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

func main() {
	var (
		n, i, j, maxj int32
		s             []string
		olv           *bufio.Reader
	)

	olv = bufio.NewReader(os.Stdin)

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

	//fmt.Println(s)
	//for i = 0; i < n; i++ {
	//	fmt.Print(len(s[i]), " ")

	//}
	//fmt.Println()

	maxj = int32(len(s[0]))
	for j = 0; j < maxj; {
		c := s[0][j]
		for i = 1; i < n && s[i][j] == c; i++ {
		}
		if i == n {
			j++
		} else {
			break
		}
	}
	fmt.Println(j)
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    var n int
    fmt.Scan(&n)
    s := make([]string,n)
    for i := 0; i < n; i++ {
        for scanner.Scan() { if scanner.Text() != "" { break } }
        s[i] = scanner.Text()
    }
    ans := 0
    for i := 0; i < len(s[0]); i++ {
        ok := true
        for j := 0; j < n; j++ {
            if s[j][i] != s[0][i] { ok = false; break }
        }
        if ok { ans++ } else { break }
    }
    fmt.Println(ans)
}

// 172A-mic
package main

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

func main() {
    var x, sum int
    fmt.Scan(&x)
    s := make([]string, x)
    z := bufio.NewReader(os.Stdin)
    for i := 0; i < x; i++ {
        fmt.Fscan(z, &s[i])
    }
    for i := 0; i < len(s[0]); i++ {
        c := 0
        for z := 1; z < x; z++ {
            if s[z][i] == s[0][i] {
                c++
            }
        }
        if c == x-1 {
            sum++
        } else {
            break
        }

    }
    fmt.Println(sum)
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/172/A

package main

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

func longestCommonPrefix(s1 string, s2 string) string {
	ptr1 := 0
	ptr2 := 0
	for ptr1 < len(s1) && ptr2 < len(s2) {
		if s1[ptr1] != s2[ptr2] {
			return s1[:ptr1]
		}
		ptr1 += 1
		ptr2 += 1
	}
	return s1
}

func Solve(n int, strings []string) int {
	prefix := strings[0]
	for i := 1; i < n; i++ {
		prefix = longestCommonPrefix(prefix, strings[i])
		if len(prefix) == 0 {
			return 0
		}
	}
	return len(prefix)
}

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

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

	fmt.Fprintf(writer, "%d\n", Solve(n, strings))
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    var n int
    fmt.Scan(&n)
    s := make([]string,n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        s[i] = scanner.Text()
    }
    ans := 0
    for i := 0; i < len(s[0]); i++ {
        ok := true
        for j := 0; j < n; j++ {
            if s[j][i] != s[0][i] { ok = false; break }
        }
        if ok { ans++ } else { break }
    }
    fmt.Println(ans)
}


When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. There were n dishes. Kefa knows that he needs exactly m dishes. But at that, he doesn't want to order the same dish twice to taste as many dishes as possible. Kefa knows that the i-th dish gives him ai units of satisfaction. But some dishes do not go well together and some dishes go very well together. Kefa set to himself k rules of eating food of the following type — if he eats dish x exactly before dish y (there should be no other dishes between x and y), then his satisfaction level raises by c. Of course, our parrot wants to get some maximal possible satisfaction from going to the restaurant. Help him in this hard task!

The first line of the input contains three space-separated numbers, n, m and k (1 ≤ m ≤ n ≤ 18, 0 ≤ k ≤ n * (n - 1)) — the number of dishes on the menu, the number of portions Kefa needs to eat to get full and the number of eating rules. The second line contains n space-separated numbers ai, (0 ≤ ai ≤ 109) — the satisfaction he gets from the i-th dish. Next k lines contain the rules. The i-th rule is described by the three numbers xi, yi and ci (1 ≤ xi, yi ≤ n, 0 ≤ ci ≤ 109). That means that if you eat dish xi right before dish yi, then the Kefa's satisfaction increases by ci. It is guaranteed that there are no such pairs of indexes i and j (1 ≤ i < j ≤ k), that xi = xj and yi = yj.

In the single line of the output print the maximum satisfaction that Kefa can get from going to the restaurant.

NoteIn the first sample it is best to first eat the second dish, then the first one. Then we get one unit of satisfaction for each dish and plus one more for the rule.In the second test the fitting sequences of choice are 4 2 1 or 2 1 4. In both cases we get satisfaction 7 for dishes and also, if we fulfill rule 1, we get an additional satisfaction 5.

package main

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

var scanner *bufio.Scanner

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

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

func nextInt() int{
    x, _ := strconv.ParseInt(nextToken(), 10, 64)
    return int(x)
}
func nextLong() int64{
    x, _ := strconv.ParseInt(nextToken(), 10, 64)
    return x
}
func nextFloat() float64{
    x, _ := strconv.ParseFloat(nextToken(), 64)
    return x
}

var n, m, k int
var a [20]int64
var p [20]int
var w [20][20]int64
var u [20][(1<<20)]bool
var dp [20][(1<<20)]int64

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

func bitCount(x int) int {
    res := 0
    for x > 0 {
        res++
        x &= (x-1)
    }
    return res
}

func f(v, mask int) int64 {
    if u[v][mask] == true {
        return dp[v][mask]
    }
    cnt := bitCount(mask)
    if cnt == m {
        return 0
    }
    ans := int64(0)
    for i := 0; i < n; i++ {
        if (mask&p[i]) > 0 {
            continue
        }
        ans = max(ans, a[i] + w[v][i] + f(i, mask | p[i]))
    }
    u[v][mask] = true
    dp[v][mask] = ans
    return ans
}

func main() {
    n, m, k = nextInt(), nextInt(), nextInt()
    for i := 0; i < n; i++ {
        a[i] = nextLong()
    }
    p[0] = 1
    for i := 1; i < n; i++ {
        p[i] = p[i-1] * 2
    }
    for i := 0; i < k; i++ {
        x, y, c := nextInt(), nextInt(), nextLong()
        w[x - 1][y - 1] = c
    }
    et := int64(0)
    for i := 0; i < n; i++ {
        et = max(et, a[i] + f(i,p[i]))
    }
    fmt.Println(et)
}

package main

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

const N = 18

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

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

	a := make([]uint64, n)
	for i := uint(0); i < n; i++ {
		fmt.Fscanf(r, "%d", &a[i])
	}
	fmt.Fscanf(r, "\n")

	var add [20][20]uint64
	for i := uint(0); i < k; i++ {
		var a, b, c uint
		fmt.Fscanf(r, "%d %d %d\n", &a, &b, &c)
		add[a-1][b-1] = uint64(c)
	}

	var dp [][]uint64
	for i := 0; i < (1 << n); i++ {
		dp = append(dp, make([]uint64, n))
	}

	for mask := (1 << n) - 1; mask >= 0; mask-- {
		cc := uint(0)
		for i := uint(0); i < n; i++ {
			if (mask & (1 << i)) != 0 {
				cc++
			}
		}
		if cc >= m {
			continue
		}
		for i := uint(0); i < n; i++ {
			if (mask & (1 << i)) == 0 {
				continue
			}
			for j := uint(0); j < n; j++ {
				if (mask & (1 << j)) == 0 {
					dp[mask][i] = max(dp[mask][i], dp[mask|(1<<j)][j]+a[j]+add[i][j])
				}
			}
		}
	}

	best := uint64(0)
	for i := uint(0); i < n; i++ {
		best = max(best, dp[1<<i][i]+a[i])
	}

	fmt.Println(best)
}

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

package main

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

func main() {
	var n int
	var m, k int
	fmt.Scan(&n, &m, &k)
	var un uint = uint(n)

	satLevel := make([][]int64, n)
	for i := 0; i < n; i++ {
		satLevel[i] = make([]int64, n)
	}

	bs := bufio.NewScanner(os.Stdin)
	bs.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		bs.Scan()
		temp, _ := strconv.Atoi(bs.Text())
		satLevel[i][i] = int64(temp)
	}

	for ; k > 0; k-- {
		bs.Scan()
		xi, _ := strconv.Atoi(bs.Text())
		xi--
		bs.Scan()
		yi, _ := strconv.Atoi(bs.Text())
		yi--
		bs.Scan()
		w, _ := strconv.Atoi(bs.Text())
		satLevel[xi][yi] = int64(w)
	}

	memo := make([][]int64, 1<<un)
	for i := 0; i < len(memo); i++ {
		memo[i] = make([]int64, n)
	}

	var maxAnswer int64 = 0
	for mask := 1; mask < len(memo); mask++ {
		bitCount := bitCount(mask)
		if bitCount > m {
			continue
		}

		var currMeal uint = 0
		for ; currMeal < un; currMeal++ {
			if (mask & (1 << currMeal)) != (1 << currMeal) {
				continue
			}

			if bitCount == 1 {
				memo[mask][currMeal] = satLevel[currMeal][currMeal]
				maxAnswer = max(maxAnswer, memo[mask][currMeal])
				continue
			}

			var prevMeal uint = 0
			for ; prevMeal < un; prevMeal++ {
				if prevMeal == currMeal || (mask&(1<<prevMeal)) != (1<<prevMeal) {
					continue
				}

				memo[mask][currMeal] = max(memo[mask][currMeal], memo[mask^(1<<currMeal)][prevMeal]+satLevel[currMeal][currMeal]+satLevel[prevMeal][currMeal])
				maxAnswer = max(maxAnswer, memo[mask][currMeal])
			}
		}
	}

	fmt.Println(maxAnswer)
}

func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func bitCount(num int) int {
	numOfBits := 0
	for ; num > 0; num /= 2 {
		if num&1 == 1 {
			numOfBits++
		}
	}

	return numOfBits
}

package main

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

type pair_t struct{ k0, k1 int }

func (p pair_t) String() string { return fmt.Sprintf("(%08b,%08b)", p.k0, p.k1) }

type mem_t interface {
	put(k0, k1 int, val int64)
	get(k0, k1 int) int64
}

type mapmem_t map[pair_t]int64

func (this mapmem_t) put(k0, k1 int, val int64) { this[pair_t{k0, k1}] = val }

func (this mapmem_t) get(k0, k1 int) int64 { return this[pair_t{k0, k1}] }

type arrmem_t [][]int64

func newArrMem(n, m int) arrmem_t {
	size := maxmask(n, m) + 1
	buf := make([]int64, size*n)
	mem := make([][]int64, n)
	for i, _ := range mem {
		mem[i] = buf[i*size : (i+1)*size]
	}
	return mem
}

func (this arrmem_t) put(k0, k1 int, val int64) { this[k1][k0] = val }

func (this arrmem_t) get(k0, k1 int) int64 { return this[k1][k0] }

func handleInput() (int, int, mem_t) {
	var buf string
	in := bufio.NewReader(os.Stdin)

	var n, m, k int
	buf, _ = in.ReadString('\n')
	fmt.Sscanf(buf, "%d %d %d", &n, &m, &k)

	//mem := make(mapmem_t, maxmask(n, m))
	mem := newArrMem(n, m)

	buf, _ = in.ReadString('\n')
	for i, valstr := range strings.Split(strings.TrimSpace(buf), " ") {
		val, _ := strconv.Atoi(valstr)
		mem.put(0, i, int64(val))
		mem.put(1<<uint(i), i, int64(val))
	}

	for i := 0; i < k; i++ {
		var x, y, val int
		buf, _ = in.ReadString('\n')
		fmt.Sscanf(buf, "%d %d %d", &x, &y, &val)
		mem.put(1<<uint(x-1), y-1, int64(val))
	}

	return n, m, mem
}

func solve(n, m int, mem mem_t) int64 {
	var max int64
	for i := 0; i < n; i++ {
		val := mem.get(0, i)
		if max < val {
			max = val
		}
	}

	maxmask := maxmask(n, m)
	for mask := 1; mask <= maxmask; mask++ {
		ones := bitcount(mask)
		if ones > m {
			continue
		}
		for last := 0; last < n; last++ {
			if 0 != mask&(1<<uint(last)) {
				var curMax int64
				prevMask := mask ^ (1 << uint(last))
				for prevLast := 0; prevLast < n; prevLast++ {
					if 0 != prevMask&(1<<uint(prevLast)) && prevLast != last {
						cur := mem.get(0, last) +
							mem.get(prevMask, prevLast) +
							mem.get(1<<uint(prevLast), last)
						if curMax < cur {
							curMax = cur
						}
					}
				}
				if ones < m && curMax != 0 {
					mem.put(mask, last, curMax)
				}
				if max < curMax {
					max = curMax
				}
			}
		}
	}
	return max
}

func maxmask(n, m int) int {
	return (1 << uint(n)) - (1 << uint(n-m))
}

func bitcount(n int) int {
	n = n&0x55555555 + (n>>1)&0x55555555
	n = n&0x33333333 + (n>>2)&0x33333333
	n = n&0x0f0f0f0f + (n>>4)&0x0f0f0f0f
	n = n&0x00ff00ff + (n>>8)&0x00ff00ff
	n = n&0x0000ffff + (n>>16)&0x0000ffff
	return n
}

func main() {
	// s := time.Now()
	// defer func() { fmt.Println("#main", time.Since(s)) }()
	fmt.Println(solve(handleInput()))
}

package main

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

type pair struct {
	k0, k1 int
}

//func (p pair) String() string { return fmt.Sprintf("%08b %08b", p.k0, p.k1) }

type pairs map[pair]int64

func (this *pairs) Add(k0, k1 int, c int64) {
	(*this)[pair{k0, k1}] = c
}

func (this *pairs) Get(k0, k1 int) int64 {
	return (*this)[pair{k0, k1}]
}

func solve(n, m int, rules pairs) int64 {
	cache := make(pairs, (1<<uint(n))+1)
	findMax := func(mask, last int) int64 {
		prevMask := mask ^ last
		var val int64
		for i := 0; i < n; i++ {
			prevLast := 1 << uint(i)
			if prevMask&prevLast != 0 && prevLast != last {
				cur := cache.Get(prevMask, prevLast) +
					rules.Get(0, last) + rules.Get(prevLast, last)
				if val < cur {
					val = cur
				}
			}
		}
		return val
	}

	for i := 0; i < n; i++ {
		idx := 1 << uint(i)
		//fmt.Println("# ", pair{idx, idx}, rules.Get(0, idx))
		cache.Add(idx, idx, rules.Get(0, idx))
	}

	var max int64
	for i := 2; i <= m; i++ {
		forEachMaskLast(n, i, func(mask, last int) {
			val := findMax(mask, last)
			if i == m {
				if max < val {
					max = val
				}
			} else {
				//fmt.Println("# ", pair{mask, last}, val)
				cache.Add(mask, last, val)
			}
		})
	}
	return max
}

func handleInput() (int, int, pairs) {
	var buf string
	in := bufio.NewReader(os.Stdin)

	var n, m, k int
	buf, _ = in.ReadString('\n')
	fmt.Sscanf(buf, "%d %d %d", &n, &m, &k)

	rules := make(pairs, n+k)

	buf, _ = in.ReadString('\n')
	parsedBuf := strings.Split(buf[:len(buf)-1], " ")
	for i := 0; i < n; i++ {
		val, _ := strconv.Atoi(parsedBuf[i])
		rules.Add(0, 1<<uint(i), int64(val))
	}

	for i := 0; i < k; i++ {
		var x, y, val int
		buf, _ = in.ReadString('\n')
		fmt.Sscanf(buf, "%d %d %d", &x, &y, &val)
		rules.Add(1<<uint(x-1), 1<<uint(y-1), int64(val))
	}

	return n, m, rules
}

func forEachMaskLast(n, m int, callback func(int, int)) {
	idxs := make([]bool, n)
	firstTF := func() int {
		for i := 0; i < n-1; i++ {
			if idxs[i] && !idxs[i+1] {
				return i
			}
		}
		return -1
	}
	alignT := func(arr []bool) {
		for i, j := 0, 0; i < len(arr); i++ {
			if arr[i] && j < i {
				arr[i], arr[j] = arr[j], arr[i]
				j++
			}
		}
	}

	for i := 0; i < m; i++ {
		idxs[i] = true
	}
	for true {
		mask := 0
		for i := 0; i < n; i++ {
			if idxs[i] {
				mask |= (1 << uint(i))
			}
		}

		for i := 0; i < n; i++ {
			if idxs[i] {
				last := (1 << uint(i))
				callback(mask, last)
			}
		}

		cur := firstTF()
		if cur == -1 {
			break
		} else {
			idxs[cur], idxs[cur+1] = false, true
			alignT(idxs[:cur])
		}
	}
}

func main() {
	// s := time.Now()
	// defer func() { fmt.Println(time.Since(s)) }()
	fmt.Println(solve(handleInput()))
}

package main

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

type pair struct {
	k0, k1 int
}

func (p pair) String() string { return fmt.Sprintf("%08b %08b", p.k0, p.k1) }

type pairs map[pair]int64

func (this *pairs) Add(k0, k1 int, c int64) {
	(*this)[pair{k0, k1}] = c
}

func (this *pairs) Get(k0, k1 int) int64 {
	return (*this)[pair{k0, k1}]
}

func solve(n, m int, rules pairs) int64 {
	cache := make(pairs, (1<<uint(n))+1)
	findMax := func(mask, last int) int64 {
		prevMask := mask ^ last
		var val int64
		for i := 0; i < n; i++ {
			prevLast := 1 << uint(i)
			if prevMask&prevLast != 0 && prevLast != last {
				cur := cache.Get(prevMask, prevLast) +
					rules.Get(0, last) + rules.Get(prevLast, last)
				if val < cur {
					val = cur
				}
			}
		}
		return val
	}

	for i := 0; i < n; i++ {
		idx := 1 << uint(i)
		// fmt.Println("# ", pair{idx, idx}, rules.Get(0, idx))
		cache.Add(idx, idx, rules.Get(0, idx))
	}

	var max int64
	for i := 2; i <= m; i++ {
		forEachMaskLast(n, i, func(mask, last int) {
			val := findMax(mask, last)
			if i == m {
				if max < val {
					max = val
				}
			} else {
				// fmt.Println("# ", pair{mask, last}, val)
				cache.Add(mask, last, val)
			}
		})
	}
	return max
}

func handleInput() (int, int, pairs) {
	var buf string
	in := bufio.NewReader(os.Stdin)

	var n, m, k int
	buf, _ = in.ReadString('\n')
	fmt.Sscanf(buf, "%d %d %d", &n, &m, &k)

	rules := make(pairs, n+k)

	buf, _ = in.ReadString('\n')
	parsedBuf := strings.Split(buf[:len(buf)-1], " ")
	for i := 0; i < n; i++ {
		val, _ := strconv.Atoi(strings.TrimSpace(parsedBuf[i]))
		rules.Add(0, 1<<uint(i), int64(val))
	}

	for i := 0; i < k; i++ {
		var x, y, val int
		buf, _ = in.ReadString('\n')
		fmt.Sscanf(buf, "%d %d %d", &x, &y, &val)
		rules.Add(1<<uint(x-1), 1<<uint(y-1), int64(val))
	}

	return n, m, rules
}

func forEachMaskLast(n, m int, callback func(int, int)) {
	idxs := make([]bool, n)
	firstTF := func() int {
		for i := 0; i < n-1; i++ {
			if idxs[i] && !idxs[i+1] {
				return i
			}
		}
		return -1
	}
	alignT := func(arr []bool) {
		for i, j := 0, 0; i < len(arr); i++ {
			if arr[i] && j < i {
				arr[i], arr[j] = arr[j], arr[i]
				j++
			}
		}
	}

	for i := 0; i < m; i++ {
		idxs[i] = true
	}
	for true {
		mask := 0
		for i := 0; i < n; i++ {
			if idxs[i] {
				mask |= (1 << uint(i))
			}
		}

		for i := 0; i < n; i++ {
			if idxs[i] {
				last := (1 << uint(i))
				callback(mask, last)
			}
		}

		cur := firstTF()
		if cur == -1 {
			break
		} else {
			idxs[cur], idxs[cur+1] = false, true
			alignT(idxs[:cur])
		}
	}
}

func main() {
	// s := time.Now()
	// defer func() { fmt.Println(time.Since(s)) }()
	fmt.Println(solve(handleInput()))
}

package main

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

type pair_t struct{ k0, k1 int }

func (p pair_t) String() string { return fmt.Sprintf("(%08b,%08b)", p.k0, p.k1) }

type mem_t interface {
	put(k0, k1 int, val int64)
	get(k0, k1 int) int64
}

type mapmem_t map[pair_t]int64

func (this mapmem_t) put(k0, k1 int, val int64) { this[pair_t{k0, k1}] = val }

func (this mapmem_t) get(k0, k1 int) int64 { return this[pair_t{k0, k1}] }

type arrmem_t [][]int64

func newArrMem(n, m int) arrmem_t {
	size := maxmask(n, m) + 1
	buf := make([]int64, size*n)
	mem := make([][]int64, n)
	for i, _ := range mem {
		mem[i] = buf[i*size : (i+1)*size]
	}
	return mem
}

func (this arrmem_t) put(k0, k1 int, val int64) { this[k1][k0] = val }

func (this arrmem_t) get(k0, k1 int) int64 { return this[k1][k0] }

func handleInput() (int, int, mem_t) {
	var buf string
	in := bufio.NewReader(os.Stdin)

	var n, m, k int
	buf, _ = in.ReadString('\n')
	fmt.Sscanf(buf, "%d %d %d", &n, &m, &k)

	//mem := make(mapmem_t, maxmask(n, m))
	mem := newArrMem(n, m)

	buf, _ = in.ReadString('\n')
	for i, valstr := range strings.Split(strings.TrimSpace(buf), " ") {
		val, _ := strconv.Atoi(valstr)
		mem.put(0, i, int64(val))
		mem.put(1<<uint(i), i, int64(val))
	}

	for i := 0; i < k; i++ {
		var x, y, val int
		buf, _ = in.ReadString('\n')
		fmt.Sscanf(buf, "%d %d %d", &x, &y, &val)
		mem.put(1<<uint(x-1), y-1, int64(val))
	}

	return n, m, mem
}

func solve(n, m int, mem mem_t) int64 {
	var max int64

	maxmask := maxmask(n, m)
	for mask := 1; mask <= maxmask; mask++ {
		ones := bitcount(mask)
		if ones > m {
			continue
		}
		for last := 0; last < n; last++ {
			if 0 != mask&(1<<uint(last)) {
				var curMax int64
				prevMask := mask ^ (1 << uint(last))
				for prevLast := 0; prevLast < n; prevLast++ {
					if 0 != prevMask&(1<<uint(prevLast)) && prevLast != last {
						cur := mem.get(0, last) +
							mem.get(prevMask, prevLast) +
							mem.get(1<<uint(prevLast), last)
						if curMax < cur {
							curMax = cur
						}
					}
				}
				if ones < m && curMax != 0 {
					mem.put(mask, last, curMax)

				}
				if max < curMax {
					max = curMax
				}
			}
		}
	}
	return max
}

func maxmask(n, m int) int {
	return (1 << uint(n)) - (1 << uint(n-m))
}

func bitcount(n int) int {
	n = n&0x55555555 + (n>>1)&0x55555555
	n = n&0x33333333 + (n>>2)&0x33333333
	n = n&0x0f0f0f0f + (n>>4)&0x0f0f0f0f
	n = n&0x00ff00ff + (n>>8)&0x00ff00ff
	n = n&0x0000ffff + (n>>16)&0x0000ffff
	return n
}

func main() {
	// s := time.Now()
	// defer func() { fmt.Println("#main", time.Since(s)) }()
	fmt.Println(solve(handleInput()))
}


So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation. Right now the situation in Berland is dismal — their both cities are surrounded! The armies of flatlanders stand on the borders of circles, the circles' centers are in the surrounded cities. At any moment all points of the flatland ring can begin to move quickly in the direction of the city — that's the strategy the flatlanders usually follow when they besiege cities.The berlanders are sure that they can repel the enemy's attack if they learn the exact time the attack starts. For that they need to construct a radar that would register any movement at the distance of at most r from it. Thus, we can install a radar at such point, that at least one point of the enemy ring will be in its detecting range (that is, at a distance of at most r). Then the radar can immediately inform about the enemy's attack. Due to the newest technologies, we can place a radar at any point without any problems. But the problem is that the berlanders have the time to make only one radar. Besides, the larger the detection radius (r) is, the more the radar costs.That's why Vasya's task (that is, your task) is to find the minimum possible detection radius for the radar. In other words, your task is to find the minimum radius r (r ≥ 0) such, that a radar with radius r can be installed at some point and it can register the start of the movements of both flatland rings from that point. In this problem you can consider the cities as material points, the attacking enemy rings - as circles with centers in the cities, the radar's detection range — as a disk (including the border) with the center at the point where the radar is placed.

The input files consist of two lines. Each line represents the city and the flatland ring that surrounds it as three space-separated integers xi, yi, ri (|xi|, |yi| ≤ 104; 1 ≤ ri ≤ 104) — the city's coordinates and the distance from the city to the flatlanders, correspondingly. It is guaranteed that the cities are located at different points.

Print a single real number — the minimum detection radius of the described radar. The answer is considered correct if the absolute or relative error does not exceed 10 - 6.

NoteThe figure below shows the answer to the first sample. In this sample the best decision is to put the radar at point with coordinates (2, 0).   The figure below shows the answer for the second sample. In this sample the best decision is to put the radar at point with coordinates (0, 0).

package main

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

var scanner *bufio.Scanner

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

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

  x0, y0, r := getF(), getF(), getF()
  x1, y1, s := getF(), getF(), getF()
  if r > s {
    r, s = s, r
  }
  d := math.Sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0))
  var gap float64
  if d + r <= s {
    gap = s - d - r
  } else if d > r + s {
    gap = d - r - s
  }
  writer.WriteString(fmt.Sprintf("%.8f\n", gap / 2))
}

package main

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

var scanner *bufio.Scanner

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

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

  a, b, r := getInt(), getInt(), getInt()
  c, d, s := getInt(), getInt(), getInt()
  gap := math.Sqrt(float64((a-c)*(a-c) + (b-d)*(b-d))) - float64(r+s)
  if gap < 0 {
    gap = 0
  }
  writer.WriteString(fmt.Sprintf("%.8f\n", gap/2))
}


Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd.

The only line contains odd integer n (1 ≤ n ≤ 49).

Print n lines with n integers. All the integers should be different and from 1 to n2. The sum in each row, column and both main diagonals should be odd.

package main

import "bufio"
import "strconv"
import "os"

var in *bufio.Scanner
var out *bufio.Writer

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

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

	in.Scan()
	n, _ := strconv.Atoi(in.Text())

	a := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, n)
		for j := 0; j < n; j++ {
			a[i][j] = 0
		}
	}

	tot := n * n
	cntOdd := (tot + 1) / 2

	odd := 1
	delta := 2

	k := n / 2
	for i := 0; i < n; i++ {
		a[i][k] = odd
		odd += delta
		cntOdd--
		if k != i {
			a[k][i] = odd
			odd += delta
			cntOdd--
		}
	}

	for cntOdd >= 4 {
		found := false
		for i := 0; i < k; i++ {
			for j := 0; j < k; j++ {
				if (a[i][j] == 0) && (a[n-1-i][j] == 0) &&
					(a[i][n-1-j] == 0) && (a[n-1-i][n-1-j] == 0) {
					found = true

					a[i][j] = odd
					odd += delta
					cntOdd--

					a[n-1-i][j] = odd
					odd += delta
					cntOdd--

					a[i][n-1-j] = odd
					odd += delta
					cntOdd--

					a[n-1-i][n-1-j] = odd
					odd += delta
					cntOdd--

					break
				}
			}
			if found {
				break
			}
		}
	}

	even := 0
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if a[i][j] == 0 {
				even += delta
				a[i][j] = even
			}
			out.WriteString(strconv.Itoa(a[i][j]))
			out.WriteByte(' ')
		}
		out.WriteByte('\n')
	}

}

package main

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

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

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

	n := nextInt()
	odd, even := 1, 2

	matrix, odd, even := makeHalfMatrix(n, odd, even)

	for i := range matrix {
		printLine(matrix[i])
	}

	midLine, odd := makeMidLine(n, odd)

	printLine(midLine)

	matrix, odd, even = makeHalfMatrix(n, odd, even)

	for i := range matrix {
		printLine(matrix[len(matrix)-i-1])
	}
}

func makeHalfMatrix(n, odd, even int) ([][]int, int, int) {
	var matrix [][]int
	half := n / 2
	remainEven := (n * n) / 4

	for i := 0; i < half; i++ {
		line := make([]int, n)

		line[half] = odd
		odd += 2
		// println(line)
		for j := 0; j < half; j++ {
			if remainEven > 0 {
				line[j] = even
				even += 2
				line[n-j-1] = even
				even += 2
				// println(line)
			} else {
				line[j] = odd
				odd += 2
				line[n-j-1] = odd
				odd += 2
			}
			// println(remainEven)
			remainEven -= 2
		}

		matrix = append(matrix, line)
	}

	return matrix, odd, even
}

func makeMidLine(n, odd int) ([]int, int) {
	line := make([]int, n)

	for i := range line {
		line[i] = odd
		odd += 2
	}

	return line, odd
}

func printLine(a []int) {
	for i := range a {
		print(a[i])

		if i == len(a)-1 {
			println()
		} else {
			print(" ")
		}
	}
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

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

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }


Recently, the students of School 179 have developed a unique algorithm, which takes in a binary string $$$s$$$ as input. However, they soon found out that if some substring $$$t$$$ of $$$s$$$ is a palindrome of length greater than 1, the algorithm will work incorrectly. Can the students somehow reorder the characters of $$$s$$$ so that the algorithm will work correctly on the string?A binary string is a string where each character is either 0 or 1.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.A palindrome is a string that reads the same backwards as forwards.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the length of the string $$$s$$$. The second line of each test case contains the string $$$s$$$ of length $$$n$$$ consisting only of the characters 0 and 1.

For each test case, print YES (case-insensitive) if it is possible to reorder the characters of $$$s$$$ so that there are no substrings that are a palindrome of length greater than 1, or NO (case-insensitive) otherwise.

NoteIn the first three test cases, the given strings do not contain palindromes of length greater than 1, so the answers are YES.In the last test case, it is impossible to reorder the characters so that the string does not contain palindromes of length greater than 1, so the answer is NO.

package main

import (
	"fmt"
)

func main() {

	var size int
	fmt.Scanln(&size)
	for index := size; index > 0; index-- {
		var n int
		fmt.Scanln(&n)

		var si string
		fmt.Scanln(&si)

		if n == 1 {
			fmt.Printf("YES \n")
		} else {
			s := []rune(si)

			if n > 2 || s[0] == s[1] {
				fmt.Printf("NO \n")
			} else {
				fmt.Printf("YES \n")
			}

		}

	}
}

package main

import (
	"fmt"
)

func main() {

	var size int
	fmt.Scanln(&size)
	for index := size; index > 0; index-- {
		var n int
		fmt.Scanln(&n)

		var s string
		fmt.Scanln(&s)

		if n == 1 {
			fmt.Printf("YES \n")
		} else {

			if n > 2 || s == "11" || s == "00" {
				fmt.Printf("NO \n")
			} else {
				fmt.Printf("YES \n")
			}

		}

	}
}

package main

import (
	"fmt"
)

func main() {

	var size int
	fmt.Scanln(&size)
	for index := size; index > 0; index-- {
		var n int
		fmt.Scanln(&n)

		var si string
		fmt.Scanln(&si)

		if n == 1 {
			fmt.Printf("YES \n")
		} else {
			s := []rune(si)

			if n > 2 || (s[0] == '1' && s[1] == '1') || (s[0] == '0' && s[1] == '0') {
				fmt.Printf("NO \n")
			} else {
				fmt.Printf("YES \n")
			}

		}

	}
}

package main

import (
	"fmt"
)

func main() {

	var size int
	fmt.Scanln(&size)
	for index := size; index > 0; index-- {
		var n int
		fmt.Scanln(&n)

		var s string
		fmt.Scanln(&s)

		// Why use a standard library to print when we can jam bytes down a buffer?
		if n > 2 || s == "11" || s == "00" {
			fmt.Printf("NO \n")
		} else {
			fmt.Printf("YES \n")
		}

	}
}

package main

import (
	"fmt"
)

func main() {

	var size int
	fmt.Scanln(&size)
	for index := size; index > 0; index-- {
		var n int
		fmt.Scanln(&n)

		var s string
		fmt.Scanln(&s)

		// Why use a standard library to print when we can jam bytes down a buffer?
		//buf := bufio.NewWriter(os.Stdout)
		//defer buf.Flush()
		if n > 2 || s == "11" || s == "00" {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}

	}
}

package main

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

func solve(r *bufio.Reader) {
	var n int64
	var s string
	fmt.Fscan(r, &n, &s)
	if len(s) > 2 || s == "11" || s == "00" {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		solve(r)
	}
}

package main

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

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

	round := 0
	length := 0
	Fscan(in, &round)

	for i := 1; i <= round; i++ {
		Fscan(in, &length)
		bitSequence := ""
		Fscan(in, &bitSequence)
		if length > 2 {
			Fprintln(out, "NO")
		} else if length <= 1 {
			Fprintln(out, "YES")
		} else {
			if bitSequence[0] != bitSequence[1] {
				Fprintln(out, "YES")
			} else {
				Fprintln(out, "NO")
			}
		}
	}
}
func main() { helper(os.Stdin, os.Stdout) }

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var n int
	fmt.Sscanf(scanner.Text(), "%d", &n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		scanner.Scan()
		var s string
		s = strings.TrimSpace(scanner.Text())
		if s == "0" || s == "1" || s == "01" || s == "10" {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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
		fmt.Fscan(in, &n)

		var s string
		fmt.Fscan(in, &s)

		if s == "1" || s == "0" || s == "10" || s == "01" {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "strings"
)
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
		fmt.Fscan(in,&n)
		var binary string
		fmt.Fscan(in,&binary)
		for j:=0;j<4;j++{
			if strings.Contains(binary, "000") == true || strings.Contains(binary, "111") == true || strings.Contains(binary, "101") == true || strings.Contains(binary, "010") == true || strings.Contains(binary, "00") == true || strings.Contains(binary, "11") == true {
				fmt.Fprintln(out,"NO")
				goto out
			}
		}
		fmt.Fprintln(out,"YES")
		out:
	}
}

package main

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

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

func (in *CF1632A) 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 *CF1632A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1632A
Date: 6/02/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1632/A
Problem: CF1632A
**/
func (in *CF1632A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		str := in.NextString()
		zeros := 0
		for i := 0; i < n; i++ {
			if str[i] == '0' {
				zeros++
			}
		}
		ones := n - zeros
		if (ones == 1 && zeros == 1) || (ones == 1 && zeros == 0) || (zeros == 1 && ones == 0) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

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

package main

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

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

func scan(a ...interface{}) {
	_, err := fmt.Fscan(in, a...)
	if err != nil {
		return
	}
}

func printf(format string, a ...interface{}) {
	_, err := fmt.Fprintf(out, format, a...)
	if err != nil {
		return
	}
}

func flush() {
	err := out.Flush()
	if err != nil {
		return
	}
}

func solve() {
	var (
		n int
		s string
	)
	scan(&n, &s)

	if n == 1 || n == 2 && s[0] != s[1] {
		printf("YES\n")
	} else {
		printf("NO\n")
	}
}

func main() {
	var testNum int
	scan(&testNum)
	for ; testNum > 0; testNum-- {
		solve()
	}

	flush()
}

package main

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

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

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

func solve(in *bufio.Reader) string {
	n := readInt(in)
	s, _ := in.ReadString('\n')
	if n == 1 {
		return "YES\n"
	} else if n == 2 && s[0] != s[1] {
		return "YES\n"
	} else {
		return "NO\n"
	}
}

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

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

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

// generated by 1e9y at 30-01-2022
// template version: 2022-01-11

package main

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

// 0000.A
func solve(n int, s string) bool {
	if n > 2 {
		return false
	}
	if s == "11" || s == "00" {
		return false
	}
	return true
}

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

	t := ReadInt(in)
	for i := 0; i < t; i++ {
		n := ReadInt(in)
		s := ReadLine(in)
		Output(solve(n, s))
	}
}

// helpers for convenient input reading

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

func ReadLine(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	return line
}

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

func ReadIntSlice(in *bufio.Reader) []int {
	parts := ReadLineParts(in)
	slice := make([]int, len(parts))
	for i, n := range parts {
		slice[i] = MustAtoi(n)
	}
	return slice
}

func ReadInt64Slice(in *bufio.Reader) []int64 {
	parts := ReadLineParts(in)
	slice := make([]int64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseInt(n, 10, 64)
	}
	return slice
}

func ReadUint64Slice(in *bufio.Reader) []uint64 {
	parts := ReadLineParts(in)
	slice := make([]uint64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseUint(n, 10, 64)
	}
	return slice
}

func MustAtoi(s string) int {
	v, _ := strconv.Atoi(s)
	return v
}

func MustParseInt(s string, base, bitSize int) int64 {
	v, _ := strconv.ParseInt(s, base, bitSize)
	return v
}

func MustParseUint(s string, base, bitSize int) uint64 {
	v, _ := strconv.ParseUint(s, base, bitSize)
	return v
}

func SkipLine(in *bufio.Reader) {
	_, _ = in.ReadString('\n')
}

// helper for convenient answer output

func Output(v interface{}) {
	switch v.(type) {
	case bool:
		if v == true {
			Println("YES")
		} else {
			Println("NO")
		}
	default:
		Println(v)
	}
}

package main

import (
	"fmt"
)

func main() {

  n := 0
  fmt.Scan(&n)
  t := 0
  p := ""
  for i := 0; i <n ; i ++{
    fmt.Scan(&t)
    fmt.Scan(&p)
    if t == 1 {
      fmt.Println("YES")
    }else if t == 2 {
      if p[0] != p[1]{
        fmt.Println("YES")
      }else{
        fmt.Println("NO")
      }
    }else {
      fmt.Println("NO")
    }
  }
}

//nolint
package main

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

//{
var reader = bufio.NewReader(os.Stdin)
var 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 println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

//}

func Solve() {
	var n int
	var st string
	scan(&n)
	scan(&st)
	if n == 1 {
		println("YES")
	} else if n == 2 {
		if st == "01" || st == "10" {
			println("YES")
		} else {
			println("NO")
		}
	} else {
		println("NO")
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, s := 0, 0, ""
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &s)
		if s == "0" || s == "1" || s == "10" || s == "01" {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func main() {

	reader := bufio.NewReader(os.Stdin)
	writter := bufio.NewWriter(os.Stdout)
	defer writter.Flush()

	t := 0
	fmt.Fscan(reader, &t)

	for t > 0 {
		n := 0
		fmt.Fscan(reader, &n)

		s := ""
		fmt.Fscan(reader, &s)

		fmt.Fprintln(writter, solve(n, s))

		t--
	}

	// n := 2
	// s := "01"
	// fmt.Println(solve(n, s))

}

func solve(n int, s string) string {

	dp := make([][]int, n)
	for i := range dp {
		dp[i] = make([]int, n)
	}

	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			if i == j {
				dp[i][j] = 1
				continue
			}

			if i == j-1 {
				if s[j] == s[i] {
					return "NO"
				}
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if s[i] == s[j] {
				if dp[i+1][j-1] == 1 {
					return "NO"
				}
			}
		}
	}

	// printMatrix(dp)

	return "YES"
}

func arraySum(array []int) int {
	sum := 0

	for i := range array {
		sum += array[i]
	}

	return sum
}

func numSum(num int) int {
	sum := 0

	for i := num; i > 0; i-- {
		sum += i
	}

	return sum
}

func strToint(str string) int {
	num, _ := strconv.Atoi(str)
	return num
}

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

	return b
}

func getFactor(num int) []int {
	result := []int{}

	for i := 1; i <= int(math.Sqrt(float64(num))); i++ {
		if num%i == 0 {
			result = append(result, i)
			result = append(result, num/i)
		}
	}

	return result
}

func gcd(a, b int) int {
	if a == 0 {
		return b
	}

	return gcd(b%a, a)
}

func printMatrix(matrix [][]int) {

	for i := range matrix {

		for j := range matrix[i] {
			fmt.Printf("%d ", matrix[i][j])
		}

		fmt.Println()

	}

}

func checkPrime(num int) bool {

	if num < 2 {
		return false
	}

	for i := 2; i <= int(math.Sqrt(float64(num))); i++ {
		if num%i == 0 {
			return false
		}
	}

	return true
}

package main

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

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

func main() {
	var tt int
	fmt.Fscanf(in, "%d\n", &tt)
	for t := 0; t < tt; t++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)
		var s string
		fmt.Fscanf(in, "%s\n", &s)
		// fmt.Fprintln(os.Stderr, s)
		if n == 1 {
			fmt.Fprintf(out, "YES\n")
			continue
		}
		if n > 2 {
			fmt.Fprintf(out, "NO\n")
			continue
		}
		if s == "01" || s == "10" {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
	defer out.Flush()

}

package main

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

/*
4
5
01011
5
01010
4
1001
1
1
---
NO
NO
NO
BO
*/

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

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

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

		if n == 1 {
			fmt.Fprintln(writer, "YES")
			continue
		}

		if n == 2 && s[0] != s[1] {
			fmt.Fprintln(writer, "YES")
			continue
		}

		fmt.Fprintln(writer, "NO")
	}
}

const maxUint = ^uint(0)

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

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

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

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(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

//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
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }
func assert(f bool) {
	if !f {
		panic("gg")
	}
}

// ----------------------------- TEMPLATE END ----------------------------------

func main() {
	defer flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		var n int
		scan(&n)
		var s string
		scan(&s)
		if n > 2 {
			printf("NO\n")
		} else if s == "00" || s == "11" {
			printf("NO\n")
		} else {
			printf("YES\n")
		}
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {

	var size int
	fmt.Scanln(&size)
	for index := size; index > 0; index-- {
		var n int
		fmt.Scanln(&n)

		var si string
		fmt.Scanln(&si)

		if n == 1 {
			fmt.Printf("YES \n")
		} else {
			s := []rune(si)

			if n > 2 || (s[0] == '1' && s[1] == '1') || (s[0] == '0' && s[1] == '0') {
				fmt.Fprintf(os.Stderr, "NO \n")
			} else {
				fmt.Fprintf(os.Stderr, "YES \n")
			}

		}

	}
}

package main

import (
	"fmt"
)

func main() {

	var size int
	fmt.Scanln(&size)
	for index := size; index > 0; index-- {
		var n int
		fmt.Scanln(&n)

		var si string
		fmt.Scanln(&si)

		if n == 1 {
			fmt.Printf("YES \n")
		} else {
			s := []rune(si)

			if s[0] == s[1] {
				fmt.Printf("NO \n")
			} else {
				fmt.Printf("YES \n")
			}

		}

	}
}

package main

import (
	"fmt"
)

func main() {

	var size int
	fmt.Scanln(&size)
	for index := size; index > 0; index-- {
		var n int
		fmt.Scanln(&n)

		var s string
		fmt.Scanln(&s)

		// Why use a standard library to print when we can jam bytes down a buffer?
		if n > 2 || s == "11" || s == "00" {
			fmt.Printf("NO")
		} else {
			fmt.Printf("YES")
		}

	}
}

package main

import (
	"fmt"
)

func main() {

	var size int
	fmt.Scanln(&size)
	for index := size; index > 0; index-- {
		var n int
		fmt.Scanln(&n)

		var s string
		fmt.Scanln(&s)

		// Why use a standard library to print when we can jam bytes down a buffer?

		if n > 2 || s == "11" || s == "00" {
			go fmt.Printf("NO")
		} else {
			go fmt.Println("YES")
		}

	}
}

package main

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

func main() {

	var size int
	fmt.Scanln(&size)
	for index := size; index > 0; index-- {
		var n int
		fmt.Scanln(&n)

		var s string
		fmt.Scanln(&s)

		// Why use a standard library to print when we can jam bytes down a buffer?
		buf := bufio.NewWriter(os.Stdout)
		defer buf.Flush()
		if n > 2 || s == "11" || s == "00" {
			go fmt.Printf("NO \n")
		} else {
			go fmt.Printf("YES \n")
		}

	}
}

package main

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

func main() {

	var size int
	fmt.Scanln(&size)
	for index := size; index > 0; index-- {
		var n int
		fmt.Scanln(&n)

		var s string
		fmt.Scanln(&s)

		// Why use a standard library to print when we can jam bytes down a buffer?
		buf := bufio.NewWriter(os.Stdout)
		defer buf.Flush()
		if n > 2 || s == "11" || s == "00" {
			go fmt.Printf("NO")
		} else {
			go fmt.Printf("YES")
		}

	}
}

package main

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

func main() {

	var size int
	fmt.Scanln(&size)
	for index := size; index > 0; index-- {
		var n int
		fmt.Scanln(&n)

		var s string
		fmt.Scanln(&s)

		// Why use a standard library to print when we can jam bytes down a buffer?
		buf := bufio.NewWriter(os.Stdout)
		defer buf.Flush()
		if n > 2 || s == "11" || s == "00" {
			os.Stderr.WriteString("NO \n")
		} else {
			os.Stderr.WriteString("YES \n")
		}

	}
}

package main

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

func solve(r *bufio.Reader) {
	var n int64
	var s string
	fmt.Fscan(r, &n, &s)
	if len(s) > 3 || s == "11" || s == "00" || s == "111" || s == "000" {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		solve(r)
	}
}

package main

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

func Reverse(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}
func solve(r *bufio.Reader) {
	var n int64
	var s string
	fmt.Fscan(r, &n, &s)
	s2 := strconv.FormatInt(n, 2)
	if s2 == s || Reverse(s2) == s {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		solve(r)
	}
}

package main

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

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

	round := 0
	length := 0
	Fscan(in, &round)

	for i := 1; i <= round; i++ {
		Fscan(in, &length)
		bitSequence := make([]int, length)
		for j := 1; j <= length; j++ {
			Fscan(in, &bitSequence[j-1])
		}
		if length > 2 {
			Fprintln(out, "NO")
		} else if length <= 1 {
			Fprintln(out, "YES")
		} else {
			if bitSequence[0] != bitSequence[1] {
				Fprintln(out, "YES")
			} else {
				Fprintln(out, "NO")
			}
		}
	}
}
func main() { helper(os.Stdin, os.Stdout) }

package main

import (
	"fmt"
	"strings"
)

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

	for i := 0; i < n; i++ {
		var dummy int
		fmt.Scanf("%d", &dummy)
		var s string
		fmt.Scanf("%s", &s)
		s = strings.TrimSpace(s)
		if s == "0" || s == "1" || s == "01" || s == "10" {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		var dummy int
		var s string
		fmt.Scanf("%d", &dummy)
		fmt.Scanf("%s", &s)
		if s == "0" || s == "1" || s == "01" || s == "10" {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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
		fmt.Fscan(in, &n)

		var s string
		fmt.Fscan(in, &s)

		if n > 2 {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

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
		fmt.Fscan(in, &n)

		var s string
		fmt.Fscan(in, &s)

		count := make([]int, 2)
		for _, ch := range s {
			if ch == '0' {
				count[0]++
			} else {
				count[1]++
			}
		}

		if n > 2 && (count[0] == n/2 || count[1] == n/2) {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "strings"
)
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
		fmt.Fscan(in,&n)
		var binary string
		fmt.Fscan(in,&binary)
		for j:=0;j<4;j++{
			if strings.Contains(binary, "000") == true || strings.Contains(binary, "111") == true || strings.Contains(binary, "101") == true || strings.Contains(binary, "010") == true {
				fmt.Fprintln(out,"NO")
				goto out
			}
		}
		fmt.Fprintln(out,"YES")
		out:
	}
}

package main

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

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

func (in *CF1632A) 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 *CF1632A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1632A
Date: 6/02/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1632/A
Problem: CF1632A
**/
func (in *CF1632A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		str := in.NextString()
		zeros := 0
		for i := 0; i < n; i++ {
			if str[i] == '0' {
				zeros++
			}
		}
		ones := n - zeros
		if ones%2 != 0 && zeros%2 != 0 || (ones%2 != 0 && zeros == 0) || (ones == 0 && zeros%2 != 0) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

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

package main

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

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

func scan(a ...interface{}) {
	_, err := fmt.Fscan(in, a)
	if err != nil {
		return
	}
}

func printf(format string, a ...interface{}) {
	_, err := fmt.Fprintf(out, format, a)
	if err != nil {
		return
	}
}

func flush() {
	err := out.Flush()
	if err != nil {
		return
	}
}

func solve() {
	var (
		n int
		s string
	)
	scan(&n, &s)

	if n == 1 || n == 2 && s[0] != s[1] {
		printf("YES")
	} else {
		printf("NO")
	}
}

func main() {
	var testNum int
	scan(testNum)
	for ; testNum > 0; testNum-- {
		solve()
	}

	flush()
}

// generated by 1e9y at 30-01-2022
// template version: 2022-01-11

package main

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

// 0000.A
func solve(n int, s string) bool {
	if n > 2 {
		return false
	}
	return true
}

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

	t := ReadInt(in)
	for i := 0; i < t; i++ {
		n := ReadInt(in)
		s := ReadLine(in)
		Output(solve(n, s))
	}
}

// helpers for convenient input reading

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

func ReadLine(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	return line
}

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

func ReadIntSlice(in *bufio.Reader) []int {
	parts := ReadLineParts(in)
	slice := make([]int, len(parts))
	for i, n := range parts {
		slice[i] = MustAtoi(n)
	}
	return slice
}

func ReadInt64Slice(in *bufio.Reader) []int64 {
	parts := ReadLineParts(in)
	slice := make([]int64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseInt(n, 10, 64)
	}
	return slice
}

func ReadUint64Slice(in *bufio.Reader) []uint64 {
	parts := ReadLineParts(in)
	slice := make([]uint64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseUint(n, 10, 64)
	}
	return slice
}

func MustAtoi(s string) int {
	v, _ := strconv.Atoi(s)
	return v
}

func MustParseInt(s string, base, bitSize int) int64 {
	v, _ := strconv.ParseInt(s, base, bitSize)
	return v
}

func MustParseUint(s string, base, bitSize int) uint64 {
	v, _ := strconv.ParseUint(s, base, bitSize)
	return v
}

func SkipLine(in *bufio.Reader) {
	_, _ = in.ReadString('\n')
}

// helper for convenient answer output

func Output(v interface{}) {
	switch v.(type) {
	case bool:
		if v == true {
			Println("YES")
		} else {
			Println("NO")
		}
	default:
		Println(v)
	}
}


Arkady invited Anna for a dinner to a sushi restaurant. The restaurant is a bit unusual: it offers $$$n$$$ pieces of sushi aligned in a row, and a customer has to choose a continuous subsegment of these sushi to buy.The pieces of sushi are of two types: either with tuna or with eel. Let's denote the type of the $$$i$$$-th from the left sushi as $$$t_i$$$, where $$$t_i = 1$$$ means it is with tuna, and $$$t_i = 2$$$ means it is with eel.Arkady does not like tuna, Anna does not like eel. Arkady wants to choose such a continuous subsegment of sushi that it has equal number of sushi of each type and each half of the subsegment has only sushi of one type. For example, subsegment $$$[2, 2, 2, 1, 1, 1]$$$ is valid, but subsegment $$$[1, 2, 1, 2, 1, 2]$$$ is not, because both halves contain both types of sushi.Find the length of the longest continuous subsegment of sushi Arkady can buy.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 100\,000$$$) — the number of pieces of sushi. The second line contains $$$n$$$ integers $$$t_1$$$, $$$t_2$$$, ..., $$$t_n$$$ ($$$t_i = 1$$$, denoting a sushi with tuna or $$$t_i = 2$$$, denoting a sushi with eel), representing the types of sushi from left to right. It is guaranteed that there is at least one piece of sushi of each type. Note that it means that there is at least one valid continuous segment.

Print a single integer — the maximum length of a valid continuous segment.

NoteIn the first example Arkady can choose the subsegment $$$[2, 2, 1, 1]$$$ or the subsegment $$$[1, 1, 2, 2]$$$ with length $$$4$$$.In the second example there is no way but to choose one of the subsegments $$$[2, 1]$$$ or $$$[1, 2]$$$ with length $$$2$$$.In the third example Arkady's best choice is the subsegment $$$[1, 1, 1, 2, 2, 2]$$$.

package main

import (
	"fmt"
)

func main() {
	var n, cnt, last int64
	// scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Scanln(&n)

	a := make([]int64, n)
	sus := make(map[int64]int64)

	for i := int64(0); i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	for i := int64(0); i < n; i++ {
		if i == 0 {
			last = a[i]
			sus[a[i]]++
		} else {
			if a[i] == last {
				sus[a[i]]++
			} else {
				if len(sus) == 2 {
					if sus[2] >= sus[1] {
						if cnt < 2*sus[1] {
							cnt = 2 * sus[1]
						}
					} else {
						if cnt < 2*sus[2] {
							cnt = 2 * sus[2]
						}
					}
					if last == 1 {
						delete(sus, 2)
					} else {
						delete(sus, 1)
					}
				}
				sus[a[i]]++
				last = a[i]
			}
		}
		if i == n-1 {
			if sus[2] >= sus[1] {
				if cnt < 2*sus[1] {
					cnt = 2 * sus[1]
				}
			} else {
				if cnt < 2*sus[2] {
					cnt = 2 * sus[2]
				}
			}
		}
	}

	fmt.Println(cnt)

}

package main

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

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

	var n int
	fmt.Fscanf(buf, "%d\n", &n)
	mat := make([]int,n)
	for i:=0;i < n;i++{
		fmt.Fscanf(buf, "%d", &mat[i])
	}
	pre1:=0
	pre2:=0
	f:=0
	r:=0
	ans := 0
	tmp := 0
	for f < n{
		for r<n&&mat[r]==mat[f]{
			r++
		}
		tmp=0
		if mat[f] == 1{
			if pre2 < r-f{
				tmp = 2*pre2
			}else{
				tmp = 2*(r-f)
			}
			pre1=r-f
		}else{
			if pre1 < r-f{
				tmp = 2*pre1
			}else{
				tmp = 2*(r-f)
			}
			pre2=r-f
		}
		if tmp > ans{
			ans = tmp
		}
		f=r
	}
	fmt.Printf("%d\n",ans)

}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n + 2)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	c := 1
	b := make([]int, 0)
	for i := 1 ; i <= n; i++ {
		if a[i] == a[i - 1] {
			c++
		} else {
			b = append(b, c)
			c = 1
		}
	}
	ans := 0
	for i := 1; i < len(b); i++ {
		ans = max(ans, min(b[i],b[i - 1]))
	}

	fmt.Println(2*ans)
}

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

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

package main

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

func main()  {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n ,x int
	fmt.Fscan(in,&n)
	A := make([]int,0)
	for i := 0 ;i <n; i++{
		fmt.Fscan(in,&x)
		A = append(A,x)
	}
	left,right,save := 0,0,0
	ans := 0
	for i := 0 ;i < n;i++{
		if(A[i] == 1){
			if(i - 1 >= 0){
				if(A[i - 1] == 2){
					save = right;
					right = 0
				}
			}
			left ++
			ans = max1(min1(save,left)* 2,ans)
		}else{
				if(i - 1 >= 0){
					if(A[i - 1] == 1){
						save = left
						left = 0
					}
				}
				right++
				ans = max1(min1(save,right) * 2,ans)
		}
	}
	fmt.Fprint(out,ans)

}
func max1(x1,x2 int) int  {
	if(x1 < x2){
		return x2
	}
	return x1
}
func min1(x1,x2 int) int  {
	if(x1 < x2){
		return x1
	}else{
		return x2
	}
}

package main

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

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

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

func getLine() string {
	s, _ := reader.ReadString('\n')
	if strings.HasSuffix(s, "\r\n") {
		s = s[:len(s)-2]
	} else if strings.HasSuffix(s, "\n") {
		s = s[:len(s)-1]
	}
	return s
}
func getLine2Int() (n int) {
	scanf("%d\n", &n)
	return
}
func getLine2Int2() (a, b int) {
	scanf("%d %d\n", &a, &b)
	return
}
func getLine2Ints(n int) []int {
	ans := make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d ", &ans[i])
	}
	scanf("%d\n", &ans[n-1])
	return ans
}

func pcheck(i bool) {
	if i {
		printf("YES\n")
	} else {
		printf("NO\n")
	}
}

var debug = true

func see(a interface{}) {
	if debug {
		printf("DEBUG:%v\n", a)
	}
}

func ss(p1, p2, max int) int {
	if p1 > p2 {
		p1 = p2
	}
	if p1 > max {
		max = p1
	}
	return max
}

func main() {
	defer writer.Flush()

	n := getLine2Int()
	in := getLine2Ints(n)

	var p1, p2, max, status int
	for i := 0; i < n; i++ {
		switch status {
		case 0: // see p1
			if in[i] == 1 {
				p1++
			} else {
				max = ss(p1, p2, max)
				p2 = 1
				status = 1
			}
		case 1:
			if in[i] == 2 {
				p2++
			} else {
				max = ss(p1, p2, max)
				p1 = 1
				status = 0
			}
		}
	}
	max = ss(p1, p2, max)
	printf("%d\n", max*2)
}

package main

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

func main() {
	n := readInt()
	input := make([]int, 0, 10)
	gao := make([]int, 0, 10)
	for i := 0; i < n; i++ {
		input = append(input, readInt())
	}
	gao = append(gao, 1)
	top := 0
	pre := input[0]
	for i := 1; i < len(input); i++ {
		if input[i] == pre {
			gao[top]++
		} else {
			top++
			gao = append(gao, 1)
			pre = input[i]
		}
	}
	// ans := gao[0 : top+1]
	// fmt.Println("ans:", ans)
	maxn := -1
	prei, nexti := 0, 1
	for ; nexti < top+1; prei, nexti = prei+1, nexti+1 {
		// fmt.Println(gao[prei], gao[nexti])
		x := min(gao[prei], gao[nexti])
		maxn = max(maxn, 2*x)
	}
	fmt.Println(maxn)
}

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
}

var reader = bufio.NewReader(os.Stdin)

func readInt() int {
	var ch byte
	var err error
	for {
		ch, err = reader.ReadByte()
		if err != nil {
			return 0
		}
		if unicode.IsDigit(rune(ch)) {
			break
		}
	}
	result := int(ch & 0xf)
	for {
		ch, err = reader.ReadByte()
		if err != nil || !unicode.IsDigit(rune(ch)) {
			return result
		}
		result = result*10 + int(ch&0xf)
	}
}

package main

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

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

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

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

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

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

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

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

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

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

func main() {
	defer Flush()

	n := readi()
	t := make([]int, n)
	for i := range t {
		t[i] = readi() - 1
	}
	var a [2]int
	var ans int
	a[t[0]]++
	for i := 1; i < n; i++ {
		v := t[i]
		if t[i-1] != t[i] {
			a[v] = 0
		}
		a[v]++
		ans = max(ans, min(a[0], a[1])*2)
	}
	println(ans)
}

package main

import (
	"fmt"
)

func maxx(x int, y int) int {
	if x < y {
		return y
	}
	return x
}

func minn(x int, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	var a int64
	fmt.Scanf("%d\n", &a)
	var b []int
	var i int64 = 0
	for i < a {
		var m int
		fmt.Scanf("%d", &m)
		b = append(b, m)
		i++
	}
	cnt := 1
	var arr []int
	for j := 1; j < len(b); j++ {
		if b[j] != b[j-1] {
			arr = append(arr, cnt)
			cnt = 1
		} else {
			cnt += 1
		}
	}
	arr = append(arr, cnt)
	ans := 0
	if len(arr) > 1{
		for j := 0; j < len(arr)-1; j++ {
			ans = maxx(ans, 2*minn(arr[j], arr[j+1]))
		}
	}
	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 max(i, j int64) int64 {
	if i > j {
		return i
	}
	return j
}

func min(i, j int64) int64 {
	if i < j {
		return i
	}
	return j
}

func main() {
	defer writer.Flush()
    var prev, prevCount, currCount, maxSoFar int64
    prev, prevCount, currCount, maxSoFar = 0, 0, 0, 0
	var n, i int64
	scanf("%d\n", &n)
	for ; n > 0; n-- {
		scanf("%d", &i)
		if i != prev {
			prev = i
            maxSoFar = max(maxSoFar, min(currCount, prevCount))
			prevCount = currCount
			currCount = 1
		} else {
            currCount++
        }
	}
    maxSoFar = max(maxSoFar, min(currCount, prevCount))
	printf("%d", maxSoFar*2)
}

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 max(i, j int64) int64 {
	if i > j {
		return i
	}
	return j
}

func min(i, j int64) int64 {
	if i < j {
		return i
	}
	return j
}

func main() {
	defer writer.Flush()
	var n, i int64
	scanf("%d\n", &n)
	prev := int64(0)
	prevCount := int64(0)
	currCount := int64(0)
	maxSoFar := int64(0)
	for ; n > 0; n-- {
		scanf("%d", &i)
		if i != prev {
			prev = i
			prevCount = currCount
			currCount = 1
		} else {
            currCount++
        }
        maxSoFar = max(maxSoFar, min(currCount, prevCount))
	}
	printf("%d", maxSoFar*2)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	c := 1
	b := make([]int, 0)
	for i :=1 ; i < n; i++ {
		if a[i] == a[i - 1] {
			c++
		} else {
			b = append(b, c)
			c = 1
		}
	}
	if c > 1 {
		b = append(b, c)
	}
	ans := 0
	for i := 1; i < len(b); i++ {
		ans = max(ans, min(b[i],b[i - 1]))
	}

	fmt.Println(2*ans)
}

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

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

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	c := 1
	b := make([]int, 0)
	for i :=1 ; i < n; i++ {
		if a[i] == a[i - 1] {
			c++
		} else {
			b = append(b, c)
			c = 1
		}
	}
	if c > 1 {
		b = append(b, c)
	}
	ans := b[0]
	for i := 1; i < len(b); i++ {
		ans = max(ans, min(b[i],b[i - 1]))
	}

	fmt.Println(2*ans)
}

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

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

package main

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

func main()  {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n ,x int
	fmt.Fscan(in,&n)
	A := make([]int,0)
	L := make([]int,n + 1)
	R := make([]int,n + 1)
	cnt := 0
	for i := 0 ;i < n;i ++{
			fmt.Fscan(in,&x)
			A = append(A,x)
			if(x == 2){
				cnt ++
				L[i] = cnt
			}else{
				if(i - 1 >= 0){
					L[i] = L[i - 1]
				}
				cnt = 0
			}
	}
	cnt = 0
	for i := n -1 ;i >= 0;i--{
		if(A[i] == 2){
			cnt ++
			R[i] = cnt
		}else{
			R[i] = R[i + 1]
			cnt = 0
		}
	}
	ans := 0
	tmp := 0
	for i := 0 ; i < n; i++{
		if(A[i] == 1){
			tmp++
			ans = max1(max1(min1(L[i],tmp)* 2,min1(R[i],tmp)* 2),ans)
		}
	}
	fmt.Fprint(out,ans)

}
func min1(x1,x2 int) int  {
	if(x1 < x2){
		return x1
	}else{
		return x2
	}
}
func max1(x1,x2 int) int  {
		if(x1 < x2){
			return x2
		}
		return x1
}

package main

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

func main()  {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n ,x int
	fmt.Fscan(in,&n)
	A := make([]int,0)
	for i := 0 ;i <n; i++{
		fmt.Fscan(in,&x)
		A = append(A,x)
	}
	turn1,turn2,turn3 := 0,0,0
	ans := 0
	for i := 0 ;i < n;i ++{
		if(A[i] == 1){
			turn1++
			ans = max1(min1(turn1 + turn2,turn3)* 2,ans)
		}else{
				if(i -1 >= 0){
					if A[i - 1] == 1{
					turn3 = 0
					}
				}
				turn3++
				if(turn1 >= 1){
					turn2 = turn1
				}
				turn1 = 0
				ans = max1(min1(turn2,turn3)*2,ans)
		}
	}
	ans = max1(min1(turn1+turn2,turn3) * 2,ans)
	turn1 = 0
	turn2 = 0
	turn3 = 0
	for i := 0 ;i < n;i++{
		if(A[i] == 2){
			turn1 ++
			ans = max1(min1(turn1 + turn2,turn3)*2,ans)
		}else{
			if(i - 1 >= 0){
				if A[i] == 1{
					turn3 = 0
				}
			}
			turn3 ++
			if(turn1 >= 1){
				turn2 = turn1
			}
			turn1 = 0
			ans = max1(min1(turn2,turn3) * 2,ans)

		}
	}
	ans = max1(min1(turn1+turn2,turn3) * 2,ans)
	fmt.Fprint(out,ans)

}
func max1(x1,x2 int) int  {
	if(x1 < x2){
		return x2
	}
	return x1
}
func min1(x1,x2 int) int  {
	if(x1 < x2){
		return x1
	}else{
		return x2
	}
}

package main

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

func main()  {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n ,x int
	fmt.Fscan(in,&n)
	A := make([]int,0)
	L := make([]int,n + 1)
	R := make([]int,n + 1)
	cnt := 0
	for i := 0 ;i < n;i ++{
			fmt.Fscan(in,&x)
			A = append(A,x)
			if(x == 2){
				cnt ++
				L[i] = cnt
			}else{
				if(i - 1 >= 0){
					L[i] = L[i - 1]
				}
				cnt = 0
			}
	}
	cnt = 0
	for i := n -1 ;i >= 0;i--{
		if(A[i] == 2){
			cnt ++
			R[i] = cnt
		}else{
			R[i] = R[i + 1]
			cnt = 0
		}
	}
	ans := 0
	tmp := 0
	for i := 0 ; i < n; i++{
		if(A[i] == 1){
			tmp ++
			ans = max1(min1(L[i],tmp)* 2,min1(R[i],tmp)* 2)
		}else{
			ans = max1(min1(L[i],tmp)*2,min1(R[i],tmp) * 2)
		}
	}
	fmt.Fprint(out,ans)

}
func min1(x1,x2 int) int  {
	if(x1 < x2){
		return x1
	}else{
		return x2
	}
}
func max1(x1,x2 int) int  {
		if(x1 < x2){
			return x2
		}
		return x1
}

package main

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

func main()  {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n ,x int
	fmt.Fscan(in,&n)
	A := make([]int,0)
	L := make([]int,n + 1)
	R := make([]int,n + 1)
	cnt := 0
	for i := 0 ;i < n;i ++{
			fmt.Fscan(in,&x)
			A = append(A,x)
			if(x == 2){
				cnt ++
				L[i] = cnt
			}else{
				if(i - 1 >= 0){
					L[i] = L[i - 1]
				}
				cnt = 0
			}
	}
	cnt = 0
	for i := n -1 ;i >= 0;i--{
		if(A[i] == 2){
			cnt ++
			R[i] = cnt
		}else{
			R[i] = R[i + 1]
			cnt = 0
		}
	}
	ans := 0
	tmp := 0
	for i := 0 ; i < n; i++{
		if(A[i] == 1){
			tmp ++
			ans = max1(min1(L[i],tmp)* 2,min1(R[i],tmp)* 2)
		}
	}
	fmt.Fprint(out,ans)

}
func min1(x1,x2 int) int  {
	if(x1 < x2){
		return x1
	}else{
		return x2
	}
}
func max1(x1,x2 int) int  {
		if(x1 < x2){
			return x2
		}
		return x1
}

package main

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

func main()  {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n ,x int
	fmt.Fscan(in,&n)
	A := make([]int,0)
	L := make([]int,n + 1)
	R := make([]int,n + 1)
	cnt := 0
	for i := 0 ;i < n;i ++{
			fmt.Fscan(in,&x)
			A = append(A,x)
			if(x == 2){
				cnt ++
				L[i] = cnt
			}else{
				if(i - 1 >= 0){
					L[i] = L[i - 1]
				}
				cnt = 0
			}
	}
	cnt = 0
	for i := n -1 ;i >= 0;i--{
		if(A[i] == 2){
			cnt ++
			R[i] = cnt
		}else{
			R[i] = R[i + 1]
			cnt = 0
		}
	}
	ans := 0
	tmp := 0
	for i := 0 ; i < n; i++{
		if(A[i] == 1){
			tmp ++
			ans = max1(min1(L[i],tmp) + tmp,min1(R[i],tmp) + tmp)
		}else{
			tmp = 0
		}
	}
	fmt.Fprint(out,ans)

}
func min1(x1,x2 int) int  {
	if(x1 < x2){
		return x1
	}else{
		return x2
	}
}
func max1(x1,x2 int) int  {
		if(x1 < x2){
			return x2
		}
		return x1
}

package main

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

func main()  {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n ,x int
	fmt.Fscan(in,&n)
	A := make([]int,0)
	L := make([]int,n + 1)
	R := make([]int,n + 1)
	cnt := 0
	for i := 0 ;i < n;i ++{
			fmt.Fscan(in,&x)
			A = append(A,x)
			if(x == 2){
				cnt ++
				L[i] = cnt
			}else{
				if(i - 1 >= 0){
					L[i] = L[i - 1]
				}
				cnt = 0
			}
	}
	cnt = 0
	for i := n -1 ;i >= 0;i--{
		if(A[i] == 2){
			cnt ++
			R[i] = cnt
		}else{
			R[i] = R[i + 1]
			cnt = 0
		}
	}
	ans := 0
	tmp := 0
	for i := 0 ; i < n; i++{
		if(A[i] == 1){
			tmp ++
			ans = max1(min1(L[i],tmp)* 2,min1(R[i],tmp)* 2)
		}else{
			tmp = 0
		}
	}
	fmt.Fprint(out,ans)

}
func min1(x1,x2 int) int  {
	if(x1 < x2){
		return x1
	}else{
		return x2
	}
}
func max1(x1,x2 int) int  {
		if(x1 < x2){
			return x2
		}
		return x1
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sCount,_ := strconv.Atoi(sc.Text())
	sc.Scan()
	ss := strings.Split(sc.Text(), " ")
	var arr []int
	curI := 0
	curV := ""
	curS := 1
	max := 0
	for i := 0; i < sCount; i++ {
		if i == 0 {
			curV = ss[i]
			curS = 1
			continue
		}
		if ss[i] != curV {
			arr = append(arr, curS)
			curS = 1
			curV = ss[i]
			if curI > 0 && max < arr[curI] + arr[curI - 1] {
				max = arr[curI] + arr[curI - 1]
			}
			curI++
		} else {
			curS++
		}
	}
	fmt.Println(max)
}

package main

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

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sCount,_ := strconv.Atoi(sc.Text())
	sc.Scan()
	ss := strings.Split(sc.Text(), " ")
	var arr []int
	curI := 0
	curV := ""
	curS := 1
	max := 0
	for i := 0; i < sCount; i++ {
		if i == 0 {
			curV = ss[i]
			curS = 1
			continue
		}
		if ss[i] != curV || i == sCount - 1{
			arr = append(arr, curS)
			curS = 1
			curV = ss[i]
			if curI > 0 && max < arr[curI] + arr[curI - 1] {
				max = arr[curI] + arr[curI - 1] - abs(arr[curI], arr[curI-1])
			}
			curI++
		} else {
			curS++
		}
	}
	fmt.Println(max)
}

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 max(i, j int64) int64 {
    if i > j {
        return i
    }
    return j
}

func min(i, j int64) int64 {
    if i < j {
        return i
    }
    return j
}

func main() {
    defer writer.Flush()
    var n, i int64
    scanf("%d\n", &n)
    prev := int64(0)
    prevCount := int64(0)
    currCount := int64(0)
    maxSoFar := int64(0)
    for ; n > 0; n-- {
        scanf("%d", &i)
        if i != prev {
            prev = i
            prevCount = currCount
            currCount = 1
            maxSoFar = max(maxSoFar, min(currCount, prevCount))
            continue
        }
        currCount++
    }
    maxSoFar = max(maxSoFar, min(currCount, prevCount))
    printf("%d", maxSoFar*2)
}

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 max(i, j int64) int64 {
    if i > j {
        return i
    }
    return j
}

func min(i, j int64) int64 {
    if i < j {
        return i
    }
    return j
}

func main() {
    defer writer.Flush()
    var n, i int64
    scanf("%d\n", &n)
    prev := int64(0)
    prevCount := int64(0)
    currCount := int64(0)
    maxSoFar := int64(0)
    for ; n > 0; n-- {
        scanf("%d", &i)
        maxSoFar = max(maxSoFar, min(currCount, prevCount))
        if i != prev {
            prev = i
            prevCount = currCount
            currCount = 1
            continue
        }
        currCount++
    }
    printf("%d", maxSoFar*2)
}