package main

import (
	"fmt"
	"strings"
)

func f(s string) string {
	if strings.Count(s, "A")+strings.Count(s, "C") == strings.Count(s, "B") {
		return "YES"
	}
	return "NO"
}

func main() {
	var (
		t int
		s string
	)

	fmt.Scan(&t)
	for ; t > 0; t-- {
		fmt.Scan(&s)
		fmt.Println(f(s))
	}
}

package main

import "fmt"

func main() {
	var (
		n int
		s string
	)
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%s\n", &s)
		if len(s)%2 == 1 {
			fmt.Print("NO\n")
		} else {
			cntA, cntB, cntC := 0, 0, 0
			for i := range s {
				if s[i] == 'A' {
					cntA++
				} else if s[i] == 'B' {
					cntB++
				} else {
					cntC++
				}
			}
			if cntA+cntC != cntB {
				fmt.Print("NO\n")
			} else {
				fmt.Print("YES\n")
			}
		}
	}

}

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

		tally := make([]int, 3)
		for _, ch := range s {
			tally[ch-'A']++
		}

		if tally[0]+tally[2] == tally[1] {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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

	test := parseInt(getString(reader))

	for ; test > 0; test-- {
		occurence := make(map[rune]int)
		s := getString(reader)

		for _, v := range s {
			occurence[v]++
		}

		if occurence['A']+occurence['C'] == occurence['B'] {
			writer.WriteString("YES\n")
		} else {
			writer.WriteString("NO\n")
		}
	}
	writer.Flush()
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		s, A, B, C := "", 0, 0, 0
		fmt.Fscan(f, &s)
		for j := 0; j < len(s); j++ {
			switch {
			case string(s[j]) == "A":
				A++
			case string(s[j]) == "B":
				B++
			case string(s[j]) == "C":
				C++
			}
		}
		if B == A+C || (A == B && C == 0) || (B == C && A == 0) {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import "fmt"

func Answ(str string) string {
	counter := 0
	for _, let := range str {
		switch let {
		case 'A':
			counter--
		case 'B':
			counter++
		case 'C':
			counter--
		default:
			return "NO"
		}
	}

	if counter == 0 {
		return "YES"
	}
	return "NO"
}

func main() {
	var in_count int
	fmt.Scan(&in_count)

	for i := 0; i < in_count; i++ {
		var tmp_str string

		fmt.Scan(&tmp_str)
		fmt.Println(Answ(tmp_str))
	}
}

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

package main

import "fmt"

func main() {
	var lengthOfArray int
	var element string

	inputArray := make([]string, 0)

	// taking the input array's length
	fmt.Scanln(&lengthOfArray)

	// taking the input array
	for i := 0; i < lengthOfArray; i++ {
		fmt.Scanln(&element)
		inputArray = append(inputArray, element)
	}

	for _, ele := range inputArray {
		checkValidity(ele)
	}

}

func checkValidity(ele string) {

	chars := make(map[rune]int)
	for _, char := range ele {
		chars[char] = chars[char] + 1
	}

	if (chars['A'] + chars['C']) == chars['B'] {
		fmt.Println("YES")
		return
	}

	fmt.Println("NO")
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	// writer  = bufio.NewWriter(os.Stdout)
	t int
	s string
)

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		var a, b, c int
		fmt.Fscan(reader, &s)
		for _, char := range s {
			if char == 'A' {
				a++
			}
			if char == 'B' {
				b++
			}
			if char == 'C' {
				c++
			}
		}
		if a+c == b {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func main() {
	var T int
	fmt.Scanf("%d\n", &T)
	for ; T > 0; T-- {
		var str string
		fmt.Scanf("%s\n", &str)

		a, b, c := 0, 0, 0
		for _, ch := range str {
			if ch == 'A' {
				a++
			} else if ch == 'B' {
				b++
			} else {
				c++
			}
		}

		if b-a == c {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		var s string
		bCount := 0
		acCount := 0

		fmt.Scan(&s)

		bCount += strings.Count(s, "B")
		acCount += strings.Count(s, "A")
		acCount += strings.Count(s, "C")

		if bCount == acCount {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}
func solve() {
	var str string
	fmt.Scan(&str)
	arr := [3]rune{}
	for _, v := range str {
		if v == 'A' {
			arr[0]++
		} else if v == 'B' {
			arr[1]++
		} else {
			arr[2]++
		}
	}
	if arr[1] == arr[0]+arr[2] {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")

}

package main

import "fmt"

func main() {
	var s string
	var t int

	fmt.Scanln(&t)
	for ; t>0; t-- {
		fmt.Scanln(&s)
		a := []int{0, 0, 0}
		for _, e := range s {
			a[e-'A'] += 1
			// println("e-A: ", e-'A', ", ", "a[e-A]: ", a[e-'A'])
		}
		if a[1]!=0 && a[0] + a[2] == a[1] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
	return
}

package main
import ("fmt")

func main() {
    var t int
    fmt.Scanln(&t)
    for i:=0; i<t; i++ {
        var s string
        c1,c2,c3:=0,0,0
        fmt.Scanln(&s)
        for j:=range s {
            if s[j]=='A' { c1++
            } else if s[j]=='B' { c2++
            } else { c3++
            }
        }
        if c2==c1+c3 { fmt.Println("YES")
        } else { fmt.Println("NO") }
    }
}

package main

import "fmt"

func solve() {
	var (
		s       string
		A, B, C int
	)
	fmt.Scan(&s)

	for _, l := range s {
		if l == 'A' {
			A++
		} else if l == 'B' {
			B++
		} else {
			C++
		}
	}
	if B-C-A == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}
func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		solve()
	}
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var s string
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%s\n", &s)
		// fmt.Println("->", s)
		a, b, c := 0, 0, 0
		for j := 0; j < len(s); j++ {
			switch s[j] {
			case 'A':
				a++
			case 'B':
				b++
			case 'C':
				c++
			}
		}
		if a+c == b {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main
import "fmt"
import "bufio"
import "strconv"
import "strings"
import "os"
/*
*/

func main() {
  /*
  */
  f := true
  if f {
    reader := bufio.NewReader(os.Stdin)
    ns, _ := reader.ReadString('\n')
    n, _  := strconv.Atoi(strings.TrimSpace(ns))
    for i:=0;i<n;i++ {
      s, _ := reader.ReadString('\n')
      run(strings.TrimSpace(s))
    }
  }else {
    run("CABCBB")
  }
}

func run(s string) {
  var a, b, c int
  for _, rn := range s {
    if rn == 'A'{ a ++ }
    if rn == 'B'{ b ++ }
    if rn == 'C'{ c ++ }
  }
  if b - a -c == 0  {
    fmt.Println("YES")
  }else{
    fmt.Println("NO")
  }
}

package main

import (
	"fmt"
)

func checkInput(s string) string {
	if len(s) == 1 {
		return "NO"
	}
	letters := map[string]int{"A": 0, "B": 0, "C": 0}
	for _, c := range s {
		letters[string(c)]++
	}
	if letters["A"]+letters["C"] == letters["B"] {
		return "YES"
	}
	return "NO"
}

func main() {
	var count int
	fmt.Scanln(&count)
	res := []string{}

	for i := 0; i < count; i++ {
		var input string
		fmt.Scanln(&input)
		res = append(res, checkInput(input))
	}

	for _, s := range res {
		fmt.Println(s)
	}
}

package main

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

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

	for t := 0; t < T; t++ {
		var s string
		fmt.Fscanf(r, "%s\n", &s)
		c := make(map[byte]int)

		for i := 0; i < len(s); i++ {
			c[s[i]]++
		}

		if c['A']+c['C'] == c['B'] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main()  {
	var t,a,b,c int
	var s string
	in:=bufio.NewReader(os.Stdin)
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		fmt.Fscan(in,&s)
		a,b,c=0,0,0
		for j:=0;j<len(s);j++{
			if s[j]=='A'{
				a++
			}
			if s[j]=='B'{
				b++
			}
			if s[j]=='C'{
				c++
			}
		}
		if b==a+c{
			fmt.Println("YES")
		}else{
			fmt.Println("NO")
		}
	}

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

package main

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

var s string

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(read, &t)

	for i := 0; i < t; i++ {

		fmt.Fscan(read, &s)

		fmt.Println(solve())
	}
}

func solve() string {
	if len(s) % 2 == 1 {
		return "NO"
	}

	A := 0
	B := 0
	C := 0

	for i := 0; i < len(s); i++ {
		if s[i] == 'A' {
			A++
		} else if s[i] == 'B' {
			B++
		} else {
			C++
		}
	}

	if B == A + C {
		return "YES"
	}
	return "NO"
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var s string
	for ; n > 0; n-- {
		fmt.Scan(&s)
		var a, b, c int
		for _, ch := range s {
			if ch == 'A' {
				a++
			}
			if ch == 'B' {
				b++
			}
			if ch == 'C' {
				c++
			}
		}
		if a+c == b {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var x string
		fmt.Scan(&x)
		if len(x)%2 != 0 {
			fmt.Println("NO")
		} else {
			var a,b,c int
			for j:=0;j<len(x);j++{
				if string(x[j]) == "A" {
					a++
				} else if string(x[j]) == "B" {
					b++
				} else {
					c++
				}
			}
			if b == (a+c) {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1579A
Date: 11/10/21
User: epradere
URL: https://codeforces.com/problemset/problem/1579/A
Problem: CF1579A
**/
func (in *CF1579A) Run() {
	n := in.NextInt()
	for ; n > 0; n-- {
		s := in.NextString()
		a, b, c := 0, 0, 0
		for i := 0; i < len(s); i++ {
			if s[i] == 'A' {
				a++
			} else if s[i] == 'B' {
				b++
			} else {
				c++
			}
		}

		if a > 0 {
			b -= a
		}

		if c > 0 {
			b -= c
		}

		if b == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

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

package main

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

//problem A

func main() {
	reader := bufio.NewReader(os.Stdin)
	var t, ac, b int
	var str []byte
	fmt.Fscanf(reader, "%d\n", &t)
	for ; t > 0; t-- {
		ac = 0
		b = 0
		str, _, _ = reader.ReadLine()

		//fmt.Fscanf(reader, "%s\n", &str)
		for i := 0; i < len(str); i++ {
			switch str[i] {
			case 'A', 'C':
				ac++
			case 'B':
				b++
			}
		}
		if ac == b {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

//problem A

func main() {
	reader := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for ; t > 0; t-- {
		var str string
		var ac, b int
		fmt.Fscanf(reader, "%s\n", &str)
		for i := 0; i < len(str); i++ {
			switch str[i] {
			case 'A', 'C':
				ac++
			case 'B':
				b++
			}
		}
		if ac == b {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

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

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

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

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

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

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

func MAXX(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 GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

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

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

var t int

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

	for o := 0; o < t; o++ {
		String := make([]byte, 0)
		fmt.Fscan(input, &String)

		var A, B, C int
		q := len(String)
		for i := 0; i < q; i++ {
			if string(String[i]) == "A" {
				A++
			}
			if string(String[i]) == "B" {
				B++
			}
			if string(String[i]) == "C" {
				C++
			}
		}

		if B != A+C {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")

		}
	}

}

package main

import (
    "fmt"
)

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

    for t > 0 {
        t--
        var s string
        fmt.Scanf("%s\n", &s)
        //fmt.Println(s)
        cntB := 0
        for _, x := range s {
            if x == 'B' {
                cntB++
            }
        }

        if (cntB * 2 == len(s)) {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }
}

package main

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

func main() {
	var (
		t  int
		s  string
		an int
		bn int
		cn int
	)
	fmt.Scanf("%d\n", &t)
	scanner := bufio.NewScanner(os.Stdin)
	for i := 0; i < t; i++ {
		an, bn, cn = 0, 0, 0
		scanner.Scan()
		s = scanner.Text()
		for j := 0; j < len(s); j++ {
			if s[j] == 'A' {
				an++
			} else if s[j] == 'B' {
				bn++
			} else if s[j] == 'C' {
				cn++
			}
		}
		if bn == an+cn {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func main() {
	var iterations int
	fmt.Scanf("%d", &iterations)
	var s string
	for ; iterations > 0; iterations-- {
		fmt.Scanf("%s\n", &s)
		var a, b, c int
		for _, ch := range s {
			if ch == 'A' {
				a++
			}
			if ch == 'B' {
				b++
			}
			if ch == 'C' {
				c++
			}
		}
		if a+c == b {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func main() {
	var iterations int
	fmt.Scanf("%d", &iterations)
	var s string
	for ; iterations > 0; iterations-- {
		fmt.Scanf("%s", &s)
		var a, b, c int
		for _, ch := range s {
			if ch == 'A' {
				a++
			}
			if ch == 'B' {
				b++
			}
			if ch == 'C' {
				c++
			}
		}
		fmt.Println(s)
	}
}

package main

import "fmt"

func main() {
	var iterations int
	fmt.Scan(iterations)
	for ; iterations > 0; iterations-- {
		var s string
		fmt.Scan(s)
		var a, b, c int
		for _, ch := range s {
			if ch == 'A' {
				a++
			}
			if ch == 'B' {
				b++
			}
			if ch == 'C' {
				c++
			}
		}
		if a+c == b {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func main() {
	var iterations int
	fmt.Scanf("%d", &iterations)
	var s string
	for ; iterations > 0; iterations-- {
		fmt.Scanf("%s", &s)
		var a, b, c int
		for _, ch := range s {
			if ch == 'A' {
				a++
			}
			if ch == 'B' {
				b++
			}
			if ch == 'C' {
				c++
			}
		}
		if a+c == b {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var x string
		fmt.Scan(&x)
		if len(x)%2 != 0 {
			fmt.Println("NO")
		} else {
			var a,b,c int
			for j:=0;j<len(x);j++{
				if string(x[j]) == "A" {
					a++
				} else if string(x[j]) == "B" {
					b++
				} else {
					c++
				}
			}
			if b >= (a+c) {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1579A
Date: 11/10/21
User: epradere
URL: https://codeforces.com/problemset/problem/1579/A
Problem: CF1579A
**/
func (in *CF1579A) Run() {
	n := in.NextInt()
	for ; n > 0; n-- {
		s := in.NextString()
		a, b, c := 0, 0, 0
		for i := 0; i < len(s); i++ {
			if s[i] == 'A' {
				a++
			} else if s[i] == 'B' {
				b++
			} else {
				c++
			}
		}
		if a == 1 && b == 1 && c == 0 {
			b = -1
		}

		if a == 0 && b == 1 && c == 1 {
			b = -1
		}

		if a > 0 {
			b -= a
		}

		if c > 0 {
			b -= c
		}

		if b == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

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

package main

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

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

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

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

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

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

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

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

func MAXX(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 GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

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

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

var t int

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

	for o := 0; o < t; o++ {
		String := make([]byte, 0)
		fmt.Fscan(input, &String)

		var A, B, C int
		q := len(String)
		for i := 0; i < q; i++ {
			if string(String[i]) == "A" {
				A++
			}
			if string(String[i]) == "B" {
				B++
			}
			if string(String[i]) == "C" {
				C++
			}
		}

		if B != A+C {
			fmt.Println("NO")
		} else {
			if B == 1 {
				fmt.Println("NO")
			}
			if B == 2 {
				arr := make([]int, 0)
				for i := 0; i < 4; i++ {
					if string(String[i]) == "B" {
						arr = append(arr, i+1)
					}
				}
				if arr[1]-arr[0] == 2 {
					fmt.Println("NO")
				} else {
					fmt.Println("YES")
				}
			}

			if B > 2 {
				fmt.Println("YES")
			}
		}
	}

}

package main

import (
    "fmt"
)

func main() {
    var t int
    fmt.Scanf("%d", &t)
    //fmt.Println(t)

    for t > 0 {
        t--
        var s string
        fmt.Scanf("%s\n", &s)
        //fmt.Println(s)
        cntB := 0
        for _, x := range s {
            if x == 'B' {
                cntB++
            }
        }

        if (cntB * 2 == len(s)) {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }
}


package main

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

func solve() {
	_ = readInt()
	m := readInt()
	s := []byte(readString())

	for i := 0; i < m; i++ {
		l := readInt() - 1
		r := readInt() - 1
		c1s := readString()
		c2s := readString()
		for j := l; j <= r; j++ {
			if s[j] == c1s[0] {
				s[j] = c2s[0]
			}
		}
	}
	fmt.Println(string(s))
}

var scanner *bufio.Scanner

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

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

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

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

// A. Scarborough Fair
/*

Are you going to Scarborough Fair?

Parsley, sage, rosemary and thyme.

Remember me to one who lives there.

He once was the true love of mine.

Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.

Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.

Although the girl wants to help, Willem insists on doing it by himself.

Grick gave Willem a string of length n.

Willem needs to do m operations, each operation has four parameters l, r, c 1, c 2, which means that all symbols c 1 in range [l, r] (from l-th to r-th, including l and r) are changed into c 2. String is 1-indexed.

Grick wants to know the final string after all the m operations.

Input
The first line contains two integers n and m (1 ≤ n, m ≤ 100).

The second line contains a string s of length n, consisting of lowercase English letters.

Each of the next m lines contains four parameters l, r, c 1, c 2 (1 ≤ l ≤ r ≤ n, c 1, c 2 are lowercase English letters), separated by space.

Output
Output string s after performing m operations described above.

Examples
Input
3 1
ioi
1 1 i n

Output
noi

Input
5 3
wxhak
3 3 h x
1 5 x a
1 3 w g

Output
gaaak

Note
For the second example:

After the first operation, the string is wxxak.

After the second operation, the string is waaak.

After the third operation, the string is gaaak.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _ := reader.ReadString('\n')
	arr := strings.Split(strings.TrimSpace(input1), " ")

	m, _ := strconv.Atoi(arr[1])

	input2, _ := reader.ReadString('\n')
	s := strings.TrimSpace(input2)
	sArr := strings.Split(s, "")

	for ; m > 0; m-- {
		input3, _ := reader.ReadString('\n')
		arr := strings.Split(strings.TrimSpace(input3), " ")
		l, _ := strconv.Atoi(arr[0])
		r, _ := strconv.Atoi(arr[1])

		for i := l - 1; i < r; i++ {
			if sArr[i] == arr[2] {
				sArr[i] = arr[3]
			}
		}
	}
	fmt.Println(strings.Join(sArr, ""))
}

package main

import "fmt"

func main() {

	var n, m int
	fmt.Scan(&n, &m)

	var s string
	fmt.Scan(&s)

	for i := 0; i < m; i++ {

		var l, r int
		var c1, c2 string

		fmt.Scan(&l, &r, &c1, &c2)

		for i := l - 1; i < r; i++ {
			if s[i] == c1[0] {
				s = s[:i] + c2 + s[i+1:]
			}
		}

	}

	fmt.Println(s)

}

package main

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

func solve() {
	_ = readInt()
	m := readInt()
	s := []byte(readString())
	for i := 0; i < m; i++ {
		l := readInt() - 1
		r := readInt() - 1
		c1 := ([]byte(readString()))[0]
		c2 := ([]byte(readString()))[0]
		for j := l; j <= r; j++ {
			if s[j] == c1 {
				s[j] = c2
			}
		}
	}
	fmt.Println(string(s))
}

var scanner *bufio.Scanner

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

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

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

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

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n, m int
	var s string
	fmt.Scanf("%d %d\n%s\n", &n, &m, &s)
	result := strings.Split(s, "")
	for i := 0; i < m; i++ {
		var l, r int
		var c1, c2 string
		fmt.Scanf("%d %d %s %s\n", &l, &r, &c1, &c2)
		for j := l; j <= r; j++ {
			if result[j-1] == c1 {
				result[j-1] = c2
			}
		}
	}
	fmt.Println(strings.Join(result, ""))
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scanln(&n, &m) // no format

	var s string
	fmt.Scanln(&s)

	i2 := []rune(s)

	var l, r int
	var c1, c2 byte
	for i := 0; i < m; i++ {
		fmt.Scanf("%d %d %c %c\n", &l, &r, &c1, &c2)

		for k, v := range i2 {
			//i2[k] = rune(c2)
			if (k+1 >= l) && (k+1 <= r) {
				if v == rune(c1) {
					i2[k] = rune(c2)
				}
			}
		}
	}

	fmt.Println(string(i2))
}

package main

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

func solve() {
	readInt()
	m := readInt()
	s := []byte(readString())
	for i := 0; i < m; i++ {
		l := readInt() - 1
		r := readInt() - 1
		from := []byte(readString())[0]
		to := []byte(readString())[0]
		for j := l; j <= r; j++ {
			if s[j] == from {
				s[j] = to
			}
		}
	}
	fmt.Println(string(s))
}

var scanner *bufio.Scanner

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

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

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

// IO

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

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

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

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main
import "fmt"
import "strings"
func main() {
	var n, m, l, r int
	var a, c1, c2 string
	fmt.Scan(&n,&m,&a)
	for i:=0;i<m;i++ {
		fmt.Scan(&l,&r,&c1,&c2)
		l--
		a = a[:l] + strings.Replace(a[l:r],c1,c2,-1) + a[r:]
	}
	fmt.Print(a)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	var s0 string
	fmt.Scan(&n, &m, &s0)
	s := ([]byte)(s0) // new and copy
	for i := 0; i < m; i++ {
		var l, r int
		var s1, s2 string
		fmt.Scan(&l, &r, &s1, &s2)
		c1 := s1[0]
		c2 := s2[0]
		for j := l - 1; j <= r - 1; j++ {
			if s[j] == c1 {
				s[j] = c2
			}
		}
	}

	fmt.Println(string(s)) // new and copy
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	s := make([]byte, n)
	fmt.Scan(&s)
	for i := 0; i < m; i++ {
		var l, r int
		var s1, s2 string
		fmt.Scan(&l, &r, &s1, &s2)
		for j := l - 1; j <= r - 1; j++ {
			if s[j] == s1[0] {
				s[j] = s2[0]
			}
		}
	}

	fmt.Println(string(s))
}

package main

import (
	//"os"
	//"time"
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	//var s string // string不能更改
	s := make([]byte, n)
	fmt.Scan(&s)
	//fmt.Println("s = ", s)
	//fmt.Println(n, m, s)
	for i := 0; i < m; i++ { // 不存在++i
		var l, r int
		//fmt.Scan(&l, &r)
		var s1, s2 string
		//var c1, c2 byte // byte不能用来输入？值为0
		//fmt.Scanf("%c", &c1)
		//fmt.Scanf("%c", &c2)
		fmt.Scan(&l, &r, &s1, &s2)
		c1 := s1[0]
		c2 := s2[0]
		//fmt.Println("l = ", l, "r = ", r, "c1 = ", c1, "c2 = ", c2)
		for j := l - 1; j <= r - 1; j++ {
			if s[j] == c1 {
				s[j] = c2
			}
		}
	}

	//fmt.Println(s);
	for _, v := range s {
		fmt.Printf("%c", v)
	}
	fmt.Println("")
}

package main

import (
  "fmt"
)

func main() {
  var n, m int
  fmt.Scan(&n, &m)
  var str string
  fmt.Scan(&str)
  var s = make([]string, n)
  for i := 0; i < n; i++ {
    s[i] = string(str[i])
  }
  for i := 0; i < m; i++ {
    var l, r int
    var c1, c2 string
    fmt.Scan(&l, &r, &c1, &c2)
    for j := l - 1; j < r; j++ {
      if s[j] == c1 {
        s[j] = c2
      }
    }
  }
  for i := 0; i < n; i++ {
    fmt.Print(s[i])
  }
}

package main

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

func main() {
	sc := NewScanner()
	_, M := sc.NextInt(), sc.NextInt()
	S := []byte(sc.NextLine())
	for i := 0; i < M; i++ {
		a, b := sc.NextInt()-1, sc.NextInt()-1
		z, x := sc.Next(), sc.Next()
		for p := a; p <= b; p++ {
			if S[p] == z[0] {
				S[p] = x[0]
			}
		}
	}
	fmt.Println(string(S))
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n, m int
	var s string
	fmt.Scanf("%d %d\n%s\n", &n, &m, &s)
	result := strings.Split(s, "")
	for i := 0; i < m; i++ {
		var l, r int
		var c1, c2 string
		fmt.Scanf("%d %d %s %s\n", &l, &r, &c1, &c2)
		for j := l; j < r; j++ {
			if result[j-1] == c1 {
				result[j-1] = c2
			}
		}
	}
	fmt.Println(strings.Join(result, ""))
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scanln(&n, &m) // no format

	var s string
	fmt.Scanf("%s", &s)

	i2 := []rune(s)

	var l, r int
	var c1, c2 byte
	for i := 0; i < m; i++ {
		fmt.Scanf("%d %d %c %c\n", &l, &r, &c1, &c2)

		for k, v := range i2 {
			//i2[k] = rune(c2)
			if (k+1 >= l) && (k+1 <= r) {
				if v == rune(c1) {
					i2[k] = rune(c2)
				}
			}
		}
	}

	fmt.Println(string(i2))
}


package main

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

// 1 2 3 4
func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var n int
		fmt.Fscan(in, &n)
		max1, max2 := 0, 0
		for i := 0; i < n; i++ {
			num := 0
			fmt.Fscan(in, &num)
			if num >= max1 {
				max1, max2 = num, max1
			} else if num > max2 {
				max2 = num
			}
		}
		fmt.Fprintln(out, max1+max2)
	}
}

// (k-1 + X*2)*k

package main

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

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
}

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

func solve(istream *bufio.Reader) {
	n := readInt(istream)
	values := readArrInt(istream)
	maxValue := 0
	for i := 0; i < n; i++ {
		if i > 0 {
			maxValue = max(values[i]+values[i-1], maxValue)
		}
		for j := i + 1; j < n; j++ {
			if i > 0 {
				maxValue = max(values[j]+values[i-1], maxValue)
			}
			if j+1 < n {
				maxValue = max(values[i]+values[j+1], maxValue)
			}
		}
	}
	fmt.Println(maxValue)
}

func main() {
	istream := bufio.NewReader(os.Stdin)
	t := readInt(istream)
	for i := 0; i < t; i++ {
		solve(istream)
	}
}

package main

import (
	"fmt"
	"sort"
)

var x [][]int

func main() {
	times := 0
	fmt.Scanf("%d\n", &times)
	x = make([][]int, times)
	for i := 0; i < times; i++ {
		var l int
		fmt.Scanf("%d\n", &l)
		x[i] = make([]int, l)
		for j := 0; j < l; j++ {
			fmt.Scanf("%d", &x[i][j])
		}
		fmt.Scanln()
	}
	for i := 0; i < times; i++ {
		fmt.Println(solution(x[i]))
	}
}

func solution(nums []int) int {
	sort.Ints(nums)
	return nums[len(nums)-1] + nums[len(nums)-2]
}

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 a, b int
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			if v >= a {
				a, b = v, a
			} else if v > b {
				b = v
			}
		}

		fmt.Fprintln(out, a+b)
	}
}

package main

import (
	"fmt"
)

func main() {
	var (
		t, n int
		a    [1001]int
	)
	for fmt.Scan(&t); t > 0; t-- {
		fmt.Scan(&n)
		s1, s2 := 0, 0

		for i := 1; i <= n; i++ {
			fmt.Scan(&a[i])
			if a[i] > s2 {
				s2 = a[i]
			}
			if s1 < s2 {
				s1, s2 = s2, s1
			}
		}
		fmt.Println(s1 + s2)
	}

}

package main

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

func main() {
	var (
		t int
	)

	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d\n", &t)

	for t > 0 {
		t--

		text, _ := reader.ReadString('\n')
		ninps := strings.Fields(text)
		//n, _ := strconv.Atoi(ninps[0])

		text, _ = reader.ReadString('\n')
		ninps = strings.Fields(text)

		largest := -1
		largestId := -1
		for i, val := range ninps {
			a, _ := strconv.Atoi(val)
			if a > largest {
				largest = a
				largestId = i
			}
		}

		secondLargest := -1
		for i, val := range ninps {
			a, _ := strconv.Atoi(val)
			if a > secondLargest && largestId != i {
				secondLargest = a
			}
		}

		fmt.Println( (largest+secondLargest) )
	}
}

package main

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

/*

 */

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	a := make([]int, n)

	for i := range a {
		scanf("%d", &a[i])
	}
	scanf("\n")

	sort.Ints(a)

	ans := a[n-1]

	if n > 1 {
		ans += a[n-2]
	}

	fmt.Fprintln(writer, ans)
}

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

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

	for ; t > 0; t-- {
		solve()
	}
}

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 reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int64) int64 {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return nums[minNumIdx]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

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

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

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

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(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"
)

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}
func main() {
	_r, _w := os.Stdin, os.Stdout
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var solve func()

	/*-------------------------------Todo-----------------------------------------*/

	solve = func() {
		var n, max1, max2 int
		Fscan(in, &n)
		for i := 0; i < n; i++ {
			var t int
			Fscan(in, &t)
			if t > max1 {
				max2 = max1
				max1 = t
			} else if t > max2 {
				max2 = t
			}
		}

		Fprintln(out, max1+max2)
	}

	/*----------------------------------------------------------------------------*/
	var T int = 1
	Fscan(in, &T)
	for i := 0; i < T; i++ {
		solve()
	}
}

package main

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

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

	var t int
	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		var n, m1, m2 int
		fmt.Fscan(r, &n)
		for j := 0; j < n; j++ {
			var t int
			fmt.Fscan(r, &t)
			if t > m1 {
				m1, m2 = t, m1
			} else if t > m2 {
				m2 = t
			}
		}
		fmt.Fprintln(w, m1+m2)
	}
}

package main

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

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

	var t int
	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(r, &n)
		nums := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(r, &nums[j])
		}

		max := func(start int) {
			index := start
			for i, v := range nums[start:] {
				if v > nums[index] {
					index = i + start
				}
			}
			nums[index], nums[start] = nums[start], nums[index]
		}
		max(0)
		max(1)
		fmt.Fprintln(w, nums[0]+nums[1])
	}
}

package main

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

func solve(nums []int) int {
	// if we sort the slice then T: O(N LogN)
	// instead find Two max in   T: O(N)
	max := func(start int) {
		index := start
		for i, v := range nums[start:] {
			if v > nums[index] {
				index = i + start
			}
		}
		nums[index], nums[start] = nums[start], nums[index]
	}
	max(0)
	max(1)
	return nums[0] + nums[1]
}

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

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

	for i := 0; i < t; i++ {
		var n int
		fmt.Fscanf(r, "%d\n", &n)
		nums := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscanf(r, "%d", &nums[j])
		}
		fmt.Fscanf(r, "\n")
		fmt.Fprintf(w, "%d\n", solve(nums))
	}
}

package main

import (
	"fmt"
	"sort"
)

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

package main

import "fmt"

func main() {
  var jumlah_soal int;
  var jumlah_kue int;
  var max_2_kue int;
  var dua_kue int;
  var result int;
  var max_kue int;
  var max_kue_2 int;
  var jumlah_kue_max int;

fmt.Scan(&jumlah_soal);
for z:=0;z<jumlah_soal;z++ {

  dua_kue = 0;
  max_2_kue = 0;
  max_kue = 0;
  jumlah_kue_max = 1;
  max_kue_2 = 0;

  fmt.Scan(&jumlah_kue);

  kue := make([]int,jumlah_kue);

  for i:=0; i<jumlah_kue; i++ {
    fmt.Scan(&kue[i]);

    if max_kue < kue[i] {
      max_kue_2 = max_kue;
      max_kue = kue[i];
      jumlah_kue_max = 1;
    } else if max_kue == kue[i] {
      jumlah_kue_max++;
    } else if max_kue_2 < kue[i] {
      max_kue_2 = kue[i];
    }

    if i!=0 {
      dua_kue = kue[i]+kue[i-1];
      if max_2_kue < dua_kue {
        max_2_kue = dua_kue;
      }
    }
  }

  if jumlah_kue_max > 1 {
    result = max_kue + max_kue;
  }else{
    result = max_kue + max_kue_2;
  }

  fmt.Println(result)
}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	// fmt.Println("hello")
	var t int
	fmt.Scan(&t)
	for tc := 0; tc < t; tc++ {
		var n int
		fmt.Scan(&n)

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1654A
Date: 16/05/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1654/A
Problem: CF1654A
**/
func (in *CF1654A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, n)
		for i:=0;i<n;i++{
			arr[i] = in.NextInt()
		}
		sort.Ints(arr)
		fmt.Println(arr[n-1]+arr[n-2])
	}
}

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

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

package main

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

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

	var t int
	fmt.Fscan(r, &t)

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

		for j := 0; j < n-2; j++ {
			var t int
			fmt.Fscan(r, &t)
			if t > m1 {
				m1, m2 = t, m1
			} else if t > m2 {
				m2 = t
			}
		}
		fmt.Fprintln(w, m1+m2)
	}
}

package main

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

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

	var t int
	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(r, &n)
		nums := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(r, &nums[j])
		}

		max := func(start int) {
			index := start
			for i, v := range nums[start:] {
				if v > nums[index] {
					index = i + start
				}
			}
			nums[index], nums[start] = nums[start], nums[index]
		}
		max(0)
		max(1)
		fmt.Fprint(w, nums[0]+nums[1])
	}
}

package main

import (
	"fmt"
)

func solve(nums []int) {
	l1, l2 := -1, -1
	for i := 0; i < len(nums); i++ {
		if l1 < nums[i] {
			l2 = l1
			l1 = nums[i]
		} else if l2 < nums[i] {
			l2 = nums[i]
		}
	}
	fmt.Println(l1 + l2)
}

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	for caseID := 1; caseID <= cases; caseID++ {
		var n int
		fmt.Scanf("%d\n", &n)
		nums := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &nums[i])
		}
		solve(nums)
	}
}

package main

import "fmt"

func main() {
  var jumlah_kue int;
  var max_2_kue int;
  var dua_kue int;
  var result int;
  var max_kue int;
  var max_kue_2 int;
  var jumlah_kue_max int;
  dua_kue = 0;
  max_2_kue = 0;
  max_kue = 0;
  jumlah_kue_max = 1;
  max_kue_2 = 0;

  fmt.Scan(&jumlah_kue);

  kue := make([]int,jumlah_kue);

  for i:=0; i<jumlah_kue; i++ {
    fmt.Scan(&kue[i]);

    if max_kue < kue[i] {
      max_kue_2 = max_kue;
      max_kue = kue[i];
      jumlah_kue_max = 1;
    } else if max_kue == kue[i] {
      jumlah_kue_max++;
    } else if max_kue_2 < kue[i] {
      max_kue_2 = kue[i];
    }

    if i!=0 {
      dua_kue = kue[i]+kue[i-1];
      if max_2_kue < dua_kue {
        max_2_kue = dua_kue;
      }
    }
  }

  if jumlah_kue_max > 1 {
    result = max_kue + max_kue;
  }else{
    result = max_kue + max_kue_2;
  }

  fmt.Println(result)
}


package main

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

// github.com/EndlessCheng/codeforces-go

type seg []struct {
	l, r int
	v, c int
}

func (t seg) do(v, c, w, d int) (int, int) {
	if v == w {
		return v, c + d
	}
	if c > d {
		return v, c - d
	}
	return w, d - c
}

func (t seg) maintain(o int) {
	lo, ro := t[o<<1], t[o<<1|1]
	t[o].v, t[o].c = t.do(lo.v, lo.c, ro.v, ro.c)
}

func (t seg) build(a []int, o, l, r int) {
	t[o].l, t[o].r = l, r
	if l == r {
		t[o].v, t[o].c = a[l-1], 1
		return
	}
	m := (l + r) >> 1
	t.build(a, o<<1, l, m)
	t.build(a, o<<1|1, m+1, r)
	t.maintain(o)
}

func (t seg) query(o, l, r int) (int, int) {
	if l <= t[o].l && t[o].r <= r {
		return t[o].v, t[o].c
	}
	m := (t[o].l + t[o].r) >> 1
	if r <= m {
		return t.query(o<<1, l, r)
	}
	if m < l {
		return t.query(o<<1|1, l, r)
	}
	a, b := t.query(o<<1, l, r)
	c, d := t.query(o<<1|1, l, r)
	return t.do(a, b, c, d)
}

func newSegmentTree(a []int) seg {
	t := make(seg, 4*len(a))
	t.build(a, 1, 1, len(a))
	return t
}

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

	var n, q, l, r int
	Fscan(in, &n, &q)
	a := make([]int, n)
	ps := make([][]int, n+1)
	for i := range a {
		Fscan(in, &a[i])
		ps[a[i]] = append(ps[a[i]], i+1)
	}
	t := newSegmentTree(a)
	for ; q > 0; q-- {
		Fscan(in, &l, &r)
		v, _ := t.query(1, l, r)
		pos := ps[v]
		ll := sort.SearchInts(pos, l)
		rr := sort.SearchInts(pos, r+1)
		c := rr - ll
		sz := r - l + 1

		if c > (sz+1)/2 {
			or := sz - c
			c -= or +1
			Fprintln(out, c+1)
		} else {
			Fprintln(out, 1)
		}
	}
}

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

package main

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

type segment struct {
	ls, rs []int
	sum    []int
	cnt    int
}

func (t *segment) pushup(pos int) {
	t.sum[pos] = t.sum[t.ls[pos]] + t.sum[t.rs[pos]]
}
func (t *segment) insert(pos *int, lst, l, r, v int) {
	t.cnt++
	*pos = t.cnt
	t.ls[*pos] = t.ls[lst]
	t.rs[*pos] = t.rs[lst]
	t.sum[*pos] = t.sum[lst]
	if l == r {
		t.sum[*pos]++
		return
	}
	mid := (l + r) / 2
	if v <= mid {
		t.insert(&t.ls[*pos], t.ls[lst], l, mid, v)
	} else {
		t.insert(&t.rs[*pos], t.rs[lst], mid+1, r, v)
	}
	t.pushup(*pos)
}
func (t *segment) query(pos, lst, l, r, lim int) int {
	if t.sum[pos]-t.sum[lst] <= lim {
		return 0
	}
	if l == r {
		return t.sum[pos]-t.sum[lst]
	}
	mid := (l + r) / 2
	if t.sum[t.ls[pos]]-t.sum[t.ls[lst]] > lim {
		return t.query(t.ls[pos], t.ls[lst], l, mid, lim)
	} else {
		return t.query(t.rs[pos], t.rs[lst], mid+1, r, lim)
	}
}
func newSegmentTree(n int) segment {
	var t segment
	t.ls = make([]int, n*40)
	t.rs = make([]int, n*40)
	t.sum = make([]int, n*40)
	t.cnt = 0
	return t
}
func run(or io.Reader, ow io.Writer) {
	in := bufio.NewReader(or)
	out := bufio.NewWriter(ow)
	defer out.Flush()
	solve := func() {
		var n, q int
		fmt.Fscan(in, &n, &q)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		t := newSegmentTree(n)
		rt := make([]int, n+1)
		rt[0] = 0
		for i := 1; i <= n; i++ {
			t.insert(&rt[i], rt[i-1], 1, n, a[i])
		}
		for q > 0 {
			q--
			var l, r int
			fmt.Fscan(in, &l, &r)
			res := t.query(rt[r], rt[l-1], 1, n, (r-l+2)/2)
			if res == 0 {
				fmt.Fprintln(out, 1)
			} else {
				fmt.Fprintln(out, 2*res-(r-l+1))
			}
		}
	}
	var T int = 1
	// fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}
}
func main() { run(os.Stdin, os.Stdout) }

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) Next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) NextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt()
	}
	return res
}
func (s *Scanner) NextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt64()
	}
	return res
}
func Min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func Max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func InitInts1D(n int, val int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = val
	}
	return res
}
func InitInts2D(n, m int, val int) [][]int {
	res := make([][]int, n)
	for i := 0; i < n; i++ {
		res[i] = InitInts1D(m, val)
	}
	return res
}
func InitInts3D(n, m, k int, val int) [][][]int {
	res := make([][][]int, n)
	for i := 0; i < n; i++ {
		res[i] = InitInts2D(m, k, val)
	}
	return res
}

type StepState struct {
	step, dist int
}
type PriorityQueue []*StepState

func (pq PriorityQueue) Len() int { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool {
	if pq[i].step != pq[j].step {
		return pq[i].step < pq[j].step
	}
	return pq[i].dist < pq[j].dist
}
func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}
func (pq *PriorityQueue) Push(x interface{}) {
	item := x.(*StepState)
	*pq = append(*pq, item)
}
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

var (
	N, Q int
	arr  []int
	idx  [][]int
)

func findOcc(num, l, r int) int {
	l1, r1 := 0, len(idx[num])
	for l1 < r1 {
		m1 := (l1 + r1) / 2
		if idx[num][m1] < l {
			l1 = m1 + 1
		} else {
			r1 = m1
		}
	}

	l2, r2 := 0, len(idx[num])
	for l2 < r2 {
		m2 := (l2 + r2) / 2
		if idx[num][m2] > r {
			r2 = m2
		} else {
			l2 = m2 + 1
		}
	}

	return r2 - r1
}

func findMode(l, r int) (int, int) {
	mode, occ := -1, -1
	for i := 0; i < 50; i++ {
		toTest := arr[rand.Intn((r-l+1)*i/50+1)+l]
		curOcc := findOcc(toTest, l, r)
		if curOcc > occ {
			mode = toTest
			occ = curOcc
		}
	}
	return mode, occ
}

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

	N = sc.NextInt()
	Q = sc.NextInt()
	arr = sc.NextInts(N)

	idx = make([][]int, N+1)
	for i := 0; i < N; i++ {
		idx[arr[i]] = append(idx[arr[i]], i)
	}

	for q := 0; q < Q; q++ {
		l := sc.NextInt()
		r := sc.NextInt()
		l--
		r--
		_, cntOcc := findMode(l, r)
		// fmt.Fprintln(wr, mode, cntOcc)
		n := r - l + 1
		ans := Max(1, cntOcc-(n-cntOcc))
		fmt.Fprintln(wr, ans)
	}

}

package main

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

// github.com/EndlessCheng/codeforces-go
var (
	_i  = 1 << 12
	buf = make([]byte, 1<<12)
	ps  [][]int
)

func rc() byte {
	if _i == 1<<12 {
		os.Stdin.Read(buf)
		_i = 0
	}
	b := buf[_i]
	_i++
	return b
}
func ri() (x int) {
	b := rc()
	for ; '0' > b; b = rc() {
	}
	for ; '0' <= b; b = rc() {
		x = x*10 + int(b&15)
	}
	return
}

type seg []struct{ l, r, v, c int }

func (t seg) do(v, c, w, d int) (int, int) {
	if v == w {
		return v, c + d
	}
	if c > d {
		return v, c - d
	}
	return w, d - c
}

func (t seg) maintain(o int) {
	lo, ro := t[o<<1], t[o<<1|1]
	t[o].v, t[o].c = t.do(lo.v, lo.c, ro.v, ro.c)
}

func (t seg) build(o, l, r int) {
	t[o].l, t[o].r = l, r
	if l == r {
		v := ri()
		t[o].v, t[o].c = v, 1
		ps[v] = append(ps[v], l)
		return
	}
	m := (l + r) >> 1
	t.build(o<<1, l, m)
	t.build(o<<1|1, m+1, r)
	t.maintain(o)
}

func (t seg) query(o, l, r int) (int, int) {
	if l <= t[o].l && t[o].r <= r {
		return t[o].v, t[o].c
	}
	m := (t[o].l + t[o].r) >> 1
	if r <= m {
		return t.query(o<<1, l, r)
	}
	if m < l {
		return t.query(o<<1|1, l, r)
	}
	a, b := t.query(o<<1, l, r)
	c, d := t.query(o<<1|1, l, r)
	return t.do(a, b, c, d)
}

func main() {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, q := ri(), ri()
	ps = make([][]int, n+1)
	t := make(seg, 4*n)
	t.build(1, 1, n)
	for ; q > 0; q-- {
		l, r := ri(), ri()
		v, _ := t.query(1, l, r)
		cnt := sort.SearchInts(ps[v][sort.SearchInts(ps[v], l):], r+1)
		if sz := r - l + 1; cnt > (sz+1)/2 {
			Fprintln(out, cnt*2-sz)
		} else {
			Fprintln(out, 1)
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go

type seg []struct {
	l, r int
	v, c int
}

func (t seg) do(v, c, w, d int) (int, int) {
	if v == w {
		return v, c + d
	}
	if c > d {
		return v, c - d
	}
	return w, d - c
}

func (t seg) maintain(o int) {
	lo, ro := t[o<<1], t[o<<1|1]
	t[o].v, t[o].c = t.do(lo.v, lo.c, ro.v, ro.c)
}

func (t seg) build(a []int, o, l, r int) {
	t[o].l, t[o].r = l, r
	if l == r {
		t[o].v, t[o].c = a[l-1], 1
		return
	}
	m := (l + r) >> 1
	t.build(a, o<<1, l, m)
	t.build(a, o<<1|1, m+1, r)
	t.maintain(o)
}

func (t seg) query(o, l, r int) (int, int) {
	if l <= t[o].l && t[o].r <= r {
		return t[o].v, t[o].c
	}
	m := (t[o].l + t[o].r) >> 1
	if r <= m {
		return t.query(o<<1, l, r)
	}
	if m < l {
		return t.query(o<<1|1, l, r)
	}
	a, b := t.query(o<<1, l, r)
	c, d := t.query(o<<1|1, l, r)
	return t.do(a, b, c, d)
}

func newSegmentTree(a []int) seg {
	t := make(seg, 4*len(a))
	t.build(a, 1, 1, len(a))
	return t
}

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

	var n, q, l, r int
	Fscan(in, &n, &q)
	a := make([]int, n)
	ps := make([][]int, n+1)
	for i := range a {
		Fscan(in, &a[i])
		ps[a[i]] = append(ps[a[i]], i+1)
	}
	t := newSegmentTree(a)
	for ; q > 0; q-- {
		Fscan(in, &l, &r)
		v, _ := t.query(1, l, r)
		pos := ps[v]
		ll := sort.SearchInts(pos, l)
		rr := sort.SearchInts(pos, r+1)
		c := rr - ll
		sz := r - l + 1

		if c > (sz+1)/2 {
			or := sz - c
			c -= or * 2
			Fprintln(out, c+1)
		} else {
			Fprintln(out, 1)
		}
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go

type seg []struct {
	l, r int
	v, c int
}

func (t seg) do(v, c, w, d int) (int, int) {
	if v == w {
		return v, c + d
	}
	if c > d {
		return v, c-d
	}
	return w, d-c
}

func (t seg) maintain(o int) {
	lo, ro := t[o<<1], t[o<<1|1]
	t[o].v, t[o].c = t.do(lo.v, lo.c, ro.v, ro.c)
}

func (t seg) build(a []int, o, l, r int) {
	t[o].l, t[o].r = l, r
	if l == r {
		t[o].v,t[o].c = a[l-1],1
		return
	}
	m := (l + r) >> 1
	t.build(a, o<<1, l, m)
	t.build(a, o<<1|1, m+1, r)
	t.maintain(o)
}

// o=1  [l,r] 1<=l<=r<=n
func (t seg) query(o, l, r int) (int, int) {
	if l <= t[o].l && t[o].r <= r {
		return t[o].v, t[o].c
	}
	m := (t[o].l + t[o].r) >> 1
	if r <= m {
		return t.query(o<<1, l, r)
	}
	if m < l {
		return t.query(o<<1|1, l, r)
	}
	a, b := t.query(o<<1, l, r)
	c, d := t.query(o<<1|1, l, r)
	return t.do(a, b, c, d)
}

func newSegmentTree(a []int) seg {
	t := make(seg, 4*len(a))
	t.build(a, 1, 1, len(a))
	return t
}

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

	var n, q, l, r int
	Fscan(in, &n, &q)
	a := make([]int, n)
	ps := make([][]int, n+1)
	for i := range a {
		Fscan(in, &a[i])
		ps[a[i]] = append(ps[a[i]], i+1)
	}
	t := newSegmentTree(a)
	for ; q > 0; q-- {
		Fscan(in, &l, &r)
		v,_ := t.query(1, l, r)
		//Fprintln(out, v)

		pos := ps[v]
		ll := sort.SearchInts(pos, l)
		rr := sort.SearchInts(pos, r+1)
		c := rr-ll
		sz := r - l + 1
		if c > (sz+1)/2 {
			Fprintln(out, c-(sz+1)/2+1)
		} else {
			Fprintln(out, 1)
		}
	}
}

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

package main

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

type segment struct {
	ls, rs []int
	sum    []int
	cnt    int
}

func (t *segment) pushup(pos int) {
	t.sum[pos] = t.sum[t.ls[pos]] + t.sum[t.rs[pos]]
}
func (t *segment) insert(pos *int, lst, l, r, v int) {
	t.cnt++
	*pos = t.cnt
	t.ls[*pos] = t.ls[lst]
	t.rs[*pos] = t.rs[lst]
	t.sum[*pos] = t.sum[lst]
	if l == r {
		t.sum[*pos]++
		return
	}
	mid := (l + r) / 2
	if v <= mid {
		t.insert(&t.ls[*pos], t.ls[lst], l, mid, v)
	} else {
		t.insert(&t.rs[*pos], t.rs[lst], mid+1, r, v)
	}
	t.pushup(*pos)
}
func (t *segment) query(pos, lst, l, r, lim int) int {
	if t.sum[pos]-t.sum[lst] <= lim {
		return 0
	}
	if l == r {
		return t.sum[pos]
	}
	mid := (l + r) / 2
	if t.sum[t.ls[pos]]-t.sum[t.ls[lst]] > lim {
		return t.query(t.ls[pos], t.ls[lst], l, mid, lim)
	} else {
		return t.query(t.rs[pos], t.rs[lst], mid+1, r, lim)
	}
}
func newSegmentTree(n int) segment {
	var t segment
	t.ls = make([]int, n*40)
	t.rs = make([]int, n*40)
	t.sum = make([]int, n*40)
	t.cnt = 0
	return t
}
func run(or io.Reader, ow io.Writer) {
	in := bufio.NewReader(or)
	out := bufio.NewWriter(ow)
	defer out.Flush()
	solve := func() {
		var n, q int
		fmt.Fscan(in, &n, &q)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		t := newSegmentTree(n)
		rt := make([]int, n+1)
		rt[0] = 0
		for i := 1; i <= n; i++ {
			t.insert(&rt[i], rt[i-1], 1, n, a[i])
		}
		for q > 0 {
			q--
			var l, r int
			fmt.Fscan(in, &l, &r)
			res := t.query(rt[r], rt[l-1], 1, n, (r-l+2)/2)
			if res == 0 {
				fmt.Fprintln(out, 1)
			} else {
				fmt.Fprintln(out, 2*res-(r-l+1))
			}
		}
	}
	var T int = 1
	// fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}
}
func main() { run(os.Stdin, os.Stdout) }


package main

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

const MOD int64 = 1000000007

var n int

var a[]int

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

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

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(read, &t)

	for i := 0; i < t; i++ {

		fmt.Fscan(read, &n)

		a = make([]int, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(read, &a[j])
		}

		fmt.Println(solve())
	}
}

type pair struct {
	v int
	idx []int
}

func solve() int {
	height := 1

	var prev = -1

	for i := 0; i < n; i++ {

		if prev == -1 {
			if a[i] == 1  {
				height++
			}

		} else {
			if prev == 1 {
				if a[i] == 1 {
					height += 5
				}
			} else if prev == 0 {

				if a[i] == 0 {
					return -1
				} else {
					height ++
				}
			}

		}

		prev = a[i]
	}

	return height

}

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

package main

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

/*
5
4
0 1 1 0
1
1
2
1 1
3
0 0 1
3
1 1 1
---
7
2
7
-1
12
*/

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

	bld := strings.Builder{}

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

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

		died := false
		ans := 1

		prev := 0

		for i := 0; i < n; i++ {
			var num int
			scanf("%d", &num)

			switch {
			case num == 1 && prev == 0:
				ans++
			case num == 1 && prev == 1:
				ans += 5
			case num == 0 && prev == 0 && i == 0:
				// do nothing
			case num == 0 && prev == 0:
				died = true
			}

			prev = num
		}
		scanf("\n")

		if died {
			ans = -1
		}

		fmt.Fprintln(&bld, ans)
	}

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

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

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

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

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

	return true
}

//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 {
	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"
	"strconv"
	"strings"
)

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

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

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

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

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

/**
Run solve the problem CF1591A
Date: 12/12/21
User: epradere
URL: https://codeforces.com/contest/1591/problem/0
Problem: CF1591A
**/
func (in *CF1591A) Run() {

	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		size := 1
		live := true
		lastDay := 0
		for i := 0; i < n; i++ {
			day := in.NextInt()
			if day > 0 {
				size++
			}
			if i > 0 {
				if lastDay == 1 && day == 1 {
					size += 4
				}
				if day == 0 && lastDay == 0 {
					live = false
				}
			}
			lastDay = day
		}

		if !live {
			fmt.Println(-1)
		} else {
			fmt.Println(size)
		}

	}
}

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

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

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		solve()
	}
}
func solve() {
	n := ReadInt()
	a := ReadInts(n)
	ans := 1
	for i := 0; i < n; i++ {
		if a[i] == 1 {
			if i > 0 && a[i-1] == 1 {
				ans += 5
			} else {
				ans++
			}
		} else {
			if i > 0 && a[i-1] == 0 {
				println(-1)
				return
			}
		}
	}
	println(ans)
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func ReadString() (s string) { fmt.Fscan(_r, &s); return }
func ReadInt() (i int)       { fmt.Fscan(_r, &i); return }
func ReadInts(n int) (a []int) {
	for ; n > 0; n-- {
		a = append(a, ReadInt())
	}
	return
}
func print(a ...interface{})   { fmt.Fprint(_w, a...) }
func println(a ...interface{}) { fmt.Fprintln(_w, a...) }
func prints(s []int)           { v := fmt.Sprint(s); println(v[1 : len(v)-1]) }

package main

import "fmt"

func solve() {
	var n int
	fmt.Scan(&n)

	var a [101]int
	for j := 0; j < n; j++ {
		fmt.Scan(&a[j]);
	}

	s := 1
	for j := 0; j < n; j++ {
		if j > 0 && a[j] == 0 && a[j - 1] == 0 {
			fmt.Println(-1);
			return;
		}
		if j > 0 && a[j] == 1 && a[j - 1] == 1 {
			s += 5
		} else {
			if a[j] == 1 {
				s++;
			}
		}
	}
	fmt.Println(s)
}

func main() {
	var t int

	fmt.Scan(&t)

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

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		nw, dead, p, hgt := false, false, 0, 1
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &p)
			if p == 0 && nw {
				dead = true
			}
			if p == 0 {
				nw = true
			} else {
				if j > 0 && !nw && p == 1 {
					hgt += 5
				} else if j == 0 && p == 1 || nw && p == 1 {
					hgt++
				}
				nw = false
			}
		}
		if dead {
			fmt.Fprintln(w, -1)
		} else {
			fmt.Fprintln(w, hgt)
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(n int, a []int) int {
	b := 1
	for i := range a {
		if a[i] == 0 {
			if i > 0 && a[i-1] == 0 {
				return -1
			}
		} else if i > 0 && a[i-1] == 1 {
			b += 5
		} else {
			b++
		}
	}
	return b
}

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

package main

import "fmt"

func main() {
	var t int

	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)

		var a [101]int
		for j := 0; j < n; j++ {
			fmt.Scan(&a[j]);
		}

		s := 1
		for j := 0; j < n; j++ {
			if j > 0 && a[j] == 0 && a[j - 1] == 0 {
				fmt.Println(-1);
				return;
			}
			if j > 0 && a[j] == 1 && a[j - 1] == 1 {
				s += 5
			} else {
				if a[j] == 1 {
					s++;
				}
			}
		}
		fmt.Println(s)
	}
}


package main

import "fmt"

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

func main() {
	var n, mx int
	fmt.Scan(&n)
	input := make([]int, n)
	for i:=0; i<n; i++ {
		fmt.Scan(&input[i])
		mx = max(input[i], mx)
	}
	for i:=0; i<n; i++ {
		for j:=i+1; j<n; j++ {
			cur := input[i]
			for k:=i+1; k<=j; k++ {
				cur = cur ^ input[k]
			}
			mx = max(cur, mx)
		}
	}
	fmt.Println(mx)
}

package main

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

func scanInt(scanner *bufio.Scanner) 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()
	n := scanInt(scanner)
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = scanInt(scanner)
	}
	best := array[0]
	for i := 0; i < n; i++ {
		x := 0
		for j := i; j < n; j++ {
			x ^= array[j]
			if x > best {
				best = x
			}
		}
	}
	writer.WriteString(fmt.Sprintf("%d\n", best))
}

package main

import "fmt"

func main() {
    max := func(a,b int) int { if a > b { return a } else { return b } }
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    for i := 0; i < n; i++ { fmt.Scan(&a[i]) }
    ans := 0
    for i := 0; i < n; i++ {
        tmp := 0
        for j := i; j < n ;j++ {
            tmp ^= a[j]
            ans = max(ans,tmp)
        }
    }
    fmt.Println(ans)
}

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)
func main() {
	var n int
	ans:=0
	var a [110]int
	fmt.Scan(&n)
	input := bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	for i:=1;i<=n;i++ {
		input.Scan()
		bb,_:=strconv.Atoi(input.Text())
		a[i]=bb
		//fmt.Scan(&a[i])
	}
	k:=0
	for i:=1;i<=n;i++ {
		k=0
		for j:=i;j<=n;j++ {
			k^=a[j]
			if k>ans {
				ans=k
			}
		}
	}
	fmt.Println(ans)
}

package main

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

func scanInt(scanner *bufio.Scanner) 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()
	n := scanInt(scanner)
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = scanInt(scanner)
	}
	best := array[0]
	for i := 0; i < n; i++ {
		x := array[i]
		for j := i+1; j < n; j++ {
			x ^= array[j]
		}
		if x > best {
			best = x
		}
	}
	writer.WriteString(fmt.Sprintf("%d\n", best))
}

package main

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

func scanInt(scanner *bufio.Scanner) 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()
	n := scanInt(scanner)
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = scanInt(scanner)
	}
	best := array[0]
	for i := 0; i < n; i++ {
		x := array[i]
		for j := i+1; j < n; j++ {
			x ^= array[j]
			if x > best {
				best = x
			}
		}
	}
	writer.WriteString(fmt.Sprintf("%d\n", best))
}

package main

import "fmt"

func main() {
    max := func(a,b int) int { if a > b { return a } else { return b } }
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    for i := 0; i < n; i++ { fmt.Scan(&a[i]) }
    ans := 0
    for i := 0; i < n; i++ {
        tmp := a[i]
        for j := i+1; j < n ;j++ {
            tmp ^= a[j]
        }
        ans = max(ans,tmp)
    }
    fmt.Println(ans)
}

package main

import "fmt"

func main() {
    max := func(a,b int) int { if a > b { return a } else { return b } }
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    for i := 0; i < n; i++ { fmt.Scan(&a[i]) }
    ans := 0
    for i := 0; i < n; i++ {
        tmp := a[i]
        for j := i+1; j < n ;j++ {
            tmp ^= a[j]
            ans = max(ans,tmp)
        }
    }
    fmt.Println(ans)
}