You are given a permutation $$$p$$$ of integers from $$$0$$$ to $$$n-1$$$ (each of them occurs exactly once). Initially, the permutation is not sorted (that is, $$$p_i>p_{i+1}$$$ for at least one $$$1 \le i \le n - 1$$$). The permutation is called $$$X$$$-sortable for some non-negative integer $$$X$$$ if it is possible to sort the permutation by performing the operation below some finite number of times:   Choose two indices $$$i$$$ and $$$j$$$ $$$(1 \le i \lt j \le n)$$$ such that $$$p_i \& p_j = X$$$.  Swap $$$p_i$$$ and $$$p_j$$$. Here $$$\&$$$ denotes the bitwise AND operation.Find the maximum value of $$$X$$$ such that $$$p$$$ is $$$X$$$-sortable. It can be shown that there always exists some value of $$$X$$$ such that $$$p$$$ is $$$X$$$-sortable.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \le t \le 10^4)$$$  — the number of test cases. Description of test cases follows. The first line of each test case contains a single integer $$$n$$$ $$$(2 \le n \le 2 \cdot 10^5)$$$  — the length of the permutation. The second line of each test case contains $$$n$$$ integers $$$p_1, p_2, ..., p_n$$$ ($$$0 \le p_i \le n-1$$$, all $$$p_i$$$ are distinct)  — the elements of $$$p$$$. It is guaranteed that $$$p$$$ is not sorted. It is guaranteed that the sum of $$$n$$$ over all cases does not exceed $$$2 \cdot 10^5$$$.

For each test case output a single integer — the maximum value of $$$X$$$ such that $$$p$$$ is $$$X$$$-sortable.

package main

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

func main() {

	var T int
	var N int
	var x int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &T)
	for T > 0 {
		fmt.Fscan(in, &N)
		ans := (1 << 30) - 1
		for i := 0; i < N; i++ {
			fmt.Fscan(in, &x)
			if x != i {
				ans &= x
			}
		}
		fmt.Println(ans)
		T--
	}
}

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}

func solve() {
	var n int
	scan(&n)
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		scan(&a[i])
	}
	copy(b, a)
	sort.Slice(b, func(i, j int) bool {
		return b[i] < b[j]
	})
	ans := 0xffffffff
	for i := 0; i < n; i++ {
		if a[i] != b[i] {
			// printf("%d %d\n", a[i], b[i])
			ans &= a[i]
		}
	}
	printf("%d\n", ans)
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var ntests int
	fmt.Fscan(scanner, &ntests)
	for iter := 0; iter < ntests; iter++ {
		var n int
		fmt.Fscan(scanner, &n)
		//slice := make([]int, n)
		res := 1024*1024 - 1
		for i := 0; i < n; i++ {
			var tmp int
			fmt.Fscan(scanner, &tmp)
			if tmp != i {
				res = res & tmp
			}
		}
		fmt.Fprintln(writer, res)
	}
}

package main

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

package main

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

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

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

		}
		Fprintln(out, k-j-1) */
		/* T_b */
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		var g []int
		for i := 0; i < n; i++ {
			if a[i] != i {
				g = append(g, a[i])
			}
		}
		cnt := make([]int, 20)
		for i := 0; i < len(g); i++ {
			x := g[i]
			for k := 0; k < 20; k++ {
				if (x & (1 << k)) != 0 {
					cnt[k]++
				}
			}
		}
		var ans int
		for i := 0; i < 20; i++ {
			if cnt[i] == len(g) {
				ans += (1 << i)
			}
		}
		Fprintln(out, ans)
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A() }

package main

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

type Int int64

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

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

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var n, x Int
		Fscan(in, &n)

		k := -L1
		for i := L0; i < n; i++ {
			Fscan(in, &x)
			if x != i {
				if k == -1 {
					k = x
				} else {
					k = k & x
				}
			}
		}
		Fprintln(out, k)

	}

}

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

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

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

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

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

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

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

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

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

func doNothing(m Int) Int {
	return m
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}

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

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

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

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

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

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

type SegTree struct {
	st []Segment
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	id := L0

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

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

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

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

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	for t := io.ReadInt(); t > 0; t-- {
		n := io.ReadInt()
		a := io.ReadIntSlice(n)

		ans := 1<<30 - 1

		for i := 0; i < n; i++ {
			if a[i] != i {
				ans &= i
			}
		}

		fmt.Println(ans)
	}
}


Kuroni has $$$n$$$ daughters. As gifts for them, he bought $$$n$$$ necklaces and $$$n$$$ bracelets:  the $$$i$$$-th necklace has a brightness $$$a_i$$$, where all the $$$a_i$$$ are pairwise distinct (i.e. all $$$a_i$$$ are different),  the $$$i$$$-th bracelet has a brightness $$$b_i$$$, where all the $$$b_i$$$ are pairwise distinct (i.e. all $$$b_i$$$ are different). Kuroni wants to give exactly one necklace and exactly one bracelet to each of his daughters. To make sure that all of them look unique, the total brightnesses of the gifts given to each daughter should be pairwise distinct. Formally, if the $$$i$$$-th daughter receives a necklace with brightness $$$x_i$$$ and a bracelet with brightness $$$y_i$$$, then the sums $$$x_i + y_i$$$ should be pairwise distinct. Help Kuroni to distribute the gifts.For example, if the brightnesses are $$$a = [1, 7, 5]$$$ and $$$b = [6, 1, 2]$$$, then we may distribute the gifts as follows:  Give the third necklace and the first bracelet to the first daughter, for a total brightness of $$$a_3 + b_1 = 11$$$. Give the first necklace and the third bracelet to the second daughter, for a total brightness of $$$a_1 + b_3 = 3$$$. Give the second necklace and the second bracelet to the third daughter, for a total brightness of $$$a_2 + b_2 = 8$$$. Here is an example of an invalid distribution:   Give the first necklace and the first bracelet to the first daughter, for a total brightness of $$$a_1 + b_1 = 7$$$. Give the second necklace and the second bracelet to the second daughter, for a total brightness of $$$a_2 + b_2 = 8$$$. Give the third necklace and the third bracelet to the third daughter, for a total brightness of $$$a_3 + b_3 = 7$$$. This distribution is invalid, as the total brightnesses of the gifts received by the first and the third daughter are the same. Don't make them this upset!

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$)  — the number of daughters, necklaces and bracelets. The second line of each test case contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 1000$$$)  — the brightnesses of the necklaces. The third line of each test case contains $$$n$$$ distinct integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 1000$$$)  — the brightnesses of the bracelets.

For each test case, print a line containing $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$, representing that the $$$i$$$-th daughter receives a necklace with brightness $$$x_i$$$. In the next line print $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$, representing that the $$$i$$$-th daughter receives a bracelet with brightness $$$y_i$$$. The sums $$$x_1 + y_1, x_2 + y_2, \dots, x_n + y_n$$$ should all be distinct. The numbers $$$x_1, \dots, x_n$$$ should be equal to the numbers $$$a_1, \dots, a_n$$$ in some order, and the numbers $$$y_1, \dots, y_n$$$ should be equal to the numbers $$$b_1, \dots, b_n$$$ in some order.  It can be shown that an answer always exists. If there are multiple possible answers, you may print any of them.

NoteIn the first test case, it is enough to give the $$$i$$$-th necklace and the $$$i$$$-th bracelet to the $$$i$$$-th daughter. The corresponding sums are $$$1 + 8 = 9$$$, $$$8 + 4 = 12$$$, and $$$5 + 5 = 10$$$.The second test case is described in the statement.

package main

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

func main() {
	handleCases(os.Stdin)
}

func handleCases(f io.Reader) {
	cases, err := scanner(f)
	if err != nil {
		panic(err)
	}

	var (
		xi, yi []int
	)

	for _, tc := range cases {
		xi, yi, err = algo(tc)
		if err != nil {
			panic(err)
		}

		fmt.Println(joinInt(xi))
		fmt.Println(joinInt(yi))
	}
}

func algo(in *input) ([]int, []int, error) {
	var (
		ai, bi []int
	)

	ai, bi = simple(in)
	if check(ai, bi) {
		return ai, bi, nil
	}

	ai, bi = ssort(in)
	if check(ai, bi) {
		return ai, bi, nil
	}

	return nil, nil, errors.New("no solution")
}

func simple(in *input) ([]int, []int) {
	return in.OzherYar, in.BrasYar
}

func ssort(in *input) ([]int, []int) {
	return sortArr(in.OzherYar), sortArr(in.BrasYar)
}

type arr []int

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

func sortArr(in []int) []int {
	ai := make([]int, 0, len(in))

	for _, i := range in {
		ai = append(ai, i)
	}

	sort.Sort(arr(ai))

	return ai
}

// true - корректно
func check(ai, bi []int) bool {
	m := map[int]struct{}{}

	var s int

	for i, _ := range ai {
		s = ai[i] + bi[i]

		_, ok := m[s]
		if ok {
			return false
		}

		m[s] = struct{}{}
	}

	return true
}

type input struct {
	DaughterCount int
	OzherYar      []int
	BrasYar       []int
}

func scanner(f io.Reader) ([]*input, error) {
	scanner := bufio.NewScanner(f)

	naborCount := true
	daughterCountLine := true
	ozherYarLine := true
	brasYarLine := true

	var (
		tmpItem *input
		tmpArr  []int
		tmpI    int
		err     error
	)

	var i []*input

	for scanner.Scan() {
		if naborCount {
			naborCount = false

			tmpI, err = parseInt(scanner.Text())
			if err != nil {
				return nil, err
			}

			i = make([]*input, 0, tmpI)

			continue
		}
		if daughterCountLine {
			daughterCountLine = false

			tmpItem = new(input)

			tmpI, err = parseInt(scanner.Text())
			if err != nil {
				return nil, err
			}

			tmpItem.DaughterCount = tmpI

			continue
		}

		if ozherYarLine {
			ozherYarLine = false
			tmpArr, err = parseIntArr(scanner.Text())
			if err != nil {
				return nil, err
			}

			tmpItem.OzherYar = tmpArr

			continue
		}

		if brasYarLine {
			brasYarLine = false

			tmpArr, err = parseIntArr(scanner.Text())
			if err != nil {
				return nil, err
			}

			tmpItem.BrasYar = tmpArr

			if tmpItem.DaughterCount != len(tmpItem.OzherYar) || tmpItem.DaughterCount != len(tmpItem.BrasYar) {
				fmt.Println(tmpItem)
				return nil, errors.New("validation error")
			}

			i = append(i, tmpItem)

			daughterCountLine = true
			ozherYarLine = true
			brasYarLine = true

			continue
		}

		break
	}

	if err := scanner.Err(); err != nil {
		return nil, err
	}

	return i, nil
}

func parseIntArr(line string) ([]int, error) {
	words := strings.Split(line, " ")
	arr := make([]int, 0, len(words))

	for _, word := range words {
		i, err := parseInt(word)
		if err != nil {
			return nil, err
		}

		arr = append(arr, i)
	}

	return arr, nil
}

func parseInt(line string) (int, error) {
	i, err := strconv.ParseInt(line, 10, 64)
	if err != nil {
		return 0, err
	}

	return int(i), nil
}

func joinInt(in []int) string {
	b := strings.Builder{}
	sep := " "

	for i, r := range in {
		if i != 0 {
			b.WriteString(sep)
		}

		b.WriteString(fmt.Sprintf("%d", r))
	}

	return b.String()
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	T := NextInt()
	for t := 0; t < T; t++ {
		n := NextInt()
		x := make([]int, n)
		for i := 0; i < n; i++ {
			x[i] = NextInt()
		}
		y := make([]int, n)
		for i := 0; i < n; i++ {
			y[i] = NextInt()
		}
		sort.Ints(x)
		sort.Ints(y)
		for i := 0; i < n; i++ {
			fmt.Fprint(out, x[i], " ")
		}
		fmt.Fprintln(out)
		for i := 0; i < n; i++ {
			fmt.Fprint(out, y[i], " ")
		}
		fmt.Fprintln(out)
	}
}

// https://codeforces.com/contest/1352/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

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

	sort.Slice(a, func(i, j int) bool {return a[i] < a[j]})
	sort.Slice(b, func(i, j int) bool {return b[i] < b[j]})

	for i := 0; i < n; i++ {
		if i > 0 {
			fmt.Print(" ")
		}
		fmt.Print(a[i])
	}
	fmt.Println()

	for i := 0; i < n; i++ {
		if i > 0 {
			fmt.Print(" ")
		}
		fmt.Print(b[i])
	}
	fmt.Println()
}

package main

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

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		n, _ := strconv.Atoi(string(line))
		line = readLine(reader)
		ans := strings.Split(string(line), " ")
		line = readLine(reader)
		bns := strings.Split(string(line), " ")
		an := make([]int, n)
		bn := make([]int, n)
		for i := 0; i < n; i++ {
			an[i], _ = strconv.Atoi(ans[i])
			bn[i], _ = strconv.Atoi(bns[i])
		}
		sort.Ints(an)
		sort.Ints(bn)
		for _, i := range an {
			fmt.Printf("%d ", i)
		}
		fmt.Println()
		for _, i := range bn {
			fmt.Printf("%d ", i)
		}
	}
}

func printList(an []int) {

}

package main

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

func main(){
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t,n int
	fmt.Scan(&t)
	for ;t>0;t--{
		fmt.Scan(&n)
		ne:= make([]int,n)
		b := make([]int,n)
		readN(ne,0,n)
		readN(b,0,n)
		sort.Ints(ne)
		sort.Ints(b)
		for _,v := range ne {
			fmt.Fprintf(out,"%d ",v)
		}
		fmt.Fprintf(out,"\n")
		for _,v := range b {
			fmt.Fprintf(out,"%d ",v)
		}
		fmt.Fprintf(out,"\n")

	}

}

func readN(all []int,i,n int){
	if n==0{
		return
	}
	if m,err := fmt.Scan(&all[i]);m!=1{
		panic(err)
	}
	readN(all,i+1,n-1)
}

package main

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

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

	solve := func() {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		b := make([]int, n)
		for i := range b {
			Fscan(in, &b[i])
		}
		sort.Ints(a)
		sort.Ints(b)
		for i, v := range a {
			if i > 0 {
				Fprint(out, " ")
			}
			Fprint(out, v)
		}
		Fprintln(out)
		for i, v := range b {
			if i > 0 {
				Fprint(out, " ")
			}
			Fprint(out, v)
		}
		Fprintln(out)

		return
	}

	var t int
	Fscan(in, &t)
	for _case := 1; _case <= t; _case++ {
		solve()
	}
}

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

package main

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

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main(){
	for testCases := ScanInt64(); testCases > 0; testCases--{
		numberOfDaughters := ScanInt()
		necklessBrightnessArray := ScanIntSlice(numberOfDaughters)
		braceletBrightnessArray := ScanIntSlice(numberOfDaughters)

		sort.Ints(necklessBrightnessArray)
		sort.Ints(braceletBrightnessArray)

		var IDs []string
		var IDs2 []string
		for _, i := range necklessBrightnessArray {
			IDs = append(IDs, strconv.Itoa(i))
		}
		for _, i := range braceletBrightnessArray {
			IDs2 = append(IDs2, strconv.Itoa(i))
		}

		fmt.Println(strings.Join(IDs, " "))
		fmt.Println(strings.Join(IDs2, " "))

	}
	close(O)
	oWg.Wait()
}

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

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

func init() {
	Pl = fmt.Println

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

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

	writer := bufio.NewWriterSize(os.Stdout, int(1e5))
	go func(writer *bufio.Writer) {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int64) []string {
	length := int(n)
	s := make([]string, n)
	for i := 0; i < length; i++ {
		s[i] = ScanWord()
	}
	return s
}

func ScanInt64() int64 {
	intStr := ScanWord()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt() int {
	intStr := ScanWord()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int64) []int64 {
	length := int(n)
	arr := make([]int64, n)
	for i := 0; i < length; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

func ScanIntSlice(n int) []int {
	length := int(n)
	arr := make([]int, n)
	for i := 0; i < length; i++ {
		arr[i] = ScanInt()
	}
	return arr
}

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

func Mx(args ...int64) int64 {
	maxVal := MN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Mn(args ...int64) int64 {
	minVal := MX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func LCM(a, b int64) int64 {
	return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}

func S(v interface{}) string {
	return fmt.Sprintf("%v", v)
}

package main
import (
	"bufio"
	"fmt"
	"os"
	"sort"
)
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)
		a := make([]int, n)
		b := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(r, &a[j])
		}
		for j := 0; j < n; j++ {
			fmt.Fscan(r, &b[j])
		}
		sort.Ints(a)
		sort.Ints(b)
		for j := 1; j < n; j++ {
			if a[j] + b[j] == a[j-1] + b[j-1] {
				b[j], b[j-1] = b[j-1],b[j]
			}
		}
		for j, e := range a {
			if j == 0 {
				fmt.Fprint(w,e)
			} else {
				fmt.Fprint(w," ", e)
			}
		}
		fmt.Fprintln(w)
		for j, e := range b {
			if j == 0 {
				fmt.Fprint(w, e)
			} else {
				fmt.Fprint(w," ", e)
			}
		}
		fmt.Fprintln(w)
	}
}

package main

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

func main() {
	handleCases(os.Stdin)
}

func handleCases(f io.Reader) {
	cases, err := scanner(f)
	if err != nil {
		panic(err)
	}

	for _, tc := range cases {
		xi, yi, err := algo(tc)
		if err != nil {
			panic(err)
		}

		fmt.Println(joinInt(xi))
		fmt.Println(joinInt(yi))
	}
}

func algo(in *input) ([]int, []int, error) {
	var (
		ai, bi []int
	)

	ai, bi = simple(in)
	if check(ai, bi) {
		return ai, bi, nil
	}

	ai, bi = reverse(in)
	if check(ai, bi) {
		return ai, bi, nil
	}

	return nil, nil, errors.New("no solution")
}

func simple(in *input) ([]int, []int) {
	return in.OzherYar, in.BrasYar
}

func reverse(in *input) ([]int, []int) {
	ai := make([]int, 0, in.DaughterCount)

	for i := in.DaughterCount - 1; i == 0; i-- {
		ai = append(ai, in.OzherYar[i])
	}

	return ai, in.BrasYar
}

// true - корректно
func check(ai, bi []int) bool {
	m := map[int]struct{}{}

	var s int

	for i, _ := range ai {
		s = ai[i] + bi[i]

		_, ok := m[s]
		if ok {
			return false
		}

		m[s] = struct{}{}
	}

	return true
}

type input struct {
	DaughterCount int
	OzherYar      []int
	BrasYar       []int
}

func scanner(f io.Reader) ([]*input, error) {
	scanner := bufio.NewScanner(f)

	naborCount := true
	daughterCountLine := true
	ozherYarLine := true
	brasYarLine := true

	var (
		tmpItem *input
		tmpArr  []int
		tmpI    int
		err     error
	)

	var i []*input

	for scanner.Scan() {
		if naborCount {
			naborCount = false

			tmpI, err = parseInt(scanner.Text())
			if err != nil {
				return nil, err
			}

			i = make([]*input, 0, tmpI)

			continue
		}
		if daughterCountLine {
			daughterCountLine = false

			tmpItem = new(input)

			tmpI, err = parseInt(scanner.Text())
			if err != nil {
				return nil, err
			}

			tmpItem.DaughterCount = tmpI

			continue
		}

		if ozherYarLine {
			ozherYarLine = false
			tmpArr, err = parseIntArr(scanner.Text())
			if err != nil {
				return nil, err
			}

			tmpItem.OzherYar = tmpArr

			continue
		}

		if brasYarLine {
			brasYarLine = false

			tmpArr, err = parseIntArr(scanner.Text())
			if err != nil {
				return nil, err
			}

			tmpItem.BrasYar = tmpArr

			if tmpItem.DaughterCount != len(tmpItem.OzherYar) || tmpItem.DaughterCount != len(tmpItem.BrasYar) {
				fmt.Println(tmpItem)
				return nil, errors.New("validation error")
			}

			i = append(i, tmpItem)

			daughterCountLine = true
			ozherYarLine = true
			brasYarLine = true

			continue
		}

		break
	}

	if err := scanner.Err(); err != nil {
		return nil, err
	}

	return i, nil
}

func parseIntArr(line string) ([]int, error) {
	words := strings.Split(line, " ")
	arr := make([]int, 0, len(words))

	for _, word := range words {
		i, err := parseInt(word)
		if err != nil {
			return nil, err
		}

		arr = append(arr, i)
	}

	return arr, nil
}

func parseInt(line string) (int, error) {
	i, err := strconv.ParseInt(line, 10, 64)
	if err != nil {
		return 0, err
	}

	return int(i), nil
}

func joinInt(in []int) string {
	b := strings.Builder{}
	sep := " "

	for i, r := range in {
		if i != 0 {
			b.WriteString(sep)
		}

		b.WriteString(fmt.Sprintf("%d", r))
	}

	return b.String()
}

package main

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

func main() {
	handleCases(os.Stdin)
}

func handleCases(f io.Reader) {
	cases, err := scanner(f)
	if err != nil {
		panic(err)
	}

	for _, tc := range cases {
		xi, yi, err := algo(tc)
		if err != nil {
			panic(err)
		}

		fmt.Println(joinInt(xi))
		fmt.Println(joinInt(yi))
	}
}

func algo(in *input) ([]int, []int, error) {
	var (
		ai, bi []int
	)

	ai, bi = simple(in)
	if check(ai, bi) {
		return ai, bi, nil
	}

	ai, bi = sort(in)
	if check(ai, bi) {
		return ai, bi, nil
	}

	ai, bi = reverse(in)
	if check(ai, bi) {
		return ai, bi, nil
	}

	return nil, nil, errors.New("no solution")
}

func simple(in *input) ([]int, []int) {
	return in.OzherYar, in.BrasYar
}

func sort(in *input) ([]int, []int) {
	return sortArr(in.OzherYar), sortArr(in.BrasYar)
}

func reverse(in *input) ([]int, []int) {
	ai := sortArr(in.OzherYar)
	bi := sortArr(sortArr(in.BrasYar))

	return ai, bi
}

func sortArr(in []int) []int {
	ai := make([]int, 0, len(in))

	for i := len(in) - 1; i == 0; i-- {
		ai = append(ai, in[i])
	}

	return ai
}

// true - корректно
func check(ai, bi []int) bool {
	m := map[int]struct{}{}

	var s int

	for i, _ := range ai {
		s = ai[i] + bi[i]

		_, ok := m[s]
		if ok {
			return false
		}

		m[s] = struct{}{}
	}

	return true
}

type input struct {
	DaughterCount int
	OzherYar      []int
	BrasYar       []int
}

func scanner(f io.Reader) ([]*input, error) {
	scanner := bufio.NewScanner(f)

	naborCount := true
	daughterCountLine := true
	ozherYarLine := true
	brasYarLine := true

	var (
		tmpItem *input
		tmpArr  []int
		tmpI    int
		err     error
	)

	var i []*input

	for scanner.Scan() {
		if naborCount {
			naborCount = false

			tmpI, err = parseInt(scanner.Text())
			if err != nil {
				return nil, err
			}

			i = make([]*input, 0, tmpI)

			continue
		}
		if daughterCountLine {
			daughterCountLine = false

			tmpItem = new(input)

			tmpI, err = parseInt(scanner.Text())
			if err != nil {
				return nil, err
			}

			tmpItem.DaughterCount = tmpI

			continue
		}

		if ozherYarLine {
			ozherYarLine = false
			tmpArr, err = parseIntArr(scanner.Text())
			if err != nil {
				return nil, err
			}

			tmpItem.OzherYar = tmpArr

			continue
		}

		if brasYarLine {
			brasYarLine = false

			tmpArr, err = parseIntArr(scanner.Text())
			if err != nil {
				return nil, err
			}

			tmpItem.BrasYar = tmpArr

			if tmpItem.DaughterCount != len(tmpItem.OzherYar) || tmpItem.DaughterCount != len(tmpItem.BrasYar) {
				fmt.Println(tmpItem)
				return nil, errors.New("validation error")
			}

			i = append(i, tmpItem)

			daughterCountLine = true
			ozherYarLine = true
			brasYarLine = true

			continue
		}

		break
	}

	if err := scanner.Err(); err != nil {
		return nil, err
	}

	return i, nil
}

func parseIntArr(line string) ([]int, error) {
	words := strings.Split(line, " ")
	arr := make([]int, 0, len(words))

	for _, word := range words {
		i, err := parseInt(word)
		if err != nil {
			return nil, err
		}

		arr = append(arr, i)
	}

	return arr, nil
}

func parseInt(line string) (int, error) {
	i, err := strconv.ParseInt(line, 10, 64)
	if err != nil {
		return 0, err
	}

	return int(i), nil
}

func joinInt(in []int) string {
	b := strings.Builder{}
	sep := " "

	for i, r := range in {
		if i != 0 {
			b.WriteString(sep)
		}

		b.WriteString(fmt.Sprintf("%d", r))
	}

	return b.String()
}


You are given a sequence $$$s$$$ consisting of $$$n$$$ digits from $$$1$$$ to $$$9$$$.You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) in such a way that each element belongs to exactly one segment and if the resulting division will be represented as an integer numbers sequence then each next element of this sequence will be strictly greater than the previous one.More formally: if the resulting division of the sequence is $$$t_1, t_2, \dots, t_k$$$, where $$$k$$$ is the number of element in a division, then for each $$$i$$$ from $$$1$$$ to $$$k-1$$$ the condition $$$t_{i} < t_{i + 1}$$$ (using numerical comparing, it means that the integer representations of strings are compared) should be satisfied.For example, if $$$s=654$$$ then you can divide it into parts $$$[6, 54]$$$ and it will be suitable division. But if you will divide it into parts $$$[65, 4]$$$ then it will be bad division because $$$65 > 4$$$. If $$$s=123$$$ then you can divide it into parts $$$[1, 23]$$$, $$$[1, 2, 3]$$$ but not into parts $$$[12, 3]$$$.Your task is to find any suitable division for each of the $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 300$$$) — the number of queries. The first line of the $$$i$$$-th query contains one integer number $$$n_i$$$ ($$$2 \le n_i \le 300$$$) — the number of digits in the $$$i$$$-th query. The second line of the $$$i$$$-th query contains one string $$$s_i$$$ of length $$$n_i$$$ consisting only of digits from $$$1$$$ to $$$9$$$.

If the sequence of digits in the $$$i$$$-th query cannot be divided into at least two parts in a way described in the problem statement, print the single line "NO" for this query. Otherwise in the first line of the answer to this query print "YES", on the second line print $$$k_i$$$ — the number of parts in your division of the $$$i$$$-th query sequence and in the third line print $$$k_i$$$ strings $$$t_{i, 1}, t_{i, 2}, \dots, t_{i, k_i}$$$ — your division. Parts should be printed in order of the initial string digits. It means that if you write the parts one after another without changing their order then you'll get the string $$$s_i$$$. See examples for better understanding.

package main

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

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

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

func main() {
	//STDOUT MUST BE FLUSHED MANUALLY
	defer writer.Flush()

	var n, len, num int
	var d string
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		scanf("%d\n", &len)
		scanf("%s\n", &d)
		// printf("len: %v, data: %v\n", len, d)
		if len > 2 {
			printf("YES\n")
			printf("2\n")
			printf("%v %v\n", d[:1], d[1:])
			continue
		}
		num, _ = strconv.Atoi(d)
		if num / 10 >= num % 10 {
			printf("NO\n")
			continue
		}
		printf("YES\n")
		printf("2\n")
		printf("%v %v\n", d[:1], d[1:])
	}
	// printf("%d\n", a+b)
}

package main

import (
	"fmt"
	//"strconv"
)

func main() {
	var t int
	fmt.Scanf("%d ", &t)
	for i := 0; i < t; i++ {
		//var k int64

		var s string
		fmt.Scanf("%s ", &s)
		fmt.Scanf("%s ", &s)
		//fmt.Println(string('#'), s)
		if len(s) == 2 && s[0] >= s[1] {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			fmt.Println("2")
			s = s[0:1] + string(' ') + s[1:]
			fmt.Println(s)
		}
	}

}

package main

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

func main() {
	var t int
	fmt.Scanf("%d ", &t)
	for t > 0 {
		t--
		var n int
		fmt.Scanf("%d ", &n)
		var s string
		fmt.Scanf("%s ", &s)
		if n > 2 || s[0] < s[1] {
			fmt.Println("YES\n2")
			s = s[0:1] + " "  + s[1:]
			fmt.Println(s)
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

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

func main() {
	defer writer.Flush()

	var q int64
	scanf("%d\n", &q)

	for q>0 {
		q--

		var n int64
		var s string

		scanf("%v\n", &n)
		scanf("%v\n", &s)

		if(n==int64(2)) {
			if(int(s[0]) < int(s[1])) {
				printf("YES\n")
				printf("2\n")
				printf("%c %c\n", s[0], s[1])
			} else {
				printf("NO\n")
			}
		} else {
			printf("YES\n")
			printf("2\n")
			printf("%c %s\n", s[0], s[1:])
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func main() {
	defer w.Flush()

	var q int
	scan(&q)
	for ; q > 0; q-- {
		var l int
		var s string
		scan(&l,&s)

		if l == 1 {
			print("NO\n")
		}else if l == 2 {
			if s[0] < s[1] {
				print("YES\n")
				print("2\n")
				print(s[:1]," ", s[1:],"\n")
			}else{
				print("NO\n")
			}

		}else if l > 2 {
			print("YES\n")
			print("2\n")
			print(s[:1], " ",s[1:] ,"\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...) }

func main() {
	defer writer.Flush()
	var q, n int
	var s string

	scanf("%d\n", &q)

	for i := 0; i < q; i++ {
		scanf("%d\n", &n)
		scanf("%s\n", &s)

		if n == 1 {
			printf("NO\n")
		} else if n == 2 {
			if s[0] >= s[1] {
				printf("NO\n")
			} else {
				printf("YES\n2\n")
				printf("%s %s\n", string(s[0]), string(s[1]))
			}
		} else {
			printf("YES\n2\n")
			printf("%s %s\n", string(s[0]), string(s[1:]))
		}

	}
}

package main

import "fmt"

func main() {
	var q int
	fmt.Scan(&q)
	for i := 0; i < q; i++{
		var n int
		var b []byte
		fmt.Scan(&n, &b)
		if n == 2 && b[0] >= b[1]{
			fmt.Println("NO")
		}else{
			fmt.Println("YES")
			if n == 1{
				fmt.Println(1)
				fmt.Println(string(b))
			}else{
				//eee
				fmt.Println(2)
				fmt.Println(string(b[0]), string(b[1:]))
			}
		}
	}
}

package main

import "fmt"

func main() {
	var q int
	fmt.Scan(&q)
	for i := 0; i < q; i++{
		var n int
		var b []byte
		fmt.Scan(&n, &b)
		if n == 2 && b[0] >= b[1]{
			fmt.Println("NO")
		}else{
			fmt.Println("YES")
			if n == 1{
				fmt.Println(1)
				fmt.Println(string(b))
			}else{
				fmt.Println(2)
				fmt.Println(string(b[0]), string(b[1:]))
			}
		}
	}
}

package main

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

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

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

func main() {
	//STDOUT MUST BE FLUSHED MANUALLY
	defer writer.Flush()

	var n, len, num int
	var d string
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		scanf("%d\n", &len)
		scanf("%s\n", &d)
		// printf("len: %v, data: %v\n", len, d)
		if len > 2 {
			printf("YES\n")
			printf("%v %v\n", d[:1], d[1:])
			continue
		}
		num, _ = strconv.Atoi(d)
		if num / 10 >= num % 10 {
			printf("NO\n")
			continue
		}
		printf("YES\n")
		printf("%v %v\n", d[:1], d[1:])
	}
	// printf("%d\n", a+b)
}

package main

import (
	"fmt"
	//"strconv"
)

func main() {
	var t int
	fmt.Scanf("%d ", &t)
	for i := 0; i < t; i++ {
		//var k int64

		var s string
		fmt.Scanf("%s ", &s)
		fmt.Scanf("%s ", &s)
		//fmt.Println(string('#'), s)
		if len(s) == 2 && s[0] == s[1] {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			fmt.Println("2")
			s = s[0:1] + string(' ') + s[1:]
			fmt.Println(s)
		}
	}

}

package main

import (
	"fmt"
	//"strconv"
)

func main() {
	var t int
	fmt.Scanf("%d ", &t)
	for i := 0; i < t; i++ {
		//var k int64
		var s string
		fmt.Scanf("%s ", &s)
		if len(s) == 2 && s[0] == s[1] {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			fmt.Println("2")
			s = s[0:1] + string(' ') + s[1:]
			fmt.Println(s)
		}
	}

}

package main

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

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

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

func main() {
	defer writer.Flush()

	var q int64
	scanf("%d\n", &q)

	for q>0 {
		q--

		var n int64
		var s string

		scanf("%v\n", &n)
		scanf("%v\n", &s)

		if(n==int64(2)) {
			if(int(s[0]) < int(s[1])) {
				printf("YES\n")
				printf("2\n")
				printf("%v %v\n", s[0], s[1])
			} else {
				printf("NO\n")
			}
		} else {
			printf("YES\n")
			printf("2\n")
			printf("%v %v\n", s[:1], s[1:])
		}
	}
}

package main

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

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

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

func main() {
	defer writer.Flush()

	var q int64
	scanf("%d\n", &q)

	for q>0 {
		q--

		var n int64
		var s string

		scanf("%v\n", &n)
		scanf("%v\n", &s)

		if(n==int64(2)) {
			if(int(s[0]) < int(s[1])) {
				printf("YES\n")
				printf("2\n")
				printf("%v %v\n", s[0], s[1])
			} else {
				printf("NO\n")
			}
		} else {
			printf("YES\n")
			printf("2\n")
			printf("%v %v\n", s[:1], s[1:])
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func main() {
	defer w.Flush()

	var q int
	scan(&q)
	for ; q > 0; q-- {
		var l int
		var s string
		scan(&l,&s)

		if l == 1 {
			print("NO\n")
		}else if l == 2 {
			if s[0] < s[1] {
				print("YES\n")
				print(s[0]," ", s[1],"\n")
			}else{
				print("NO\n")
			}

		}else if l > 2 {
			print("YES\n")
			print(s[:1], " ",s[1:] ,"\n")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func main() {
	defer w.Flush()

	var q int
	scan(&q)
	for ; q > 0; q-- {
		var l int
		var s string
		scan(&l,&s)

		if l == 1 {
			print("NO\n")
		}else if l == 2 {
			if s[0] < s[1] {
				print("YES\n")
				print("2\n")
				print(s[0]," ", s[1],"\n")
			}else{
				print("NO\n")
			}

		}else if l > 2 {
			print("YES\n")
			print("2\n")
			print(s[:1], " ",s[1:] ,"\n")
		}
	}
}

package main

import "fmt"

func main() {
	var q int
	fmt.Scan(&q)
	for i := 0; i < q; i++{
		var n int
		var b []byte
		fmt.Scan(&n, &b)
		if n == 2 && b[0] >= b[1]{
			fmt.Println("NO")
		}else{
			fmt.Println("YES")
			if n == 1{
				fmt.Println(string(b))
			}else{
				fmt.Println(string(b[0]), string(b[1:]))
			}
		}
	}
}


You are given a string $$$s$$$, consisting only of characters '0' or '1'. Let $$$|s|$$$ be the length of $$$s$$$.You are asked to choose some integer $$$k$$$ ($$$k > 0$$$) and find a sequence $$$a$$$ of length $$$k$$$ such that:   $$$1 \le a_1 < a_2 < \dots < a_k \le |s|$$$;  $$$a_{i-1} + 1 < a_i$$$ for all $$$i$$$ from $$$2$$$ to $$$k$$$. The characters at positions $$$a_1, a_2, \dots, a_k$$$ are removed, the remaining characters are concatenated without changing the order. So, in other words, the positions in the sequence $$$a$$$ should not be adjacent.Let the resulting string be $$$s'$$$. $$$s'$$$ is called sorted if for all $$$i$$$ from $$$2$$$ to $$$|s'|$$$ $$$s'_{i-1} \le s'_i$$$.Does there exist such a sequence $$$a$$$ that the resulting string $$$s'$$$ is sorted?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. Then the descriptions of $$$t$$$ testcases follow. The only line of each testcase contains a string $$$s$$$ ($$$2 \le |s| \le 100$$$). Each character is either '0' or '1'.

For each testcase print "YES" if there exists a sequence $$$a$$$ such that removing the characters at positions $$$a_1, a_2, \dots, a_k$$$ and concatenating the parts without changing the order produces a sorted string. Otherwise, print "NO". You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

NoteIn the first testcase you can choose a sequence $$$a=[1,3,6,9]$$$. Removing the underlined letters from "10101011011" will produce a string "0011111", which is sorted.In the second and the third testcases the sequences are already sorted.In the fourth testcase you can choose a sequence $$$a=[3]$$$. $$$s'=$$$ "11", which is sorted.In the fifth testcase there is no way to choose a sequence $$$a$$$ such that $$$s'$$$ is sorted.

package main

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

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

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

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

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

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		if solve() {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

type ll = int64

func solve() bool {
	var s string
	scan(&s)
	a := []int{}
	for i := range s {
		if s[i] == '1' {
			a = append(a, i)
		}
		b := []int{}
		for j := i + 1; j < len(s); j++ {
			if s[j] == '0' {
				b = append(b, j)
			}
		}
		if check(a, b) {
			return true
		}
	}
	return false
}

func check(a, b []int) bool {
	x := append(append(([]int)(nil), a...), b...)
	for i := 1; i < len(x); i++ {
		if x[i]-x[i-1] == 1 {
			return false
		}
	}
	return true
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	var s string
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&s)
		ind := strings.Index(s, "11")
		ltind := strings.LastIndex(s, "00")
		if ltind > ind && ind >= 0 {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	var s string
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&s)
		ind := strings.Index(s, "11")
		ltind := strings.LastIndex(s, "00")
		if ind != -1 && ltind != -1 && ltind > ind {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
	}
}

package main

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

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

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

		zeroIdx := strings.LastIndex(s, "00")
		oneIdx := strings.Index(s, "11")
		if oneIdx >= 0 && oneIdx < zeroIdx {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

import (
	"fmt"
	"math/big"
)

var ret *big.Int

func isPrime(x int) bool {
	for i := 2; i < x; i++ {
		if x % i == 0 {
			return false
		}
	}
	return true
}

func dfs(dep, maxDep, n int, a, primeArr []int32, used []bool) {
	if dep == maxDep {
		cur := big.NewInt(1)
		for i := 0; i < n; i++ {
			curFlag := false
			for j := 0; j < maxDep; j++ {
				if used[j] && a[i] % primeArr[j] == 0 {
					curFlag = true
				}
			}
			if !curFlag {
				return
			}
		}
		for i := 0; i < maxDep; i++ {
			if used[i] {
				cur.Mul(cur, big.NewInt(int64(primeArr[i])))
			}
		}
		//fmt.Println(cur)
		if ret.Cmp(big.NewInt(0)) == 0 || -1 == cur.Cmp(ret) {
			ret = cur
		}
		return
	}
	used[dep] = true
	dfs(dep + 1, maxDep, n, a, primeArr, used)
	used[dep] = false
	dfs(dep + 1, maxDep, n, a, primeArr, used)
}

func main() {
	input()
}

func input() {
	var T int
	fmt.Scan(&T)
	for i := 0; i < T; i++ {
		var s string
		fmt.Scan(&s)
		fmt.Println(answer(s))
	}
}

func answer(s string) string {
	flag := false
	for i := 0; i < len(s); i++ {
		if !flag {
			if s[i] == '1' {
				if i + 1 < len(s) && s[i + 1] == '1' {
					flag = true
				}
			}
		} else {
			if s[i] == '0' {
				if i + 1 < len(s) && s[i + 1] == '0' {
					return "NO"
				}
			}
		}
	}
	return "YES"
}

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

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

package main
import (
	. "fmt"
	. "strings"
)
func main() {
	T, s := 0, ""
	for Scan(&T); T > 0; T-- {
		Scan(&s)
		if i := Index(s, "11"); i >= 0 && i < LastIndex(s, "00") {
			Println("NO");
		} else {
			Println("YES");
		}
	}
}

package main
import (
	. "fmt"
	. "strings"
)

func main() {
	T, s := 0, ""
	for Scan(&T); T > 0; T-- {
		Scan(&s)
		if i := Index(s, "11"); i >= 0 && i < LastIndex(s, "00") {
			Println("NO")
		} else {
			Println("YES")
		}
	}
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		s, _ := reader.ReadString('\n')
		res := solve(len(s)-1, s)
		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}
func solve(n int, s string) bool {
	var one bool

	for i := 1; i < n; i++ {
		if s[i] == s[i-1] && s[i] == '0' {
			if one {
				return false
			}
		}
		one = one || s[i] == '1' && s[i-1] == '1'
	}
	return true
}
func solve1(n int, s string) bool {
	// if position i is kept
	// if s[i] = 0, then all '1' before it should be removed,
	// if s[i] = 1, then all '0' after it should be removed
	// let dp[i] means if there are continues 1 before i,
	dp := make([]bool, n)
	for i := 1; i < n; i++ {
		dp[i] = dp[i-1] || s[i] == '1' && s[i-1] == '1'
	}
	if !dp[n-1] {
		// remove all ones
		return true
	}
	// fp means there are continues 0 so far
	var fp bool
	for i := n - 2; i >= 0; i-- {
		if s[i] == '0' {
			if !dp[i] && !fp {
				// remove all ones before, and all zeros after
				return true
			}
		}
		fp = fp || s[i] == '0' && s[i+1] == '0'
	}
	if !fp {
		// return all zeros
		return true
	}
	return false
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		s, _ := reader.ReadString('\n')
		res := solve(len(s)-1, s)
		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(n int, s string) bool {
	// if position i is kept
	// if s[i] = 0, then all '1' before it should be removed,
	// if s[i] = 1, then all '0' after it should be removed
	// let dp[i] means if there are continues 1 before i,
	dp := make([]bool, n)
	for i := 1; i < n; i++ {
		dp[i] = dp[i-1] || s[i] == '1' && s[i-1] == '1'
	}
	if !dp[n-1] {
		// remove all ones
		return true
	}
	// fp means there are continues 0 so far
	var fp bool
	for i := n - 2; i >= 0; i-- {
		if s[i] == '0' {
			if !dp[i] && !fp {
				// remove all ones before, and all zeros after
				return true
			}
		}
		fp = fp || s[i] == '0' && s[i+1] == '0'
	}
	if !fp {
		// return all zeros
		return true
	}
	return false
}

package main

import (
	"fmt"
	"strings"
)

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

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

		ones := strings.Index(s, "11")
		zeroes := strings.LastIndex(s, "00")

		if ones != -1 && zeroes != -1 && ones < zeroes {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}

package main
import (
	. "fmt"
	. "strings"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	T, s := 0, ""
	for Scan(&T); T > 0; T-- {
		Scan(&s)
		if i := Index(s, "11"); i >= 0 && i < LastIndex(s, "00") {
			Println("NO")
		} else {
			Println("YES")
		}
	}
}

package main

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

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

	solve := func(Case int) bool {
		var s string
		Fscan(in, &s)
	o:
		for i := range s {
			ps := []int{}
			for j, b := range s[:i] {
				if b == '1' {
					ps = append(ps, j)
				}
			}
			for j := i; j < len(s); j++ {
				if s[j] == '0' {
					ps = append(ps, j)
				}
			}
			for i := 1; i < len(ps); i++ {
				if ps[i]-ps[i-1] == 1 {
					continue o
				}
			}
			return true
		}
		return false
		//cnt := []int{}
		//for i, n := 0, len(s); i < n; {
		//	st := i
		//	v := s[st]
		//	for ; i < n && s[i] == v; i++ {
		//	}
		//	cnt = append(cnt, i-st)
		//}
		//if len(cnt) == 1 {
		//	return true
		//}
		//
		//	Println(cnt)
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		Fprintln(out, map[bool]string{true: "YES", false: "NO"}[solve(Case)])
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

// 00
package main

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

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var s string
		fmt.Fscan(reader, &s)
		i := 1
		for i < len(s) {
			if s[i] == '1' && s[i-1] == '1' {
				break
			}
			i++
		}
		for i < len(s) {
			if s[i] == '0' && s[i-1] == '0' {
				break
			}
			i++
		}
		if i == len(s) {
			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 s string
		flag:=0
		f:=0
		fmt.Scan(&s);
		for j:=0;j<len(s)-1;j++ {
			if s[j]=='0' && s[j+1]=='0' && flag==1 {
				f=1;
				break;
			}
			if s[j]=='1' && s[j+1]=='1' {
				flag=1;
			}

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

	}
}

package main

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

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

func solve() {
	s := getS()

	var lastZero int
	firstOne := len(s)

	for i := 0; i < len(s)-1; i++ {
		if s[i] == '1' && s[i+1] == '1' && firstOne == len(s) {
			firstOne = i
		}

		if s[i] == '0' && s[i+1] == '0' {
			lastZero = i
		}
	}

	if lastZero <= firstOne {
		out("YES")
	} else {
		out("NO")
	}
}

// http://github.com/KadoBOT (me@ricardoambrogi.com)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	for i := getI(); i > 0; i-- {
		solve()
	}
	out()
}

// !------- HELPERS -------!
func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

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

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

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

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

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

func ceil(n, d int64) int64 {
	return (n + d - 1) / d
}

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

func nsorti(data ...int64) []int64 {
	idxs := make([]int64, len(data))
	for i := 0; i < len(data); i++ {
		idxs[i] = int64(i)
	}

	sort.SliceStable(idxs, func(i, j int) bool { return data[idxs[i]] < data[idxs[j]] })
	return idxs
}

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

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

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

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

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

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

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

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

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

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

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

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

// !------- FORMULAS -------!
func gcd(a, b int64) int64 {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func lcm(a, b int64, integers ...int64) int64 {
	result := a * b / gcd(a, b)

	for i := 0; i < len(integers); i++ {
		result = lcm(result, integers[i])
	}

	return result
}

func sieve(n int64) []int64 {
	integers := make([]bool, n+1)
	for i := int64(2); i < n+1; i++ {
		integers[i] = true
	}

	for p := int64(2); p*p <= n; p++ {
		if integers[p] == true {
			for i := p * 2; i <= n; i += p {
				integers[i] = false
			}
		}
	}

	var primes []int64
	for p := int64(2); p <= n; p++ {
		if integers[p] == true {
			primes = append(primes, p)
		}
	}

	return primes
}

package main
import (
    "fmt"
)

func main() {
    var T int
    fmt.Scanf("%d\n", &T)
    for t := 1; t <= T; t++ {
        var s string
        fmt.Scanf("%s\n", &s)
        res := false
        for i := 0; i < len(s); i++ {
            flag := true
            last := -10000
            for j := 0; j < len(s); j++ {
                if j <= i {
                    if s[j] == '1' {
                        if j == last + 1 {
                            flag = false
                            break
                        }
                        last = j
                    }
                } else {
                    if s[j] == '0' {
                        if j == last + 1 {
                            flag = false
                            break
                        }
                        last = j
                    }
                }
            }
            if flag {
                res = true
                break
            }
        }
        if res {
            fmt.Printf("YES\n")
        } else {
            fmt.Printf("NO\n")
        }
    }
}

package main

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
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)

		k := len(STRING)
		one := make([]int, 0)
		zero := make([]int, 0)

		for i := 0; i < k-1; i++ {
			if string(STRING[i]) == "1" && string(STRING[i+1]) == "1" {
				one = append(one, i)
			}
			if string(STRING[i]) == "0" && string(STRING[i+1]) == "0" {
				zero = append(zero, i)
			}

		}
		if len(zero)*len(one) == 0 {
			fmt.Println("YES")
		} else {
			k := len(zero)
			if zero[k-1] > one[0] {
				fmt.Println("NO")
			} else {
				fmt.Println("YES")
			}
		}

	}

}

package main

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

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

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

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

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

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

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

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

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

func check(s string, from, to int, sym byte) bool {
	pos := []int{}
	for j := from; j < to; j++ {
		if s[j] == sym {
			pos = append(pos, j)
		}
	}
	if len(pos) == 0 {
		return false
	}
	ok := true
	for j := 1; j < len(pos); j++ {
		if !(pos[j-1]+1 < pos[j]) {
			ok = false
		}
	}
	return ok
}

func solve() {
	var s string
	scan(&s)

	if check(s, 0, len(s), '0') || check(s, 0, len(s), '1') {
		printf("yes\n")
		return
	}

	ok := true
	for i := 1; i < len(s); i++ {
		if s[i-1] > s[i] {
			ok = false
		}
	}
	if ok {
		printf("yes\n")
		return
	}

	cnt := make(map[byte]int)
	for i := range s {
		cnt[s[i]]++
	}
	for i := range s {
		if cnt['0'] == 0 {
			if check(s, 0, i, '1') {
				printf("yes\n")
				return
			}
		}
		cnt[s[i]]--
	}

	cnt = make(map[byte]int)
	for i := range s {
		cnt[s[i]]++
	}
	for i := len(s) - 1; i >= 0; i-- {
		if cnt['1'] == 0 {
			if check(s, i+1, len(s), '0') {
				printf("yes\n")
				return
			}
		}
		cnt[s[i]]--
	}

	printf("no\n")
}

package main

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

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

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

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

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

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

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

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

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

func check(s string, from, to int, sym byte) bool {
	pos := []int{}
	for j := from; j < to; j++ {
		if s[j] == sym {
			pos = append(pos, j)
		}
	}
	if len(pos) == 0 {
		return false
	}
	ok := true
	for j := 1; j < len(pos); j++ {
		if !(pos[j-1]+1 < pos[j]) {
			ok = false
		}
	}
	return ok
}

func solve() {
	var s string
	scan(&s)

	if check(s, 0, len(s), '0') || check(s, 0, len(s), '1') {
		printf("yes\n")
		return
	}

	cnt := make(map[byte]int)
	for i := range s {
		cnt[s[i]]++
	}

	ok := true
	for i := 1; i < len(s); i++ {
		if s[i-1] > s[i] {
			ok = false
		}
	}
	if ok {
		printf("yes\n")
		return
	}
	for i := range s {
		if cnt['0'] == 0 {
			if check(s, 0, i, '1') {
				printf("yes\n")
				return
			}
		}
		cnt[s[i]]--
	}

	printf("no\n")
}

package main

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

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

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

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

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

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

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

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

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

func check(s string, from, to int, sym byte) bool {
	pos := []int{}
	for j := from; j < to; j++ {
		if s[j] == sym {
			pos = append(pos, j)
		}
	}
	if len(pos) == 0 {
		return false
	}
	ok := true
	for j := 1; j < len(pos); j++ {
		if !(pos[j-1]+1 < pos[j]) {
			ok = false
		}
	}
	return ok
}

func solve() {
	var s string
	scan(&s)

	if check(s, 0, len(s), '0') || check(s, 0, len(s), '1') {
		printf("yes\n")
		return
	}

	cnt := make(map[byte]int)
	for i := range s {
		cnt[s[i]]++
	}

	ok := true
	for i := 1; i < len(s); i++ {
		if s[i-1] >= s[i] {
			ok = false
		}
	}
	if ok {
		printf("yes\n")
		return
	}
	for i := range s {
		if cnt['0'] == 0 {
			if check(s, 0, i, '1') {
				printf("yes\n")
				return
			}
		}
		cnt[s[i]]--
	}

	printf("no\n")
}

package main

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

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

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

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

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

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

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

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

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

func check(s string, from, to int, sym byte) bool {
	pos := []int{}
	for j := from; j < to; j++ {
		if s[j] == sym {
			pos = append(pos, j)
		}
	}
	if len(pos) == 0 {
		return false
	}
	ok := true
	for j := 1; j < len(pos); j++ {
		if !(pos[j-1]+1 < pos[j]) {
			ok = false
		}
	}
	return ok
}

func solve() {
	var s string
	scan(&s)

	if check(s, 0, len(s), '0') || check(s, 0, len(s), '1') {
		printf("yes\n")
		return
	}

	cnt := make(map[byte]int)
	for i := range s {
		cnt[s[i]]++
	}
	if cnt['0'] == 0 || cnt['1'] == 0 {
		printf("yes\n")
		return
	}
	for i := range s {
		if cnt['0'] == 0 {
			if check(s, 0, i, '1') {
				printf("yes\n")
				return
			}
		}
		cnt[s[i]]--
	}

	printf("no\n")
}

package main

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

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

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

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

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

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

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

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

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

func check(s string, from, to int, sym byte) bool {
	pos := []int{}
	for j := from; j < to; j++ {
		if s[j] == sym {
			pos = append(pos, j)
		}
	}
	if len(pos) == 0 {
		return false
	}
	ok := true
	for j := 1; j < len(pos); j++ {
		if !(pos[j-1]+1 < pos[j]) {
			ok = false
		}
	}
	return ok
}

func solve() {
	var s string
	scan(&s)

	if check(s, 0, len(s), '0') || check(s, 0, len(s), '1') {
		printf("yes\n")
		return
	}

	cnt := make(map[byte]int)
	for i := range s {
		cnt[s[i]]++
	}
	if cnt['0'] == 0 || cnt['1'] == 0 {
		printf("no\n")
		return
	}
	for i := range s {
		if cnt['0'] == 0 {
			if check(s, 0, i, '1') {
				printf("yes\n")
				return
			}
		}
		cnt[s[i]]--
	}

	printf("no\n")
}

package main

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

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

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

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

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

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

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

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

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

func check(s string, from, to int, sym byte) bool {
	pos := []int{}
	for j := from; j < to; j++ {
		if s[j] == sym {
			pos = append(pos, j)
		}
	}
	ok := true
	for j := 1; j < len(pos); j++ {
		if !(pos[j-1]+1 < pos[j]) {
			ok = false
		}
	}
	return ok
}

func solve() {
	var s string
	scan(&s)

	if check(s, 0, len(s), '0') || check(s, 0, len(s), '1') {
		printf("yes\n")
		return
	}

	cnt := make(map[byte]int)
	for i := range s {
		cnt[s[i]]++
	}
	if cnt['0'] == 0 || cnt['1'] == 0 {
		printf("yes\n")
		return
	}
	for i := range s {
		if cnt['0'] == 0 {
			if check(s, 0, i, '1') {
				printf("yes\n")
				return
			}
		}
		cnt[s[i]]--
	}

	printf("no\n")
}

package main

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

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

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

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

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

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

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

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

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

func check(s string, from, to int, sym byte) bool {
	pos := []int{}
	for j := from; j < to; j++ {
		if s[j] == sym {
			pos = append(pos, j)
		}
	}
	ok := true
	for j := 1; j < len(pos); j++ {
		if !(pos[j-1]+1 < pos[j]) {
			ok = false
		}
	}
	return ok
}

func solve() {
	var s string
	scan(&s)

	if check(s, 0, len(s), '0') || check(s, 0, len(s), '1') {
		printf("yes\n")
		return
	}

	cnt := make(map[byte]int)
	for i := range s {
		cnt[s[i]]++
	}
	for i := range s {
		if cnt['0'] > 0 {
			cnt[s[i]]--
			continue
		}
		cnt[s[i]]--
		if check(s, 0, i, '1') {
			printf("yes\n")
			return
		}
	}

	printf("no\n")
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	var s string
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&s)
		ind := strings.Index(s, "11")
		ltind := strings.Index(s, "00")
		if ind != -1 && ltind != -1 && ltind > ind {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	var s string
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&s)
		ind := strings.Index(s, "11")
		ltind := strings.Index(s, "00")
		if ind >= 0 && ltind >= 0 && ltind > ind {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	var s string
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&s)
		ind := strings.Index(s, "11")
		ltind := strings.Index(s, "00")
		if ltind > ind && ind >= 0 && ltind >= 0 {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	var s string
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&s)
		ind := strings.Index(s, "11")
		ltind := strings.Index(s, "00")
		if ltind > ind && ind >= 0 {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
	}
}

package main

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

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

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

		zeroIdx := strings.Index(s, "00")
		oneIdx := strings.Index(s, "11")
		if zeroIdx >= 0 && oneIdx >= 0 && oneIdx < zeroIdx {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

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

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

		zeroIdx := strings.Index(s, "00")
		oneIdx := strings.Index(s, "11")
		if oneIdx >= 0 && zeroIdx > oneIdx {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

import (
	"fmt"
	"math/big"
)

var ret *big.Int

func isPrime(x int) bool {
	for i := 2; i < x; i++ {
		if x % i == 0 {
			return false
		}
	}
	return true
}

func dfs(dep, maxDep, n int, a, primeArr []int32, used []bool) {
	if dep == maxDep {
		cur := big.NewInt(1)
		for i := 0; i < n; i++ {
			curFlag := false
			for j := 0; j < maxDep; j++ {
				if used[j] && a[i] % primeArr[j] == 0 {
					curFlag = true
				}
			}
			if !curFlag {
				return
			}
		}
		for i := 0; i < maxDep; i++ {
			if used[i] {
				cur.Mul(cur, big.NewInt(int64(primeArr[i])))
			}
		}
		//fmt.Println(cur)
		if ret.Cmp(big.NewInt(0)) == 0 || -1 == cur.Cmp(ret) {
			ret = cur
		}
		return
	}
	used[dep] = true
	dfs(dep + 1, maxDep, n, a, primeArr, used)
	used[dep] = false
	dfs(dep + 1, maxDep, n, a, primeArr, used)
}

func main() {
	input()
}

func input() {
	var T int
	fmt.Scan(&T)
	for i := 0; i < T; i++ {
		var s string
		fmt.Scan(&s)
		fmt.Println(answer(s))
	}
}

func answer(s string) string {
	newS := ""
	for i := 0; i < len(s); i++ {
		if s[i] == '1' {
			newS = s[i + 1:]
			break
		}
	}
	if len(newS) == 0 {
		return "YES"
	}
	for i := len(newS) - 1; i >= 0; i-- {
		if newS[i] == '0' {
			if i > 0 {
				if newS[i - 1] == '0' {
					return "NO"
				}
			}
		}
	}
	return "YES"
}

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

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

package main

import (
	"fmt"
	"math/big"
)

var ret *big.Int

func isPrime(x int) bool {
	for i := 2; i < x; i++ {
		if x % i == 0 {
			return false
		}
	}
	return true
}

func dfs(dep, maxDep, n int, a, primeArr []int32, used []bool) {
	if dep == maxDep {
		cur := big.NewInt(1)
		for i := 0; i < n; i++ {
			curFlag := false
			for j := 0; j < maxDep; j++ {
				if used[j] && a[i] % primeArr[j] == 0 {
					curFlag = true
				}
			}
			if !curFlag {
				return
			}
		}
		for i := 0; i < maxDep; i++ {
			if used[i] {
				cur.Mul(cur, big.NewInt(int64(primeArr[i])))
			}
		}
		//fmt.Println(cur)
		if ret.Cmp(big.NewInt(0)) == 0 || -1 == cur.Cmp(ret) {
			ret = cur
		}
		return
	}
	used[dep] = true
	dfs(dep + 1, maxDep, n, a, primeArr, used)
	used[dep] = false
	dfs(dep + 1, maxDep, n, a, primeArr, used)
}

func main() {
	input()
}

func input() {
	var T int
	fmt.Scan(&T)
	for i := 0; i < T; i++ {
		var s string
		fmt.Scan(&s)
		fmt.Println(answer(s))
	}
}

func answer(s string) string {
	newS := ""
	for i := 0; i < len(s); i++ {
		if s[i] == '1' {
			newS = s[i:]
			break
		}
	}
	if len(newS) == 0 {
		return "YES"
	}
	for i := len(newS) - 1; i >= 0; i-- {
		if newS[i] == '0' {
			if i > 0 {
				if newS[i - 1] == '0' {
					return "NO"
				}
			}
		}
	}
	return "YES"
}

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

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

package main

import (
	"fmt"
	"strings"
)

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

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

		ones := strings.Index(s, "11")
		zeroes := strings.Index(s, "00")

		if ones != -1 && zeroes != -1 && ones < zeroes {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}


Find out if it is possible to partition the first $$$n$$$ positive integers into two non-empty disjoint sets $$$S_1$$$ and $$$S_2$$$ such that:$$$\mathrm{gcd}(\mathrm{sum}(S_1), \mathrm{sum}(S_2)) > 1$$$ Here $$$\mathrm{sum}(S)$$$ denotes the sum of all elements present in set $$$S$$$ and $$$\mathrm{gcd}$$$ means thegreatest common divisor.Every integer number from $$$1$$$ to $$$n$$$ should be present in exactly one of $$$S_1$$$ or $$$S_2$$$.

The only line of the input contains a single integer $$$n$$$ ($$$1 \le n \le 45\,000$$$)

If such partition doesn't exist, print "No" (quotes for clarity). Otherwise, print "Yes" (quotes for clarity), followed by two lines, describing $$$S_1$$$ and $$$S_2$$$ respectively. Each set description starts with the set size, followed by the elements of the set in any order. Each set must be non-empty. If there are multiple possible partitions — print any of them.

NoteIn the first example, there is no way to partition a single number into two non-empty sets, hence the answer is "No".In the second example, the sums of the sets are $$$2$$$ and $$$4$$$ respectively. The $$$\mathrm{gcd}(2, 4) = 2 > 1$$$, hence that is one of the possible answers.

package main

import "fmt"

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

	sum := n * (n + 1) / 2

	ans := 0

	for gcd := 2; gcd < n; gcd++ {
		cmp := sum - gcd
		if cmp > 0 && cmp%gcd == 0 {
			ans = gcd
			break
		}
	}

	if ans == 0 {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
		fmt.Printf("%d", n-1)
		for i := 1; i <= n; i++ {
			if i == ans {
				continue
			}
			fmt.Printf(" %d", i)
		}
		fmt.Printf("\n1 %d\n", ans)
	}
}

package main

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

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

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

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

func main() {
	defer writer.Flush()
	var n, tot, t1 int
	scanf("%d", &n)
	tot = n * (n + 1) / 2
	for i := 1; i <= n; i++ {
		t1 = tot - i
		if gcd(t1, i) > 1 {
			printf("Yes\n%d %d\n%d ", 1, i, n-1)
			for j := 1; j <= n; j++ {
				if j == i {
					continue
				}
				printf("%d ", j)
			}

			return
		}
	}
	printf("No")
}

// Find the answer by looking at n(n + 1)/2
package main

import (
	"fmt"
	"os"
)

func main() {
	n := 0
	fmt.Scan(&n)
	if n <= 2 {
		fmt.Println("No")
		os.Exit(0)
	} else {
		fmt.Println("Yes")
	}

	choice := 0
	if n%2 == 0 {
		choice = n / 2
	} else {
		choice = (n + 1) / 2
	}

	fmt.Println("1", choice)
	fmt.Print(n - 1)
	for i := 1; i <= n; i++ {
		if i == choice {
			continue
		}
		fmt.Printf(" %d", i)
	}
	fmt.Println()
}

// Find the answer by looking at n(n + 1)/2
package main

import (
	"fmt"
	"os"
)

func main() {
	n := 0
	fmt.Scan(&n)
	if n == 1 {
		fmt.Println("No")
		os.Exit(0)
	} else {
		fmt.Println("Yes")
	}

	choice := 0
	if n%2 == 0 {
		choice = n / 2
	} else {
		choice = (n + 1) / 2
	}

	fmt.Println("1", choice)
	fmt.Print("2")
	for i := 1; i <= n; i++ {
		if i == choice {
			continue
		}
		fmt.Printf(" %d", i)
	}
	fmt.Println()
}

// Find the answer by looking at n(n + 1)/2
package main

import (
	"fmt"
	"os"
)

func main() {
	n := 0
	fmt.Scan(&n)
	if n == 1 {
		fmt.Println("No")
		os.Exit(0)
	} else {
		fmt.Println("Yes")
	}

	choice := 0
	if n%2 == 0 {
		choice = n / 2
	} else {
		choice = (n + 1) / 2
	}

	fmt.Println("1", choice)
	fmt.Print(n - 1)
	for i := 1; i <= n; i++ {
		if i == choice {
			continue
		}
		fmt.Printf(" %d", i)
	}
	fmt.Println()
}


Farmer John has just given the cows a program to play with! The program contains two integer variables, x and y, and performs the following operations on a sequence a1, a2, ..., an of positive integers:  Initially, x = 1 and y = 0. If, after any step, x ≤ 0 or x > n, the program immediately terminates.  The program increases both x and y by a value equal to ax simultaneously.  The program now increases y by ax while decreasing x by ax.  The program executes steps 2 and 3 (first step 2, then step 3) repeatedly until it terminates (it may never terminate). So, the sequence of executed steps may start with: step 2, step 3, step 2, step 3, step 2 and so on. The cows are not very good at arithmetic though, and they want to see how the program works. Please help them!You are given the sequence a2, a3, ..., an. Suppose for each i (1 ≤ i ≤ n - 1) we run the program on the sequence i, a2, a3, ..., an. For each such run output the final value of y if the program terminates or -1 if it does not terminate.

The first line contains a single integer, n (2 ≤ n ≤ 2·105). The next line contains n - 1 space separated integers, a2, a3, ..., an (1 ≤ ai ≤ 109).

Output n - 1 lines. On the i-th line, print the requested value when the program is run on the sequence i, a2, a3, ...an. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

NoteIn the first sample   For i = 1,  x becomes  and y becomes 1 + 2 = 3.  For i = 2,  x becomes  and y becomes 2 + 4 = 6.  For i = 3,  x becomes  and y becomes 3 + 1 + 4 = 8.

package main

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

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

	var n int
	Fscan(in, &n)
	a := make([]int, n+1)
	for i := 2; i <= n; i++ {
		Fscan(in, &a[i])
	}
	dp := make([][2]int64, n+1)
	var f func(int, int8) int64
	f = func(p int, d int8) (res int64) {
		if p > 1 {
			dv := &dp[p][d]
			if *dv != 0 {
				return *dv
			}
			*dv = -1
			defer func() { *dv = res }()
		}
		res = int64(a[p])
		if d == 0 {
			p -= a[p]
		} else {
			p += a[p]
		}
		if p == 1 {
			return -1
		}
		if p <= 0 || p > n {
			return
		}
		v := f(p, d^1)
		if v == -1 {
			return -1
		}
		return res + v
	}
	for a[1] = 1; a[1] < n; a[1]++ {
		Fprintln(out, f(1, 1))
	}
}

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

package main

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

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

	var n int64
	Fscan(in, &n)
	a := make([]int64, n+1)
	for i := int64(2); i <= n; i++ {
		Fscan(in, &a[i])
	}
	dp := make([][2]int64, n+1)
	var f func(int64, int8) int64
	f = func(p int64, d int8) (res int64) {
		if p > 1 {
			dv := &dp[p][d]
			if *dv != 0 {
				return *dv
			}
			*dv = -1
			defer func() { *dv = res }()
		}
		res = a[p]
		if d == 0 {
			p -= a[p]
		} else {
			p += a[p]
		}
		if p == 1 {
			return -1
		}
		if p <= 0 || p > n {
			return
		}
		v := f(p, d^1)
		if v == -1 {
			return -1
		}
		return res + v
	}
	for a[1] = 1; a[1] < n; a[1]++ {
		Fprintln(out, f(1, 1))
	}
}

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