Given an array of $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 1000$$$). Find the maximum value of $$$i + j$$$ such that $$$a_i$$$ and $$$a_j$$$ are coprime,$$$^{\dagger}$$$ or $$$-1$$$ if no such $$$i$$$, $$$j$$$ exist.For example consider the array $$$[1, 3, 5, 2, 4, 7, 7]$$$. The maximum value of $$$i + j$$$ that can be obtained is $$$5 + 7$$$, since $$$a_5 = 4$$$ and $$$a_7 = 7$$$ are coprime.$$$^{\dagger}$$$ Two integers $$$p$$$ and $$$q$$$ are coprime if the only positive integer that is a divisor of both of them is $$$1$$$ (that is, their greatest common divisor is $$$1$$$).

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 2\cdot10^5$$$) — the length of the array. The following line contains $$$n$$$ space-separated positive integers $$$a_1$$$, $$$a_2$$$,..., $$$a_n$$$ ($$$1 \leq a_i \leq 1000$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$.

For each test case, output a single integer  — the maximum value of $$$i + j$$$ such that $$$i$$$ and $$$j$$$ satisfy the condition that $$$a_i$$$ and $$$a_j$$$ are coprime, or output $$$-1$$$ in case no $$$i$$$, $$$j$$$ satisfy the condition.

NoteFor the first test case, we can choose $$$i = j = 3$$$, with sum of indices equal to $$$6$$$, since $$$1$$$ and $$$1$$$ are coprime.For the second test case, we can choose $$$i = 7$$$ and $$$j = 5$$$, with sum of indices equal to $$$7 + 5 = 12$$$, since $$$7$$$ and $$$4$$$ are coprime.

package main

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

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

	var T, N, X int
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &N)
		a := make([]int, 1001)
		for i := 1; i <= N; i++ {
			fmt.Fscan(in, &X)
			a[X] = i
		}
		result := -1
		for i := 1; i < 1001; i++ {
			for j := i; j < 1001; j++ {
				if a[i] > 0 && a[j] > 0 && a[i]+a[j] > result && gcd(i, j) == 1 {
					result = a[i] + a[j]
				}
			}
		}
		fmt.Fprintln(out, result)
	}
}

func gcd(i, j int) int {
	for j != 0 {
		i, j = j, i%j
	}
	return i
}

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

package main

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

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

	var T, N int
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &N)
		a, b := make([]int, N+1), make([]int, 1001)
		for i := 1; i <= N; i++ {
			fmt.Fscan(in, &a[i])
			b[a[i]] = i
		}
		result := -1
		for i := 1; i < 1001; i++ {
			for j := i; j < 1001; j++ {
				if b[i] > 0 && b[j] > 0 && gcd(i, j) == 1 && b[i]+b[j] > result {
					result = b[i] + b[j]
				}
			}
		}
		fmt.Fprintln(out, result)
	}
}

func gcd(i, j int) int {
	for j != 0 {
		i, j = j, i%j
	}
	return i
}

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

package main

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

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

	var T, N int
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &N)
		a, b := make([]int, N+1), make([]int, 1001)
		for i := 1; i <= N; i++ {
			fmt.Fscan(in, &a[i])
			b[a[i]] = i
		}
		result := -1
		for i := 1; i < 1001; i++ {
			for j := i; j < 1001; j++ {
				if b[i] > 0 && b[j] > 0 && gcd(i, j) == 1 && b[i]+b[j] > result {
					result = b[i] + b[j]
				}
			}
		}
		fmt.Fprintln(out, result)
	}
}

func gcd(i, j int) int {
	if j == 0 {
		return i
	}
	return gcd(j, i%j)
}

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

package main

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

func gcd(a, b int) int {
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

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

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

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

		aa := make([]int, n)
		for i := range aa {
			fmt.Fscan(in, &aa[i])
		}

		bb := make([]int, 1001)
		for i, v := range aa {
			bb[v] = i + 1
		}

		d := -1
		for i := 1; i <= 1000; i++ {
			if bb[i] == 0 {
				continue
			}
			for j := 1; j <= 1000; j++ {
				if bb[j] == 0 || gcd(i, j) != 1 {
					continue
				}
				d = max(d, bb[i]+bb[j])
			}
		}
		fmt.Fprintln(out, d)
	}
}

package main

import (
	"fmt"
)

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

		var numArr []int
		var num2 int
		fmt.Scan(&num2)
		for i := 0; i < num2; i++ {

			var num3 int
			fmt.Scan(&num3)
			numArr = append(numArr, num3)
		}
		var res int
		res = four(numArr)
		fmt.Println(res)
		// var res string
		// res = sec(numArr)
	}

}

func four(arr []int) int {
	arrMap := make(map[int]int)

	for i := 0; i < len(arr); i++ {
		arrMap[arr[i]] = i
	}
	max := 0
	for i := 1000; i > 0; i-- {
		for j := i; j > 0; j-- {
			if gcd(i, j) == 1 {
				val1, ok1 := arrMap[i]
				val2, ok2 := arrMap[j]
				if ok1 && ok2 {
					if val1+val2+2 > max {
						max = val1 + val2 + 2
					}
				}
			}
		}
	}
	if max == 0 {
		return -1
	}
	return max
}

func gcd(a, b int) int {
	// 如果分子大于分母，需要交换顺序
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a

}

package main

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

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

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

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

	var v [][]int
	for i := 1; i <= 1000; i++ {
		for j := i; j <= 1000; j++ {
			if gcd(i, j) == 1 {
				v = append(v, []int{i, j})
			}
		}
	}

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		b := make([]int, 1004)
		for i := range b { b[i] = -3e5 }

		var n int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
			b[a[i]] = max(b[a[i]], i+1)
		}

		res := -1
		for _, vv := range v {
			res = max(res, b[vv[0]] + b[vv[1]])
		}
		fmt.Fprintln(w, res)
	}

}

package main

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

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

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		b := make([]int, 1004)
		for i := range b { b[i] = -3e5 }

		var n int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
			b[a[i]] = max(b[a[i]], i+1)
		}

		res := -1
		for i, v1 := range b {
			for j, v2 := range b {
				if gcd(i, j) == 1 {
					res = max(res, v1 + v2)
				}
			}
		}
		fmt.Fprintln(w, res)
	}

}

package main

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

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

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

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

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

		b := make([]int, 1004)
		for i := range b { b[i] = -3e5 }

		var n int
		fmt.Fscan(r, &n)
		a := make([]int, n)

		for i := range a {
			fmt.Fscan(r, &a[i])
			b[a[i]] = max(b[a[i]], i+1)
		}

		res := -1
		for i, v1 := range b {
			for j, v2 := range b {
				if gcd(i, j) == 1 {
					// fmt.Fprintf(w, "*** i:%d j:%d v1:%d v2:%d v1+v2:%d\n", i, j, v1, v2, v1 + v2) // ***
					res = max(res, v1 + v2)
				}
			}
		}
		fmt.Fprintln(w, res)
	}

}

package main

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

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

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

	var T int
	var n int
	var x int

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

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		p := make([]int, 1001)
		for i, _ := range p {
			p[i] = -1
		}
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			p[x] = i
		}
		ans := -1
		for i := 1; i < 1001; i++ {
			for j := i; j < 1001; j++ {
				if p[i] >= 0 && p[j] >= 0 {
					if gcd(i, j) == 1 {
						if p[i]+p[j]+2 > ans {
							ans = p[i] + p[j] + 2
						}
					}
				}
			}
		}

		Fprintln(out, ans)
	}
}

package main

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

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

func solve() {
	var N, X int

	fmt.Fscan(in, &N)
	a := make([]int, 1001)
	for i := 1; i <= N; i++ {
		fmt.Fscan(in, &X)
		a[X] = i
	}

	result := -1
	for i := 1; i < 1001; i++ {
		for j := i; j < 1001; j++ {
			if a[i] > 0 && a[j] > 0 && a[i]+a[j] > result && gcd(i, j) == 1 {
				result = a[i] + a[j]
			}
		}
	}

	fmt.Fprintln(out, result)
}

func main() {
	var T int
	fmt.Fscan(in, &T)
	for ; T > 0; T-- {
		solve()
	}
	out.Flush()
}

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

package main

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

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		var n int
		Fscan(in, &n)
		var a = [1001]int{}
		for i := 0; i < n; i++ {
			var x int
			Fscan(in, &x)
			a[x] = i + 1
		}
		ans := -1
		for i := 0; i <= 1000; i++ {
			for j := 0; j <= i; j ++ {
				if gcd(i, j) == 1 && a[i] > 0 && a[j] > 0 {
					if ans < a[i] + a[j] {
						ans = a[i] + a[j]
					}
				}
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

import (
	"fmt"
)

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

func main() {
	var T int
	fmt.Scan(&T)
	for Case := 1; Case <= T; Case++ {
		var n int
		fmt.Scan(&n)
		var a = [1001]int{}
		for i := 0; i < n; i++ {
			var x int
			fmt.Scan(&x)
			a[x] = i + 1
		}
		ans := -1
		for i := 0; i <= 1000; i++ {
			for j := 0; j <= i; j ++ {
				if gcd(i, j) == 1 && a[i] > 0 && a[j] > 0 {
					if ans < a[i] + a[j] {
						ans = a[i] + a[j]
					}
				}
			}
		}
		fmt.Println(ans)
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

func  gcd(a, b int) int {
  for b != 0 {
      a, b = b, a%b
  }
  return a
}

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

	for ; t > 0; t-- {
		var n int
    fmt.Fscan(in, &n)
    a := make([]int, 1005, 1005)
    for i := 1; i <= n;i++{
      var x int
      fmt.Fscan(in, &x)
      a[x] = i
    }
    ret := -1
    for i := 1; i <= 1000; i++ {
      for j := 1; j <= 1000; j++ {
        if a[i] + a[j] > ret && gcd(i, j) == 1 && a[i] > 0 && a[j] > 0 {
          ret = a[i] + a[j]
        }
      }
    }
    fmt.Println(ret)
	}
}

package main

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

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

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

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		mx := -1
		a := make([]int, n)
		mp := make(map[int]int)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
			mp[a[j]] = j
		}
		for v, vid := range mp {
			for vv, vvid := range mp {
				if gcd(v, vv) == 1 {
					mx = max(mx, vid+vvid+2)
				}
			}
		}
		fmt.Println(mx)
	}
}

package main

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

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

func readInt() int {
	var i int
	fmt.Fscan(reader, &i)
	return i
}

func readString() string {
	var s string
	fmt.Fscan(reader, &s)
	return s
}

func max(u int, v int) int {
	if u < v {
		u = v
	}
	return u
}

func gcd(u int, v int) int {
	if u == 0 {
		return v
	}
	return gcd(v % u, u)
}

func main(){
	defer writer.Flush()
	T := readInt()
	for i := 1; i <= T; i++{
		n := readInt()
		m := make([]int, 1001)
		for i := 1; i <= n; i++ {
			a := readInt()
			m[a] = max(m[a], i)
		}
		ans := -1
		for i := 1000; i >= 1; i--{
			if m[i] > 0 {
				for j := i; j > 0; j-- {
					if m[j] == 0 {
						continue
					}
					if gcd(i, j) == 1 {
						ans = max(ans, m[i] + m[j])
					}
				}
			}
		}
		fmt.Fprintln(writer, ans)
	}
}

package main

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

const mod = 998244353
const mx = int64(1e9 + 7)

var crp [][]int

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	Fscan(in, &n)
	arr := make([]int, n+1)
	for i := 1; i <= n; i++ {
		Fscan(in, &arr[i])
	}
	idx := make([][]int, 1001)
	ans := -1
	for i := 1; i <= n; i++ {
		idx[arr[i]] = append(idx[arr[i]], i)
		for _, v := range crp[arr[i]] {
			if len(idx[v]) != 0 {
				ans = max(i+idx[v][len(idx[v])-1], ans)
			}
		}
	}
	Fprintln(out, ans)
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

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

func main() {
	crp = make([][]int, 1001)
	for i := 1; i <= 1000; i++ {
		for j := 1; j <= 1000; j++ {
			if gcd(i, j) == 1 {
				crp[i] = append(crp[i], j)
			}
		}
	}
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

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

func gcd(x, y int) int {
	if x < y {
		return gcd(y, x)
	}
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func solve(n int, a []int) int {
	b := make([]int, 1001)
	for i, x := range a {
		b[x] = i + 1
	}
	m := -1
	for i := 1; i < 1001; i++ {
		for j := i; j < 1001; j++ {
			if b[i] > 0 && b[j] > 0 && gcd(i, j) == 1 && b[i]+b[j] > m {
				m = b[i] + b[j]
			}
		}
	}
	return m
}

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 (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	maxInd := make([]int, 1001)
	for i := range maxInd {
		maxInd[i] = -1
	}
	for i := range arr {
		fmt.Fscan(in, &arr[i])
		maxInd[arr[i]] = i
	}
	ans := -1
	for i := 1; i <= 1000; i++ {
		for j := 1; j <= 1000; j++ {
			if maxInd[i] == -1 || maxInd[j] == -1 || GCD(i, j) != 1 {
				continue
			}
			ans = max(ans, maxInd[i]+maxInd[j]+2)
		}
	}
	fmt.Fprintln(out, ans)
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func GCD(a, b int) int {
	for a != b {
		if a > b {
			a -= b
		} else {
			b -= a
		}
	}

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []byte(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)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func gcd(a, b int) int {
	for b != 0 {
		a %= b
		a, b = b, a
	}
	return a
}

func main() {
	io := NewIO(os.Stdin, os.Stdout)

	vz := make([][]int, 1001)
	for i := 1; i <= 1000; i++ {
		for j := 1; j <= i; j++ {
			if gcd(i, j) == 1 {
				vz[i] = append(vz[i], j)
				vz[j] = append(vz[j], i)
			}
		}
	}

	t := io.ReadInt()
	for ; t > 0; t-- {
		n := io.ReadInt()
		a := io.ReadIntSlice(n)

		mx := make([]int, 1001)
		for i := 0; i < len(a); i++ {
			mx[a[i]] = i + 1
		}

		ans := -1

		for i := len(a) - 1; i >= 0; i-- {
			curr := a[i]
			for j := 0; j < len(vz[curr]); j++ {
				nw := mx[vz[curr][j]]
				if nw != 0 {
					ans = max(ans, i+1+nw)
				}
			}
		}

		io.Println(ans)
	}
}

package main

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

// https://space.bilibili.com/206214
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(curCase int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		pos := [1001]int{}
		for i, v := range a {
			pos[v] = max(pos[v], i+1)
		}
		ans := -1
		for i := 1; i <= 1000; i++ {
			for j := 1; j <= 1000; j++ {
				if gcd(i,j) != 1 {
					continue
				}
				p,q := pos[i],pos[j]
				if p > 0 && q > 0 {
					ans = max(ans, p+q)
				}
			}
		}
		Fprintln(out, ans)
	}

	cases := 1
	Fscan(in, &cases)
	for curCase := 1; curCase <= cases; curCase++ {
		solve(curCase)
	}

	// 如果是多组数据，请务必加上这段保险 —— 已经无法统计，有多少位竞赛选手在漏读数据上损失大把分数（包括我）
	// 此外，如果不小心写成了 scan(v) 而不是 scan(&v)，由于未传入指针，不会读入任何数据，这样本地运行一次就能立马发现错误
	leftData, _ := ioutil.ReadAll(in)
	if s := strings.TrimSpace(string(leftData)); s != "" {
		panic("有未读入的数据：\n" + s)
	}

}

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

func gcd(a, b int) int {
	for a != 0 {
		a, b = b%a, a
	}
	return b
}
func max(a, b int) int {
	if b > a {
		return b
	}
	return a
}

package main

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

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

	var T, N, X int
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &N)
		a := make([]int, 1001)
		for i := 1; i <= N; i++ {
			fmt.Fscan(in, &X)
			a[X] = i
		}
		result := -1
		for i := 1; i < 1001; i++ {
			for j := i; j < 1001; j++ {
				if a[i]+a[j] > result && gcd(i, j) == 1 {
					result = a[i] + a[j]
				}
			}
		}
		fmt.Fprintln(out, result)
	}
}

func gcd(i, j int) int {
	for j != 0 {
		i, j = j, i%j
	}
	return i
}

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

package main

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

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

	var T, N int
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &N)
		a, b := make([]int, N+1), make([]int, 1001)
		for i := 1; i <= N; i++ {
			fmt.Fscan(in, &a[i])
			b[a[i]] = i
		}
		result := -1
		for i := 1; i < 1001; i++ {
			for j := i; j < 1001; j++ {
				if gcd(i, j) == 1 && b[i]+b[j] > result {
					result = b[i] + b[j]
				}
			}
		}
		fmt.Fprintln(out, result)
	}
}

func gcd(i, j int) int {
	if j == 0 {
		return i
	}
	return gcd(j, i%j)
}

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

package main

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

func gcd(a, b int) int {
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

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

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

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

		aa := make([]int, n)
		for i := range aa {
			fmt.Fscan(in, &aa[i])
		}

		bb := make([]int, 1001)
		for i, v := range aa {
			bb[v] = i + 1
		}

		d := -1
		for i := 1; i <= 20; i++ {
			if bb[i] == 0 {
				continue
			}
			for j := 1; j <= 20; j++ {
				if bb[j] == 0 || gcd(i, j) != 1 {
					continue
				}
				d = max(d, bb[i]+bb[j])
			}
		}
		fmt.Fprintln(out, d)
	}
}

package main

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

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

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

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

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

		b := make([]int, 1004)
		for i := range b { b[i] = -2e5 }

		var n int
		fmt.Fscan(r, &n)
		a := make([]int, n)

		for i := range a {
			fmt.Fscan(r, &a[i])
			b[a[i]] = max(b[a[i]], i+1)
		}

		res := -1
		for i, v1 := range b {
			for j, v2 := range b {
				if gcd(i, j) == 1 {
					res = max(res, v1 + v2)
				}
			}
		}
		fmt.Fprintln(w, res)
	}

}

package main

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

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

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

	var T int
	var n int
	var x int

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

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		r := make([]int, n)
		p := make([]int, 1001)
		for i, _ := range p {
			p[i] = -1
		}
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			r[i] = x
			p[x] = i
		}
		ans := -1
		for i := 1; i < 1001; i++ {
			for j := i; j < 1001; j++ {
				if p[i] > 0 && p[j] > 0 {
					if gcd(i, j) == 1 {
						if p[i]+p[j]+2 > ans {
							ans = p[i] + p[j] + 2
						}
					}
				}
			}
		}

		Fprintln(out, ans)
	}
}


$$$n$$$ students attended the first meeting of the Berland SU programming course ($$$n$$$ is even). All students will be divided into two groups. Each group will be attending exactly one lesson each week during one of the five working days (Monday, Tuesday, Wednesday, Thursday and Friday), and the days chosen for the groups must be different. Furthermore, both groups should contain the same number of students.Each student has filled a survey in which they told which days of the week are convenient for them to attend a lesson, and which are not. Your task is to determine if it is possible to choose two different week days to schedule the lessons for the group (the first group will attend the lesson on the first chosen day, the second group will attend the lesson on the second chosen day), and divide the students into two groups, so the groups have equal sizes, and for each student, the chosen lesson day for their group is convenient.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. Then the descriptions of $$$t$$$ testcases follow. The first line of each testcase contains one integer $$$n$$$ ($$$2 \le n \le 1\,000$$$) — the number of students. The $$$i$$$-th of the next $$$n$$$ lines contains $$$5$$$ integers, each of them is $$$0$$$ or $$$1$$$. If the $$$j$$$-th integer is $$$1$$$, then the $$$i$$$-th student can attend the lessons on the $$$j$$$-th day of the week. If the $$$j$$$-th integer is $$$0$$$, then the $$$i$$$-th student cannot attend the lessons on the $$$j$$$-th day of the week.  Additional constraints on the input: for each student, at least one of the days of the week is convenient, the total number of students over all testcases doesn't exceed $$$10^5$$$.

For each testcase print an answer. If it's possible to divide the students into two groups of equal sizes and choose different days for the groups so each student can attend the lesson in the chosen day of their group, print "YES" (without quotes). Otherwise, print "NO" (without quotes).

NoteIn the first testcase, there is a way to meet all the constraints. For example, the first group can consist of the first and the third students, they will attend the lessons on Thursday (the fourth day); the second group can consist of the second and the fourth students, and they will attend the lessons on Tuesday (the second day).In the second testcase, it is impossible to divide the students into groups so they attend the lessons on different days.

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%d\n", &n)
		s := make([][5]byte, n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d %d %d %d %d\n", &s[i][0], &s[i][1], &s[i][2], &s[i][3], &s[i][4])
		}
		found := false
		for i := 0; i < 5; i++ {
			for j := i + 1; j < 5; j++ {
				rs := true
				var onlyi, onlyj, both int
				for q := 0; q < n; q++ {
					if s[q][i] == 0 && s[q][j] == 0 {
						rs = false
						break
					}
					if s[q][i] == 1 && s[q][j] == 0 {
						onlyi++
					}
					if s[q][i] == 0 && s[q][j] == 1 {
						onlyj++
					}
					if s[q][i] == 1 && s[q][j] == 1 {
						both++
					}
				}
				if !rs {
					continue
				}
				if onlyi+both < n/2 || onlyj+both < n/2 {
					continue
				}
				found = true
				break
			}
		}
		if found {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

var input io.Reader = bufio.NewReader(os.Stdin)
var output io.Writer = bufio.NewWriter(os.Stdout)

var t, n int
var a [1005][5]int

func testcase() bool {
	fmt.Fscan(input, &n)

	for i := 0; i < n; i++ {
		for j := 0; j < 5; j++ {
			fmt.Fscan(input, &a[i][j])
		}
	}
	for i := 0; i < 5; i++ {
		for j := i + 1; j < 5; j++ {
			var cnt [3]int
			can := true
			for k := 0; k < n; k++ {
				if a[k][i] == a[k][j] {
					if a[k][i] == 0 {
						can = false
						break
					}
					cnt[2]++
				} else {
					if a[k][i] == 1 {
						cnt[0]++
					} else {
						cnt[1]++
					}
				}
			}
			if cnt[0] < cnt[1] {
				tmp := cnt[1] - cnt[0]
				cnt[0] += tmp
				cnt[2] -= tmp
			} else {
				tmp := cnt[0] - cnt[1]
				cnt[1] += tmp
				cnt[2] -= tmp
			}
			if cnt[2] < 0 {
				can = false
			}
			cnt[0] += cnt[2] / 2
			cnt[1] += cnt[2] / 2
			if cnt[0] == cnt[1] && cnt[0]+cnt[1] == n && can {
				return true
			}
		}
	}
	return false
}

func main() {
	fmt.Fscan(input, &t)
	for ; t > 0; t-- {
		cur := testcase()
		if cur {
			fmt.Fprint(os.Stdout, "YES\n")
		} else {
			fmt.Fprint(os.Stdout, "NO\n")
		}
	}

}

package main

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

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

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

var t, n int
var a [1005][5]int

func testcase() bool {
	// scanf("%d\n", &n)
	fmt.Fscan(input, &n)
	for i := 0; i < n; i++ {
		for j := 0; j < 5; j++ {
			// scanf("%d ", &a[i][j])
			fmt.Fscan(input, &a[i][j])
		}
	}
	for i := 0; i < 5; i++ {
		for j := i + 1; j < 5; j++ {
			var cnt [3]int
			can := true
			for k := 0; k < n; k++ {
				if a[k][i] == a[k][j] {
					if a[k][i] == 0 {
						can = false
						break
					}
					cnt[2]++
				} else {
					if a[k][i] == 1 {
						cnt[0]++
					} else {
						cnt[1]++
					}
				}
			}
			if cnt[0] < cnt[1] {
				tmp := cnt[1] - cnt[0]
				cnt[0] += tmp
				cnt[2] -= tmp
			} else {
				tmp := cnt[0] - cnt[1]
				cnt[1] += tmp
				cnt[2] -= tmp
			}
			if cnt[2] < 0 {
				can = false
			}
			cnt[0] += cnt[2] / 2
			cnt[1] += cnt[2] / 2
			// fmt.Println(i, j, cnt)
			if cnt[0] == cnt[1] && cnt[0]+cnt[1] == n && can {
				return true
			}
		}
	}
	return false
}

func main() {
	// scanf("%d\n", &t)
	fmt.Fscan(input, &t)
	for ; t > 0; t-- {
		// writer.Flush()
		cur := testcase()
		// fmt.Println(cur)
		if cur {
			// printf("YES\n")
			fmt.Println("YES")
		} else {
			// printf("NO\n")
			fmt.Println("NO")
		}
		// writer.Flush()
	}

}

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

var t, n int
var a [1005][5]int

func testcase() bool {
	// scanf("%d\n", &n)
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		for j := 0; j < 5; j++ {
			// scanf("%d ", &a[i][j])
			fmt.Scan(&a[i][j])
		}
	}
	for i := 0; i < 5; i++ {
		for j := i + 1; j < 5; j++ {
			var cnt [3]int
			can := true
			for k := 0; k < n; k++ {
				if a[k][i] == a[k][j] {
					if a[k][i] == 0 {
						can = false
						break
					}
					cnt[2]++
				} else {
					if a[k][i] == 1 {
						cnt[0]++
					} else {
						cnt[1]++
					}
				}
			}
			if cnt[0] < cnt[1] {
				tmp := cnt[1] - cnt[0]
				cnt[0] += tmp
				cnt[2] -= tmp
			} else {
				tmp := cnt[0] - cnt[1]
				cnt[1] += tmp
				cnt[2] -= tmp
			}
			if cnt[2] < 0 {
				can = false
			}
			cnt[0] += cnt[2] / 2
			cnt[1] += cnt[2] / 2
			// fmt.Println(i, j, cnt)
			if cnt[0] == cnt[1] && cnt[0]+cnt[1] == n && can {
				return true
			}
		}
	}
	return false
}

func main() {
	// scanf("%d\n", &t)
	fmt.Scan(&t)
	for ; t > 0; t-- {
		// writer.Flush()
		cur := testcase()
		// fmt.Println(cur)
		if cur {
			// printf("YES\n")
			fmt.Println("YES")
		} else {
			// printf("NO\n")
			fmt.Println("NO")
		}
		// writer.Flush()
	}

}

package main

import (
	"fmt"
)

var t, n int
var a [1005][5]int

func testcase() bool {
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		for j := 0; j < 5; j++ {
			fmt.Scan(&a[i][j])
		}
	}
	for i := 0; i < 5; i++ {
		for j := i + 1; j < 5; j++ {
			var cnt [3]int
			can := true
			for k := 0; k < n; k++ {
				if a[k][i] == a[k][j] {
					if a[k][i] == 0 {
						can = false
						break
					}
					cnt[2]++
				} else {
					if a[k][i] == 1 {
						cnt[0]++
					} else {
						cnt[1]++
					}
				}
			}
			if cnt[0] < cnt[1] {
				tmp := cnt[1] - cnt[0]
				cnt[0] += tmp
				cnt[2] -= tmp
			} else {
				tmp := cnt[0] - cnt[1]
				cnt[1] += tmp
				cnt[2] -= tmp
			}
			if cnt[2] < 0 {
				can = false
			}
			cnt[0] += cnt[2] / 2
			cnt[1] += cnt[2] / 2
			// fmt.Println(i, j, cnt)
			if cnt[0] == cnt[1] && cnt[0]+cnt[1] == n && can {
				return true
			}
		}
	}
	return false
}

func main() {
	fmt.Scan(&t)
	for ; t > 0; t-- {
		cur := testcase()
		if cur {
			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)

		c := make([][5]int, n)
		for i := 0; i < n; i++ {
			for j := 0; j < 5; j++ {
				fmt.Fscan(in, &c[i][j])
			}
		}

		var isValid bool
		for i := 0; i < 5; i++ {
			for j := 0; j < 5; j++ {
				if i == j {
					continue
				}

				var c1, c2, cx int
				for _, p := range c {
					if p[i] == 1 {
						c1++
					}

					if p[j] == 1 {
						c2++
					}

					if p[i] == 0 && p[j] == 0 {
						cx++
					}
				}

				if c1 >= n/2 && c2 >= n/2 && cx == 0 {
					isValid = true
					break
				}
			}
		}

		if !isValid {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

import "fmt"

const (
	MaxN = 1005
	MaxDay = 5
)

var (
	T, n int
	a [MaxN][MaxDay]int
)

func main() {
	_, _ = fmt.Scan(&T)
	for ; T > 0; T-- {
		_, _ = fmt.Scan(&n)

		for i := 0; i < n; i++ {
			for j := 0; j < MaxDay; j++ {
				_, _ = fmt.Scan(&a[i][j])
			}
		}

		ans := "NO"
		for j1 := 0; j1 < MaxDay; j1++ {
			for j2 := j1 + 1; j2 < MaxDay; j2++ {
				x, y := 0, 0
				for i := 0; i < n; i++ {
					if a[i][j1] == 0 && a[i][j2] == 0 {
						x, y = 0, 0
						break
					}
					x += a[i][j1]
					y += a[i][j2]
				}
				if x >= n / 2 && y >= n / 2 {
					ans = "YES"
				}
			}
		}

		fmt.Println(ans)
	}
}

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
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

var t int

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

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)

		bir := make([]int, 0)
		iki := make([]int, 0)
		uc := make([]int, 0)
		dort := make([]int, 0)
		bas := make([]int, 0)

		for i := 1; i < n+1; i++ {
			var b, ii, u, d, bs int
			fmt.Fscan(input, &b, &ii, &u, &d, &bs)
			if b == 1 {
				bir = append(bir, i)
			}
			if ii == 1 {
				iki = append(iki, i)
			}
			if u == 1 {
				uc = append(uc, i)
			}
			if d == 1 {
				dort = append(dort, i)
			}
			if bs == 1 {
				bas = append(bas, i)
			}

		}

		l := n / 2
		Bigg := make([][]int, 0)
		if len(bir) >= l {
			Bigg = append(Bigg, bir)
		}
		if len(iki) >= l {
			Bigg = append(Bigg, iki)
		}
		if len(uc) >= l {
			Bigg = append(Bigg, uc)
		}
		if len(dort) >= l {
			Bigg = append(Bigg, dort)
		}
		if len(bas) >= l {
			Bigg = append(Bigg, bas)
		}

		if len(Bigg) < 2 {
			fmt.Println("NO")
		} else {
			q := len(Bigg)
			ee := 0
			for i := 0; i < q-1; i++ {
				z := 0
				for j := i + 1; j < q; j++ {
					union := Union(Bigg[i], Bigg[j])
					if len(union) == n {
						ee = 1
						z = 1
						break
					}
				}
				if z == 1 {
					break
				}
			}
			if ee == 1 {
				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
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

var t int

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

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)

		bir := make([]int, 0)
		iki := make([]int, 0)
		uc := make([]int, 0)
		dort := make([]int, 0)
		bas := make([]int, 0)

		for i := 1; i < n+1; i++ {
			var b, ii, u, d, bs int
			fmt.Fscan(input, &b, &ii, &u, &d, &bs)
			if b == 1 {
				bir = append(bir, i)
			}
			if ii == 1 {
				iki = append(iki, i)
			}
			if u == 1 {
				uc = append(uc, i)
			}
			if d == 1 {
				dort = append(dort, i)
			}
			if bs == 1 {
				bas = append(bas, i)
			}

		}

		l := n / 2
		Bigg := make([][]int, 0)
		if len(bir) >= l {
			Bigg = append(Bigg, bir)
		}
		if len(iki) >= l {
			Bigg = append(Bigg, iki)
		}
		if len(uc) >= l {
			Bigg = append(Bigg, uc)
		}
		if len(dort) >= l {
			Bigg = append(Bigg, dort)
		}
		if len(bas) >= l {
			Bigg = append(Bigg, bas)
		}

		if len(Bigg) < 2 {
			fmt.Println("NO")
		} else {
			q := len(Bigg)
			e := 0
			for i := 0; i < q-1; i++ {
				z := 0
				for j := i + 1; j < q; j++ {
					union := Union(Bigg[i], Bigg[j])
					if len(union) == n {
						e = 1
						z = 1
						break
					}
				}
				if z == 1 {
					break
				}
			}
			if e == 1 {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}

	}

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var t int
	_, _ = fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		var n int
		_, _ = fmt.Fscan(reader, &n)
		students := make([][]rune, n)
		for i := 0; i < int(n); i++ {
			students[i] = make([]rune, 5)
			for j := range students[i] {
				_, _ = fmt.Fscan(reader, &students[i][j])
			}
		}
		can := "NO"
		for i := 0; i < 5; i++ {
			for j := 0; j < 5; j++ {
				if i == j {
					continue
				}
				days := make(map[int]map[int]bool)
				for k := 0; k < 5; k++ {
					days[k] = make(map[int]bool)
				}
				for k, v := range students {
					if v[i] != 0 {
						days[i][k] = true
					}
					if v[j] != 0 {
						days[j][k] = true
					}
				}
				len0, len1 := len(days[i]), len(days[j])
				for k := range days[i] {
					if days[i][k] && days[j][k] {
						if len0 > len1 {
							days[i][k] = false
							len0--
						} else {
							days[j][k] = false
							len1--
						}
					}
				}
				if len0 == len1 && len0 == int(n)/2 {
					can = "YES"
				}
			}
		}
		fmt.Println(can)
	}
}

package main

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

var n int

var st [][5]int

var days [5][]bool

func main() {

	r := bufio.NewReader(os.Stdin)

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

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

		st = make([][5]int, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(r, &st[j][0], &st[j][1], &st[j][2], &st[j][3], &st[j][4])
		}

		ans := solve()
		fmt.Println(ans)
	}
}

func solve() string {

	for i := 0; i < 5; i++ {
		days[i] = make([]bool, n)
	}

	for i := 0; i < n; i++ {
		if st[i][0] == 1 {
			days[0][i] = true
		}
		if st[i][1] == 1 {
			days[1][i] = true
		}
		if st[i][2] == 1 {
			days[2][i] = true
		}
		if st[i][3] == 1 {
			days[3][i] = true
		}
		if st[i][4] == 1 {
			days[4][i] = true
		}
	}

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

		d1 := days[i]
		for j := i + 1; j < 5; j++ {
			d2 := days[j]

			one := 0
			two := 0
			both := 0

			for k := 0; k < n; k++ {
				if d1[k] {
					one++
				}
				if d2[k] {
					two++
				}
				if d1[k] || d2[k] {
					both++
				}
			}

			if one >= n/2 && two >= n/2 && both == n {
				return "YES"
			}
		}
	}

	return "NO"
}

package main

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

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

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

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

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

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

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

func main() {
	defer writer.Flush()
	for t := _int(); t > 0; t-- {
		n := _int()
		students := make([][5]int, n)
		for i := range students {
			for j := range students[i] {
				students[i][j] = _int()
			}
		}
		printf("%s\n", sol(n, students))
	}
}

func sol(n int, students [][5]int) string {
	for i := 0; i < 5; i++ {
		for j := i + 1; j < 5; j++ {
			if can(n, students, i, j) {
				return "YES"
			}
		}
	}
	return "NO"
}

func can(n int, students [][5]int, d1, d2 int) bool {
	canD1 := 0
	canD2 := 0
	for i := range students {
		if !(students[i][d1] == 1 || students[i][d2] == 1) {
			return false
		}
		if students[i][d1] == 1 {
			canD1++
		}
		if students[i][d2] == 1 {
			canD2++
		}
	}
	return canD1 >= n/2 && canD2 >= n/2
}

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 n int
		fmt.Fscanf(r, "%d\n", &n)

		arr := make([][]int, n)
		for i := 0; i < n; i++ {
			arr[i] = make([]int, 5)
			for j := 0; j < 5; j++ {
				fmt.Fscanf(r, "%d", &arr[i][j])
			}
			fmt.Fscanf(r, "\n")
		}

		found := false
		for i := 0; i < 5 && !found; i++ {
			for j := i + 1; j < 5 && !found; j++ {
				ic, jc, bc := 0, 0, 0
				for k := 0; k < n; k++ {
					if arr[k][i] == 1 && arr[k][j] == 1 {
						bc++
					} else if arr[k][i] == 1 {
						ic++
					} else if arr[k][j] == 1 {
						jc++
					} else {
						break
					}
				}

				if ic+jc+bc == n && (ic+bc) >= n/2 && (jc+bc) >= n/2 {
					found = true
					break
				}

			}
		}

		if found {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

var reader = bufio.NewScanner(os.Stdin)

func rString() string {
	if !reader.Scan() {
		panic(reader.Err())
	}
	return reader.Text()
}

func rInt() int64 {
	text := rString()
	n, _ := strconv.ParseInt(text, 10, 0)
	return n
}

func main() {
	t := rInt()
	fmt.Println("t=", t)
	for ; t > 0; t-- {
		n := rInt()
		fmt.Println("n=", n)
		s := make([][5]byte, n)
		for i := int64(0); i < n; i++ {
			fmt.Scanf("%d %d %d %d %d\n", &s[i][0], &s[i][1], &s[i][2], &s[i][3], &s[i][4])
		}
		fmt.Println("s=", s)
		found := false
		for i := 0; i < 5; i++ {
			for j := i + 1; j < 5; j++ {
				rs := true
				var onlyi, onlyj, both int64
				for _, w := range s {
					if w[i] == 0 && w[j] == 0 {
						rs = false
						break
					}
					if w[i] == 1 && w[j] == 0 {
						onlyi++
					}
					if w[i] == 0 && w[j] == 1 {
						onlyj++
					}
					if w[i] == 1 && w[j] == 1 {
						both++
					}
				}
				if !rs {
					continue
				}
				if onlyi+both < n/2 || onlyj+both < n/2 {
					continue
				}
				found = true
				break
			}
		}
		if found {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

var reader = bufio.NewScanner(os.Stdin)

func rString() string {
	if !reader.Scan() {
		panic(reader.Err())
	}
	return reader.Text()
}

func rInt() int64 {
	text := rString()
	n, _ := strconv.ParseInt(text, 10, 0)
	return n
}

func main() {
	t := rInt()
	fmt.Println("t=", t)
	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%d\n", &n)
		fmt.Println("n=", n)
		s := make([][5]byte, n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d %d %d %d %d\n", &s[i][0], &s[i][1], &s[i][2], &s[i][3], &s[i][4])
		}
		fmt.Println("s=", s)
		found := false
		for i := 0; i < 5; i++ {
			for j := i + 1; j < 5; j++ {
				rs := true
				var onlyi, onlyj, both int
				for _, w := range s {
					if w[i] == 0 && w[j] == 0 {
						rs = false
						break
					}
					if w[i] == 1 && w[j] == 0 {
						onlyi++
					}
					if w[i] == 0 && w[j] == 1 {
						onlyj++
					}
					if w[i] == 1 && w[j] == 1 {
						both++
					}
				}
				if !rs {
					continue
				}
				if onlyi+both < n/2 || onlyj+both < n/2 {
					continue
				}
				found = true
				break
			}
		}
		if found {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

var reader = bufio.NewScanner(os.Stdin)

func rString() string {
	if !reader.Scan() {
		panic(reader.Err())
	}
	return reader.Text()
}

func rInt() int64 {
	text := rString()
	n, _ := strconv.ParseInt(text, 10, 0)
	return n
}

func main() {
	for t := rInt(); t > 0; t-- {
		var n int
		fmt.Scanf("%d\n", &n)
		s := make([][5]byte, n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d %d %d %d %d\n", &s[i][0], &s[i][1], &s[i][2], &s[i][3], &s[i][4])
		}
		fmt.Println("s=", s)
		found := false
		for i := 0; i < 5; i++ {
			for j := i + 1; j < 5; j++ {
				rs := true
				var onlyi, onlyj, both int
				for _, w := range s {
					if w[i] == 0 && w[j] == 0 {
						rs = false
						break
					}
					if w[i] == 1 && w[j] == 0 {
						onlyi++
					}
					if w[i] == 0 && w[j] == 1 {
						onlyj++
					}
					if w[i] == 1 && w[j] == 1 {
						both++
					}
				}
				if !rs {
					continue
				}
				if onlyi+both < n/2 || onlyj+both < n/2 {
					continue
				}
				found = true
				break
			}
		}
		if found {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func rString() string {
	reader := bufio.NewScanner(os.Stdin)
	if !reader.Scan() {
		panic(reader.Err())
	}
	return reader.Text()
}

func rInt() (int64, error) {
	text := rString()
	n, _ := strconv.ParseInt(text, 10, 0)
	return n, nil
}

func main() {
	t, _ := rInt()
	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%d\n", &n)
		s := make([][5]byte, n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d %d %d %d %d\n", &s[i][0], &s[i][1], &s[i][2], &s[i][3], &s[i][4])
		}
		fmt.Println("s=", s)
		found := false
		for i := 0; i < 5; i++ {
			for j := i + 1; j < 5; j++ {
				rs := true
				var onlyi, onlyj, both int
				for _, w := range s {
					if w[i] == 0 && w[j] == 0 {
						rs = false
						break
					}
					if w[i] == 1 && w[j] == 0 {
						onlyi++
					}
					if w[i] == 0 && w[j] == 1 {
						onlyj++
					}
					if w[i] == 1 && w[j] == 1 {
						both++
					}
				}
				if !rs {
					continue
				}
				if onlyi+both < n/2 || onlyj+both < n/2 {
					continue
				}
				found = true
				break
			}
		}
		if found {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func rString() string {
	reader := bufio.NewScanner(os.Stdin)
	if !reader.Scan() {
		panic(reader.Err())
	}
	return reader.Text()
}

func rInt() (int64, error) {
	text := rString()
	n, _ := strconv.ParseInt(text, 10, 0)
	return n, nil
}

func main() {
	t, _ := rInt()
	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%d\n", &n)
		s := make([][5]byte, n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d %d %d %d %d\n", &s[i][0], &s[i][1], &s[i][2], &s[i][3], &s[i][4])
		}
		found := false
		for i := 0; i < 5; i++ {
			for j := i + 1; j < 5; j++ {
				rs := true
				var onlyi, onlyj, both int
				for _, w := range s {
					if w[i] == 0 && w[j] == 0 {
						rs = false
						break
					}
					if w[i] == 1 && w[j] == 0 {
						onlyi++
					}
					if w[i] == 0 && w[j] == 1 {
						onlyj++
					}
					if w[i] == 1 && w[j] == 1 {
						both++
					}
				}
				if !rs {
					continue
				}
				if onlyi+both < n/2 || onlyj+both < n/2 {
					continue
				}
				found = true
				break
			}
		}
		if found {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func rString() string {
	reader := bufio.NewScanner(os.Stdin)
	if !reader.Scan() {
		panic(reader.Err())
	}
	return reader.Text()
}

func rInt() (int64, error) {
	text := rString()
	n, _ := strconv.ParseInt(text, 10, 0)
	return n, nil
}

func main() {
	t, _ := rInt()
	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%d\n", &n)
		s := make([][5]byte, n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d %d %d %d %d\n", &s[i][0], &s[i][1], &s[i][2], &s[i][3], &s[i][4])
		}
		found := false
		for i := 0; i < 5; i++ {
			for j := i + 1; j < 5; j++ {
				rs := true
				var onlyi, onlyj, both int
				for q := 0; q < n; q++ {
					if s[q][i] == 0 && s[q][j] == 0 {
						rs = false
						break
					}
					if s[q][i] == 1 && s[q][j] == 0 {
						onlyi++
					}
					if s[q][i] == 0 && s[q][j] == 1 {
						onlyj++
					}
					if s[q][i] == 1 && s[q][j] == 1 {
						both++
					}
				}
				if !rs {
					continue
				}
				if onlyi+both < n/2 || onlyj+both < n/2 {
					continue
				}
				found = true
				break
			}
		}
		if found {
			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 n int
		fmt.Scanf("%d\n", &n)
		s := make([][5]byte, n)
		for i := 0; i < n; i++ {
			for j := 0; j < 5; j++ {
				fmt.Scanf("%d", &s[i][j])
			}
		}
		found := false
		for i := 0; i < 5; i++ {
			for j := i + 1; j < 5; j++ {
				rs := true
				var onlyi, onlyj, both int
				for q := 0; q < n; q++ {
					if s[q][i] == 0 && s[q][j] == 0 {
						rs = false
						break
					}
					if s[q][i] == 1 && s[q][j] == 0 {
						onlyi++
					}
					if s[q][i] == 0 && s[q][j] == 1 {
						onlyj++
					}
					if s[q][i] == 1 && s[q][j] == 1 {
						both++
					}
				}
				if !rs {
					continue
				}
				if onlyi+both < n/2 || onlyj+both < n/2 {
					continue
				}
				found = true
				break
			}
		}
		if found {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%d", &n)
		s := make([][5]byte, n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d %d %d %d %d\n", &s[i][0], &s[i][1], &s[i][2], &s[i][3], &s[i][4])
		}
		found := false
		for i := 0; i < 5; i++ {
			for j := i + 1; j < 5; j++ {
				rs := true
				var onlyi, onlyj, both int
				for q := 0; q < n; q++ {
					if s[q][i] == 0 && s[q][j] == 0 {
						rs = false
						break
					}
					if s[q][i] == 1 && s[q][j] == 0 {
						onlyi++
					}
					if s[q][i] == 0 && s[q][j] == 1 {
						onlyj++
					}
					if s[q][i] == 1 && s[q][j] == 1 {
						both++
					}
				}
				if !rs {
					continue
				}
				if onlyi+both < n/2 || onlyj+both < n/2 {
					continue
				}
				found = true
				break
			}
		}
		if found {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%d", &n)
		s := make([][5]byte, n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d %d %d %d %d\n", &s[i][0], &s[i][1], &s[i][2], &s[i][3], &s[i][4])
		}
		found := true
		for i := 0; i < 5; i++ {
			for j := i + 1; j < 5; j++ {
				rs := true
				var onlyi, onlyj, both int
				for q := 0; q < n; q++ {
					if s[q][i] == 0 && s[q][j] == 0 {
						rs = false
						break
					}
					if s[q][i] == 1 && s[q][j] == 0 {
						onlyi++
					}
					if s[q][i] == 0 && s[q][j] == 1 {
						onlyj++
					}
					if s[q][i] == 1 && s[q][j] == 1 {
						both++
					}
				}
				if !rs {
					continue
				}
				if onlyi+both < n/2 || onlyj+both < n/2 {
					continue
				}
				found = true
				break
			}
		}
		if found {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%d", &n)
		s := make([][5]byte, n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d %d %d %d %d\n", &s[i][0], &s[i][1], &s[i][2], &s[i][3], &s[i][4])
		}
		found := true
		for i := 0; i < 5; i++ {
			for j := i + 1; j < 5; j++ {
				rs := true
				var onlyi, onlyj, both int
				for q := 0; q < n; q++ {
					if s[q][i] == 0 && s[q][j] == 0 {
						rs = false
						break
					}
					if s[q][i] == 1 && s[q][j] == 0 {
						onlyi++
					}
					if s[q][i] == 0 && s[q][j] == 1 {
						onlyj++
					}
					if s[q][i] == 1 && s[q][j] == 1 {
						both++
					}
				}
				if !rs {
					continue
				}
				if onlyi+both < n/2 || onlyj+both < n/2 {
					continue
				}
				found = true
				break
			}
		}
		if found {
			fmt.Println("YES")
		}
		fmt.Println("NO")
	}
}

package main

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

func readInt() (int, error) {
	reader := bufio.NewReader(os.Stdin)
	var n int
	_, err := fmt.Fscan(reader, &n)
	return n, err
}

func readInt64() (int64, error) {
	reader := bufio.NewReader(os.Stdin)
	var n int
	_, err := fmt.Fscan(reader, &n)
	return int64(n), err
}

func main() {
	t, _ := readInt()
	for ; t > 0; t-- {
		n, _ := readInt64()
		fmt.Printf("%d %d\n", 1-n, n)
	}
}

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

var t, n int
var a [1005][5]int

func testcase() bool {
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		for j := 0; j < 5; j++ {
			scanf("%d ", &a[i][j])
		}
	}
	for i := 0; i < 5; i++ {
		for j := i + 1; j < 5; j++ {
			var cnt [3]int
			can := true
			for k := 0; k < n; k++ {
				if a[k][i] == a[k][j] {
					if a[k][i] == 0 {
						can = false
						break
					}
					cnt[2]++
				} else {
					if a[k][i] == 1 {
						cnt[0]++
					} else {
						cnt[1]++
					}
				}
			}
			if cnt[0] < cnt[1] {
				tmp := cnt[1] - cnt[0]
				cnt[0] += tmp
				cnt[2] -= tmp
			} else {
				tmp := cnt[0] - cnt[1]
				cnt[1] += tmp
				cnt[2] -= tmp
			}
			if cnt[2] < 0 {
				can = false
			}
			cnt[0] += cnt[2] / 2
			cnt[1] += cnt[2] / 2
			// fmt.Println(i, j, cnt)
			if cnt[0] == cnt[1] && cnt[0]+cnt[1] == n && can {
				return true
			}
		}
	}
	return false
}

func main() {
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		// writer.Flush()
		cur := testcase()
		// fmt.Println(cur)
		if cur {
			// printf("YES\n")
			fmt.Println("YES")
		} else {
			// printf("NO\n")
			fmt.Println("NO")
		}
		// writer.Flush()
	}

}

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

var t, n int
var a [1005][5]int

func testcase() bool {
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		for j := 0; j < 5; j++ {
			scanf("%d ", &a[i][j])
		}
	}
	for i := 0; i < 5; i++ {
		for j := i + 1; j < 5; j++ {
			var cnt [3]int
			can := true
			for k := 0; k < n; k++ {
				if a[k][i] == a[k][j] {
					if a[k][i] == 0 {
						can = false
						break
					}
					cnt[2]++
				} else {
					if a[k][i] == 1 {
						cnt[0]++
					} else {
						cnt[1]++
					}
				}
			}
			if cnt[0] < cnt[1] {
				tmp := cnt[1] - cnt[0]
				cnt[0] += tmp
				cnt[2] -= tmp
			} else {
				tmp := cnt[0] - cnt[1]
				cnt[1] += tmp
				cnt[2] -= tmp
			}
			if cnt[2] < 0 {
				can = false
			}
			cnt[0] += cnt[2] / 2
			cnt[1] += cnt[2] / 2
			// fmt.Println(i, j, cnt)
			if cnt[0] == cnt[1] && cnt[0]+cnt[1] == n && can {
				return true
			}
		}
	}
	return false
}

func main() {
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		// writer.Flush()
		cur := testcase()
		// fmt.Println(cur)
		if cur {
			// printf("YES\n")
			fmt.Println("YES")
		} else {
			// printf("NO\n")
			fmt.Println("NO")
		}
		// writer.Flush()
	}

}

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

var t, n int
var a [1005][5]int

func testcase() bool {
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		for j := 0; j < 5; j++ {
			scanf("%d ", &a[i][j])
		}
	}
	for i := 0; i < 5; i++ {
		for j := i + 1; j < 5; j++ {
			var cnt [3]int
			can := true
			for k := 0; k < n; k++ {
				if a[k][i] == a[k][j] {
					if a[k][i] == 0 {
						can = false
						break
					}
					cnt[2]++
				} else {
					if a[k][i] == 1 {
						cnt[0]++
					} else {
						cnt[1]++
					}
				}
			}
			if cnt[0] < cnt[1] {
				tmp := cnt[1] - cnt[0]
				cnt[0] += tmp
				cnt[2] -= tmp
			} else {
				tmp := cnt[0] - cnt[1]
				cnt[1] += tmp
				cnt[2] -= tmp
			}
			if cnt[2] < 0 {
				can = false
			}
			cnt[0] += cnt[2] / 2
			cnt[1] += cnt[2] / 2
			// fmt.Println(i, j, cnt)
			if cnt[0] == cnt[1] && cnt[0]+cnt[1] == n && can {
				return true
			}
		}
	}
	return false
}

func main() {
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		writer.Flush()
		cur := testcase()
		// fmt.Println(cur)
		if cur {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
		writer.Flush()
	}

}

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

var t, n int
var a [1005][5]int

func testcase() bool {
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		for j := 0; j < 5; j++ {
			scanf("%d ", &a[i][j])
		}
	}
	for i := 0; i < 5; i++ {
		for j := i + 1; j < 5; j++ {
			var cnt [3]int
			can := true
			for k := 0; k < n; k++ {
				if a[k][i] == a[k][j] {
					if a[k][i] == 0 {
						can = false
						break
					}
					cnt[2]++
				} else {
					if a[k][i] == 1 {
						cnt[0]++
					} else {
						cnt[1]++
					}
				}
			}
			if cnt[0] < cnt[1] {
				tmp := cnt[1] - cnt[0]
				cnt[0] += tmp
				cnt[2] -= tmp
			} else {
				tmp := cnt[0] - cnt[1]
				cnt[1] += tmp
				cnt[2] -= tmp
			}
			if cnt[2] < 0 {
				can = false
			}
			cnt[0] += cnt[2] / 2
			cnt[1] += cnt[2] / 2
			// fmt.Println(i, j, cnt)
			if cnt[0] == cnt[1] && cnt[0]+cnt[1] == n && can {
				return true
			}
		}
	}
	return false
}

func main() {
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		cur := testcase()
		// fmt.Println(cur)
		if cur {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
		writer.Flush()
	}

}

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

var t, n int
var a [1005][5]int

func testcase() bool {
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		for j := 0; j < 5; j++ {
			scanf("%d ", &a[i][j])
		}
	}
	for i := 0; i < 5; i++ {
		for j := i + 1; j < 5; j++ {
			var cnt [3]int
			can := true
			for k := 0; k < n; k++ {
				if a[k][i] == a[k][j] {
					if a[k][i] == 0 {
						can = false
						break
					}
					cnt[2]++
				} else {
					if a[k][i] == 1 {
						cnt[0]++
					} else {
						cnt[1]++
					}
				}
			}
			if cnt[0] < cnt[1] {
				tmp := cnt[1] - cnt[0]
				cnt[0] += tmp
				cnt[2] -= tmp
			} else {
				tmp := cnt[0] - cnt[1]
				cnt[1] += tmp
				cnt[2] -= tmp
			}
			if cnt[2] < 0 {
				can = false
			}
			cnt[0] += cnt[2] / 2
			cnt[1] += cnt[2] / 2
			// fmt.Println(i, j, cnt)
			if cnt[0] == cnt[1] && cnt[0]+cnt[1] == n && can {
				return true
			}
		}
	}
	return false
}

func main() {
	defer writer.Flush()
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		cur := testcase()
		if cur {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}

}

package main

import (
	"fmt"
)

var t, n int
var a [1005][5]int

func testcase() bool {
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		for j := 0; j < 5; j++ {
			fmt.Scan(&a[i][j])
		}
	}
	for i := 0; i < 5; i++ {
		for j := i + 1; j < 5; j++ {
			var cnt [3]int
			cur := true
			for k := 0; k < n; k++ {
				if a[k][i] == a[k][j] {
					if a[k][i] == 0 {
						cur = false
						break
					}
					cnt[2]++
				} else {
					if a[k][i] == 1 {
						cnt[0]++
					} else {
						cnt[1]++
					}
				}
			}
			tmp := cnt[2] / 2
			if cnt[0] < cnt[1] {
				cnt[1] += tmp
				cnt[0] += cnt[2] - tmp
			} else {
				cnt[0] += tmp
				cnt[1] += cnt[2] - tmp
			}
			// fmt.Println(i, j, cnt)
			if cnt[0] == cnt[1] && cnt[0]+cnt[1] == n && cur {
				return true
			}
		}
	}
	return false
}

func main() {
	fmt.Scan(&t)
	for ; t > 0; t-- {
		cur := testcase()
		if cur {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}

}

package main

import (
	"fmt"
)

func testcase() bool {
	var n int
	fmt.Scan(&n)
	a := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, 5)
		for j := 0; j < 5; j++ {
			fmt.Scan(&a[i][j])
		}
	}
	for i := 0; i < 5; i++ {
		for j := i + 1; j < 5; j++ {
			var cnt [3]int
			cur := true
			for k := 0; k < n; k++ {
				if a[k][i] == a[k][j] {
					if a[k][i] == 0 {
						cur = false
						break
					}
					cnt[2]++
				} else {
					if a[k][i] == 1 {
						cnt[0]++
					} else {
						cnt[1]++
					}
				}
			}
			tmp := cnt[2] / 2
			if cnt[0] < cnt[1] {
				cnt[1] += tmp
				cnt[0] += cnt[2] - tmp
			} else {
				cnt[0] += tmp
				cnt[1] += cnt[2] - tmp
			}
			// fmt.Println(i, j, cnt)
			if cnt[0] == cnt[1] && cnt[0]+cnt[1] == n && cur {
				return true
			}
		}
	}
	return false
}

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		cur := testcase()
		if cur {
			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)

		c := make([][5]int, n)
		for i := 0; i < n; i++ {
			for j := 0; j < 5; j++ {
				fmt.Fscan(in, &c[i][j])
			}
		}

		var isValid bool
		for i := 0; i < 5; i++ {
			for j := 0; j < 5; j++ {
				if i == j {
					continue
				}

				var c1, c2, cx int
				for _, p := range c {
					if p[i] == 1 {
						c1++
					} else if p[j] == 1 {
						c2++
					} else if p[i] == 0 && p[j] == 0 {
						cx++
					}
				}

				if c1 >= n/2 && c2 >= n/2 && cx == 0 {
					isValid = true
					break
				}
			}
		}

		if !isValid {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

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)

		c := make([][]int, 5)
		for i := 0; i < n; i++ {
			for j := 0; j < 5; j++ {
				var v int
				fmt.Fscan(in, &v)

				if v == 1 {
					c[j] = append(c[j], i)
				}
			}
		}

		var isValid bool
		for i := 0; i < 5; i++ {
			if len(c[i]) < n/2 {
				continue
			}

			for j := 0; j < 5; j++ {
				if i == j || len(c[j]) < n/2 {
					continue
				}

				var tally int
				for _, v := range c[j] {
					idx := sort.SearchInts(c[i], v)
					if idx >= len(c[i]) || c[i][idx] != v {
						tally++
					}
				}

				if tally >= n/2 {
					isValid = true
					break
				}
			}
		}
		if !isValid {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

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)

		c := make([][]int, 5)
		for i := 0; i < n; i++ {
			for j := 0; j < 5; j++ {
				var v int
				fmt.Fscan(in, &v)

				if v == 1 {
					c[j] = append(c[j], i)
				}
			}
		}

		var isValid bool
		for i := 0; i < 4; i++ {
			if len(c[i]) < n/2 {
				continue
			}

			for j := i + 1; j < 5; j++ {
				if len(c[j]) < n/2 {
					continue
				}

				var tally int
				for _, v := range c[j] {
					idx := sort.SearchInts(c[i], v)
					if idx >= len(c[i]) || c[i][idx] != v {
						tally++
					}
				}

				if tally >= n/2 {
					isValid = true
					break
				}
			}
		}
		if !isValid {
			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)

		c := make([]int, 5)
		for i := 0; i < n; i++ {
			for j := 0; j < 5; j++ {
				var v int
				fmt.Fscan(in, &v)

				if v == 1 {
					c[j]++
				}
			}
		}

		var isValid bool
		for i := 0; i < 4; i++ {
			if c[i] < n/2 {
				continue
			}

			for j := i + 1; j < 5; j++ {
				if c[j] >= n/2 {
					isValid = true
					break
				}
			}
		}
		if !isValid {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

import "fmt"

const (
	MaxN = 1005
	MaxDay = 5
)

var (
	T, n int
	a [MaxN][MaxDay]int
)

func main() {
	_, _ = fmt.Scan(&T)
	for ; T > 0; T-- {
		_, _ = fmt.Scan(&n)

		for i := 0; i < n; i++ {
			for j := 0; j < MaxDay; j++ {
				_, _ = fmt.Scan(&a[i][j])
			}
		}

		ans := "NO"
		for j1 := 0; j1 < MaxDay; j1++ {
			for j2 := j1 + 1; j2 < MaxDay; j2++ {
				x, y := 0, 0
				for i := 0; i < n; i++ {
					if a[i][j1] == 0 && a[i][j2] == 0 {
						break
					}
					x += a[i][j1]
					y += a[i][j2]
				}
				if x >= n / 2 && y >= n / 2 {
					ans = "YES"
				}
			}
		}

		fmt.Println(ans)
	}
}