A number is ternary if it contains only digits $$$0$$$, $$$1$$$ and $$$2$$$. For example, the following numbers are ternary: $$$1022$$$, $$$11$$$, $$$21$$$, $$$2002$$$.You are given a long ternary number $$$x$$$. The first (leftmost) digit of $$$x$$$ is guaranteed to be $$$2$$$, the other digits of $$$x$$$ can be $$$0$$$, $$$1$$$ or $$$2$$$.Let's define the ternary XOR operation $$$\odot$$$ of two ternary numbers $$$a$$$ and $$$b$$$ (both of length $$$n$$$) as a number $$$c = a \odot b$$$ of length $$$n$$$, where $$$c_i = (a_i + b_i) \% 3$$$ (where $$$\%$$$ is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by $$$3$$$. For example, $$$10222 \odot 11021 = 21210$$$.Your task is to find such ternary numbers $$$a$$$ and $$$b$$$ both of length $$$n$$$ and both without leading zeros that $$$a \odot b = x$$$ and $$$max(a, b)$$$ is the minimum possible.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^4$$$) — the length of $$$x$$$. The second line of the test case contains ternary number $$$x$$$ consisting of $$$n$$$ digits $$$0, 1$$$ or $$$2$$$. It is guaranteed that the first digit of $$$x$$$ is $$$2$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^4$$$ ($$$\sum n \le 5 \cdot 10^4$$$).

For each test case, print the answer — two ternary integers $$$a$$$ and $$$b$$$ both of length $$$n$$$ and both without leading zeros such that $$$a \odot b = x$$$ and $$$max(a, b)$$$ is the minimum possible. If there are several answers, you can print any.

package main

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

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 scanAllStr() (string, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return "", err
	}
	return strings.TrimRight(str, "\n\r"), nil
}

func main() {
	defer writer.Flush()

	var casesNumb int
	scanf("%d\n", &casesNumb)

	for i := 0; i < casesNumb; i++ {
		exec()
	}
}

func exec() {
	var length int
	scanf("%d\n", &length)

	var x string
	scanf("%s\n", &x)

	rawX := []byte(x)

	a := make([]byte, length)
	b := make([]byte, length)

	var isDiffered bool
	for i := 0; i< length; i++{
		switch rawX[i] {
		case '0':
				a[i] = '0'
				b[i] = '0'
		case '1':
			if isDiffered {
				a[i] = '0'
				b[i] = '1'
			} else {
				a[i] = '1'
				b[i] = '0'
				isDiffered = true
			}
		case '2':
			if isDiffered {
				a[i] = '0'
				b[i] = '2'
			} else {
				a[i] = '1'
				b[i] = '1'
			}
		}
	}

	printf("%s\n%s\n", a, b)
}

package main

import (
	"bufio"
	"fmt"
	"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 NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(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 Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(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 reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

func unique(a []int) int {
	newLen := 0
	n := len(a)
	for i := 0; i < n; i++ {
		if newLen == 0 || a[i] != a[newLen-1] {
			a[newLen] = a[i]
			newLen++
		}
	}
	return newLen
}

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

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

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()
	a := make([]byte, 100000)
	b := make([]byte, 100000)

	for t := 0; t < T; t++ {
		n := NextInt()
		s := NextBytes()
		// 0 => 0, 0
		// 1 => 0, 1
		// 2 => 1, 1
		equal := true
		for i := 0; i < n; i++ {
			if s[i] == '0' {
				a[i] = '0'
				b[i] = '0'
			} else if s[i] == '1' {
				if equal {
					a[i] = '0'
					b[i] = '1'
					equal = false
				} else {
					a[i] = '1'
					b[i] = '0'
				}
			} else if s[i] == '2' {
				if equal {
					a[i] = '1'
					b[i] = '1'
				} else {
					a[i] = '2'
					b[i] = '0'
				}
			}
		}
		fmt.Fprintln(out, string(a[:n]))
		fmt.Fprintln(out, string(b[:n]))
	}

}

package main

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

func main() {
	for t := ScanInt64(); t > 0; t-- {
		n, stringValue := ScanInt(), ScanWord()
		firstString, secondString := "", ""
		flag := false

		for i := 0; i < n; i++{
			if stringValue[i] == '2'{
				if flag{
					firstString += "2"
					secondString += "0"
				}else{
					firstString += "1"
					secondString += "1"
				}
			}else if stringValue[i] == '1'{
				firstString += "1"
				secondString += "0"
				if !flag{
					flag = true
					temp := firstString
					firstString = secondString
					secondString = temp
				}
			}else{
				firstString += "0"
				secondString += "0"
			}
		}
		P(firstString)
		P(secondString)
	}

	close(O)
	oWg.Wait()
}

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

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

func init() {
	P = fmt.Println

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

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

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

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

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
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 sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func swapString(a,b string){

}

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		readLine(reader)
		line := readLine(reader)
		str1 := strings.Builder{}
		str2 := strings.Builder{}
		str1.WriteByte('1')
		str2.WriteByte('1')
		a := 0
		// fmt.Println(line)
		for i := 1; i < len(line); i++ {
			x := line[i] - '0'
			switch x {
			case 0:
				str1.WriteByte('0')
				str2.WriteByte('0')
			case 1:
				if a == 0 {
					str1.WriteByte('1')
					str2.WriteByte('0')
					a = 1
				} else {
					str1.WriteByte('0')
					str2.WriteByte('1')
				}
			case 2:
				if a == 0 {
					str1.WriteByte('1')
					str2.WriteByte('1')
				} else {
					str1.WriteByte('0')
					str2.WriteByte('2')
				}
			}
		}
		fmt.Println(str1.String())
		fmt.Println(str2.String())
	}
}

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 {
			break
		}
	}
	return result
}

/*
URL:
https://codeforces.com/problemset/problem/1328/C
*/

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

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

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int
	n int
	S []rune
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n = ReadInt()
		S = ReadRuneSlice()

		solve()
	}
}

func solve() {
	A, B := []rune{}, []rune{}
	flag := false
	for i := 0; i < n; i++ {
		if flag {
			A = append(A, '0')
			B = append(B, S[i])
			continue
		}

		if S[i] == '2' {
			A = append(A, '1')
			B = append(B, '1')
		} else if S[i] == '0' {
			A = append(A, '0')
			B = append(B, '0')
		} else {
			A = append(A, S[i])
			B = append(B, '0')
			flag = true
		}
	}

	fmt.Println(string(A))
	fmt.Println(string(B))
}

/*******************************************************************/

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

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T, n int
	var s []byte
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &s)
		t := []byte{}
		for i, b := range s {
			if b == '1' {
				Fprintf(out, "%s1%s\n", t, strings.Repeat("0", n-1-i))
				Fprintf(out, "%s0%s\n", t, s[i+1:])
				continue o
			}
			t = append(t, '0'+b&15/2)
		}
		Fprintf(out, "%s\n", t)
		Fprintf(out, "%s\n", t)
	}
}

package main

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

const N = 50050
var s string
var nt int
var n int
var a, b [N] int

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

	fmt.Fscanf(reader, "%d\n", &nt)
	for kk := 0; kk < nt; kk++ {
		fmt.Fscanf(reader, "%d\n", &n)
		fmt.Fscanf(reader, "%s\n", &s)

		var have = false

		for i := 0; i < n; i++ {
			var value = int(s[i] - '0')
			if value == 0 {
				a[i] = 0
				b[i] = 0
				continue
			}

			if have {
				a[i] = 0
				b[i] = value
			} else {
				if value == 1 {
					a[i] = 1
					b[i] = 0
					have = true
				} else {
					a[i] = 1
					b[i] = 1
				}
			}

		}

		for i := 0; i < n; i++ {
			fmt.Fprintf(writer, "%d", a[i])
		}
		fmt.Fprintf(writer, "\n")
		for i := 0; i < n; i++ {
			fmt.Fprintf(writer, "%d", b[i])
		}
		fmt.Fprintf(writer, "\n")
	}
}

// https://serhatgiydiren.github.io

package main

import "fmt"
import "os"
import "bufio"

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

func solve(test_id int) {
 var n int
 var s,s1,s2 string
 fmt.Fscanf(reader, "%d\n", &n)
 fmt.Fscanf(reader, "%s\n", &s)
 diff_seen := false
 for i := 0 ; i < n ; i++ {
  if diff_seen {
   s1 += "0"
   s2 += string(s[i])
  } else {
   if s[i] == '2' {
    s1 += "1"
    s2 += "1"
   } else if s[i] == '1' {
    s1 += "1"
    s2 += "0"
    diff_seen = true
   } else {
    s1 += "0"
    s2 += "0"
   }
  }
 }
 fmt.Fprintf(writer, "%s\n%s\n", s1, s2)
}

func solve_cases() {
 defer writer.Flush()
 t := 1
 fmt.Fscanf(reader, "%d\n", &t)
 for i := 0 ; i < t ; i++ {
  solve(i)
 }
}

func main() {
 solve_cases()
}

package main

import (
	// "os"
	// "log"
	"fmt"
	"bytes"
)

type Pair struct {
    first, second int
}

func main() {
	/*stdin, err := os.OpenFile("lol.txt", os.O_RDONLY|os.O_CREATE, 0666)

    if err != nil {
        log.Fatal(err)
    }
    os.Stdin = stdin*/

    var t, n int
    var s string

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

        var buffer1, buffer2 bytes.Buffer
        choices := [9]Pair{ {0, 0}, {0, 1}, {1, 0}, {1, 1}, {0, 2}, {2, 0}, {1, 2}, {2, 1}, {2, 2}}
        choices2 := [9]Pair{ {0, 0}, {0, 1}, {1, 0}, {0, 2}, {2, 0}, {1, 1}, {1, 2}, {2, 1}, {2, 2}}

        flag := false
        for j := 0; j < n; j++ {
			z := int(s[j]) - 48

			if flag == true {
				for _, p := range choices2 {
					x, y := p.first, p.second
					if (x + y) % 3 == z {
						buffer2.WriteString(string(x + 48))
						buffer1.WriteString(string(y + 48))
						if x != y {
							flag = true
						}
						break
					}
				}
				continue
			}

			for _, p := range choices {
				x, y := p.first, p.second
				if (x + y) % 3 == z {
					buffer1.WriteString(string(x + 48))
					buffer2.WriteString(string(y + 48))
					if x != y {
						flag = true
					}
					break
				}
			}
		}

		fmt.Println(buffer1.String())
		fmt.Println(buffer2.String())
    }
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		in.ReadLine()
		flag := false
		var a, b string
		for j := 0; j < n; j++ {
			char, _ := in.ReadByte()
			if flag {
				switch char {
				case '0':
					a += "0"
					b += "0"
				case '1':
					a += "1"
					b += "0"
				case '2':
					a += "2"
					b += "0"
				}
			} else {
				switch char {
				case '0':
					a += "0"
					b += "0"
				case '1':
					a += "0"
					b += "1"
					flag = true
				case '2':
					a += "1"
					b += "1"
				}
			}
		}
		in.ReadLine()
		fmt.Fprintln(out, a)
		fmt.Fprintln(out, b)
	}
	out.Flush()
}

package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

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

var sc = newScanner()

func main() {
	t := scanInt()
	for i := 0; i < t; i++ {
		n, x := scanInt(), scanString()
		solve(n, x)
	}
}

func solve(n int, x string) {
	a := make([]int, n)
	b := make([]int, n)
	found := false
	for i := 0; i < n; i++ {
		c := int(x[i] - '0')
		if found {
			a[i] = 0
			b[i] = c
			continue
		}
		switch c {
		case 2:
			a[i] = 1
			b[i] = 1
		case 1:
			found = true
			a[i] = 1
			b[i] = 0
		}
	}
	for i := 0; i < n; i++ {
		fmt.Print(a[i])
	}
	fmt.Println()
	for i := 0; i < n; i++ {
		fmt.Print(b[i])
	}
	fmt.Println()
}

// Число называется троичным, если оно содержит только цифры 0, 1 и 2. Например, следующие числа являются
// троичными: 1022, 11, 21, 2002.
// Вам задано длинное троичное число x. Первая (самая левая) цифра числа x гарантированно является 2, остальные цифры
// числа x могут быть 0, 1 или 2 .
//
// Определим троичную операцию XOR ⊙  над двумя троичными числами a и b (оба имеют длину n) как число c=a⊙b
// длины n, где ci=(ai+bi)%3 (где % — операция взятия по модулю).
// Другими словами, сложим соответствующие цифры и возьмем остатки от сумм при делении на 3.
// Например, 10222⊙11021=21210.
// Ваша задача — найти такие троичные числа a и b (оба длины n и без лидирующих нулей), что a⊙b=x и
// max(a,b) — минимально возможный.
//
// Вам нужно ответить на t независимых наборов входных данных.
package main

import (
	"bufio"
	"bytes"
	"flag"
	"fmt"
	"log"
	"os"
	"runtime/pprof"
)

var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")

func calculate(character byte) (byte, byte) {
	switch character {
	case '2':
		return '1', '1'
	case '1':
		return '1', '0'
	case '0':
		return '0', '0'
	default:
		panic(character)
	}
}

func processString(line []byte) ([]byte, []byte) {
	length := len(line)
	a := make([]byte, 0, length)
	b := make([]byte, 0, length)
	var i int
	for i = 0; i < length; i++ {
		a1, b1 := calculate(line[i])
		a = append(a, a1)
		b = append(b, b1)
		if a1 > b1 {
			i++
			break
		}
	}
	for ; i < length; i++ {
		a = append(a, '0')
		b = append(b, line[i])
	}
	return a, b
}

func main() {
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}
	var n uint64
	var t int64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	_, err := fmt.Fscanf(reader, "%d\n", &n)
	if err != nil {
		fmt.Printf("err1: %v", err.Error())
		os.Exit(1)
	}
	for ; n > 0; n-- {

		_, err = fmt.Fscanf(reader, "%d\n", &t)
		if err != nil {
			fmt.Printf("err2: %v", err.Error())
			os.Exit(1)
		}
		line, _ := reader.ReadBytes('\n')
		line = bytes.TrimSpace(line)
		a, b := processString(line)
		fmt.Fprintf(writer, "%s\n%s\n", a, b)
	}
	writer.Flush()
}

// Author: sighduck
// URL: https://codeforces.com/contest/1328/problem/C

package main

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

func Solve(n int, x string) (string, string) {
	a := make([]string, n)
	b := make([]string, n)
	gt := false
	for i := 0; i < n; i++ {
		if x[i] == '2' && !gt {
			a[i] = "1"
			b[i] = "1"
		} else if x[i] == '2' && gt {
			a[i] = "0"
			b[i] = "2"
		} else if x[i] == '0' {
			a[i] = "0"
			b[i] = "0"
		} else if x[i] == '1' && !gt {
			a[i] = "1"
			b[i] = "0"
			gt = true
		} else if x[i] == '1' && gt {
			a[i] = "0"
			b[i] = "1"
		}
	}
	return strings.Join(a, ""), strings.Join(b, "")
}

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

	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		var x string
		fmt.Fscanf(reader, "%d\n%s\n", &n, &x)
		a, b := Solve(n, x)
		fmt.Fprintf(writer, "%s\n%s\n", a, b)
	}
}

package main

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

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

type Writer interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter(writer io.Writer) Writer {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

var (
	reader = NewWordScanner(os.Stdin)
	writer = NewWriter(os.Stdout)
)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		_ = reader.NextString()
		x := reader.NextString()
		a, b := sol(x)
		writer.Printf("%s\n", a)
		writer.Printf("%s\n", b)
	}
}

func sol(x string) (string, string) {
	a := []rune{}
	b := []rune{}
	unbalanced := false // if true, add higher num to b
	for _, r := range x {
		if unbalanced {
			a = append(a, '0')
			b = append(b, r)
		} else {
			if r == '2' {
				a = append(a, '1')
				b = append(b, '1')
			}
			if r == '1' {
				a = append(a, '1')
				b = append(b, '0')
				unbalanced = true
			}
			if r == '0' {
				a = append(a, '0')
				b = append(b, '0')
			}
		}
	}
	return string(a), string(b)
}

package main

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

func main() {
	for t := ScanInt64(); t > 0; t-- {
		n, stringValue := ScanInt(), ScanWord()
		firstString, secondString := "", ""
		flag := false

		for i := 0; i < n; i++{
			if stringValue[i] == '2'{
				if flag{
					firstString += "2"
					secondString += "0"
				}else{
					firstString += "1"
					secondString += "1"
				}
			}else if stringValue[i] == '1'{
				firstString += "1"
				secondString += "0"
				if !flag{
					flag = true
					swapString(firstString, secondString)
				}
			}else{
				firstString += "0"
				secondString += "0"
			}
		}
		P(firstString)
		P(secondString)
	}

	close(O)
	oWg.Wait()
}

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

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

func init() {
	P = fmt.Println

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

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

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

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

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
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 sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func swapString(a,b string)(string, string){
	return b,a
}

package main

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

func main() {
	for t := ScanInt64(); t > 0; t-- {
		n, stringValue := ScanInt(), ScanWord()
		firstString, secondString := "", ""
		flag := false

		for i := 0; i < n; i++{
			if stringValue[i] == '2'{
				if flag{
					firstString += "2"
					secondString += "0"
				}else{
					firstString += "1"
					secondString += "1"
				}
			}else if stringValue[i] == '1'{
				firstString += "1"
				secondString += "0"
				if !flag{
					flag = true
					swapString(firstString, secondString)
				}
			}else{
				firstString += "0"
				secondString += "0"
			}
		}
		P(firstString)
		P(secondString)
	}

	close(O)
	oWg.Wait()
}

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

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

func init() {
	P = fmt.Println

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

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

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

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

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
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 sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func swapString(a,b string){
	temp := a
	a = b
	b = temp
}

package main

import (
	// "os"
	// "log"
	"fmt"
	"bytes"
)

type Pair struct {
    first, second int
}

func main() {
	/*stdin, err := os.OpenFile("lol.txt", os.O_RDONLY|os.O_CREATE, 0666)

    if err != nil {
        log.Fatal(err)
    }
    os.Stdin = stdin*/

    var t, n int
    var s string

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

        var buffer1, buffer2 bytes.Buffer
        choices := [9]Pair{ {0, 0}, {0, 1}, {1, 0}, {1, 1}, {0, 2}, {2, 0}, {1, 2}, {2, 1}, {2, 2}}
        choices2 := [9]Pair{ {0, 0}, {0, 1}, {1, 0}, {0, 2}, {2, 0}, {1, 1}, {1, 2}, {2, 1}, {2, 2}}

        flag := false
        for j := 0; j < n; j++ {
			z := int(s[j]) - 48

			if flag == true {
				for _, p := range choices2 {
					x, y := p.first, p.second
					if (x + y) % 3 == z {
						buffer1.WriteString(string(x + 48))
						buffer2.WriteString(string(y + 48))
						if x != y {
							flag = true
						}
						break
					}
				}
				continue
			}

			for _, p := range choices {
				x, y := p.first, p.second
				if (x + y) % 3 == z {
					buffer1.WriteString(string(x + 48))
					buffer2.WriteString(string(y + 48))
					if x != y {
						flag = true
					}
					break
				}
			}
		}

		fmt.Println(buffer1.String())
		fmt.Println(buffer2.String())
    }
}

package main

import (
	// "os"
	// "log"
	"fmt"
	"bytes"
)

type Pair struct {
    first, second int
}

func main() {
	/*stdin, err := os.OpenFile("lol.txt", os.O_RDONLY|os.O_CREATE, 0666)

    if err != nil {
        log.Fatal(err)
    }
    os.Stdin = stdin*/

    var t, n int
    var s string

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

        var buffer1, buffer2 bytes.Buffer
        choices := [9]Pair{ {0, 0}, {0, 1}, {1, 0}, {1, 1}, {0, 2}, {2, 0}, {1, 2}, {2, 1}, {2, 2}}

        for j := 0; j < n; j++ {
			z := int(s[j]) - 48

			for _, p := range choices {
				x, y := p.first, p.second
				if (x + y) % 3 == z {
					buffer1.WriteString(string(x + 48))
					buffer2.WriteString(string(y + 48))
					break
				}
			}
		}

		fmt.Println(buffer1.String())
		fmt.Println(buffer2.String())
    }
}

// Число называется троичным, если оно содержит только цифры 0, 1 и 2. Например, следующие числа являются
// троичными: 1022, 11, 21, 2002.
// Вам задано длинное троичное число x. Первая (самая левая) цифра числа x гарантированно является 2, остальные цифры
// числа x могут быть 0, 1 или 2 .
//
// Определим троичную операцию XOR ⊙  над двумя троичными числами a и b (оба имеют длину n) как число c=a⊙b
// длины n, где ci=(ai+bi)%3 (где % — операция взятия по модулю).
// Другими словами, сложим соответствующие цифры и возьмем остатки от сумм при делении на 3.
// Например, 10222⊙11021=21210.
// Ваша задача — найти такие троичные числа a и b (оба длины n и без лидирующих нулей), что a⊙b=x и
// max(a,b) — минимально возможный.
//
// Вам нужно ответить на t независимых наборов входных данных.
package main

import (
	"bufio"
	"bytes"
	"flag"
	"fmt"
	"log"
	"os"
	"runtime/pprof"
)

var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")

func calculate(character byte) (byte, byte) {
	switch character {
	case '2':
		return '1', '1'
	case '1':
		return '1', '0'
	case '0':
		return '0', '0'
	default:
		panic(character)
	}
}

func processString(line []byte) ([]byte, []byte) {
	length := len(line)
	a := make([]byte, 0, length)
	b := make([]byte, 0, length)
	var i int
	for i = 0; i < length; i++ {
		a1, b1 := calculate(line[i])
		a = append(a, a1)
		b = append(b, b1)
		if a1 > b1 {
			break
		}
	}
	for ; i < length; i++ {
		a = append(a, '0')
		b = append(b, line[i])
	}
	return a, b
}

func main() {
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}
	var n uint64
	var t int64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	_, err := fmt.Fscanf(reader, "%d\n", &n)
	if err != nil {
		fmt.Printf("err1: %v", err.Error())
		os.Exit(1)
	}
	for ; n > 0; n-- {

		_, err = fmt.Fscanf(reader, "%d\n", &t)
		if err != nil {
			fmt.Printf("err2: %v", err.Error())
			os.Exit(1)
		}
		line, _ := reader.ReadBytes('\n')
		line = bytes.TrimSpace(line)
		a, b := processString(line)
		fmt.Fprintf(writer, "%s\n%s\n", a, b)
	}
	writer.Flush()
}


The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph G. It is required to find a subset of vertices C of the maximum size such that any two of them are connected by an edge in graph G. Sounds simple, doesn't it? Nobody yet knows an algorithm that finds a solution to this problem in polynomial time of the size of the graph. However, as with many other NP-complete problems, the clique problem is easier if you consider a specific type of a graph.Consider n distinct points on a line. Let the i-th point have the coordinate xi and weight wi. Let's form graph G, whose vertices are these points and edges connect exactly the pairs of points (i, j), such that the distance between them is not less than the sum of their weights, or more formally: |xi - xj| ≥ wi + wj.Find the size of the maximum clique in such graph.

The first line contains the integer n (1 ≤ n ≤ 200 000) — the number of points. Each of the next n lines contains two numbers xi, wi (0 ≤ xi ≤ 109, 1 ≤ wi ≤ 109) — the coordinate and the weight of a point. All xi are different.

Print a single number — the number of vertexes in the maximum clique of the given graph.

NoteIf you happen to know how to solve this problem without using the specific properties of the graph formulated in the problem statement, then you are able to get a prize of one million dollars!The picture for the sample test.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF528B(_r io.Reader, out io.Writer) {
	type pair struct{ x, y int }
	in := bufio.NewReader(_r)
	var n, ans int
	Fscan(in, &n)
	a := make([]pair, n)
	for i := range a {
		Fscan(in, &a[i].x, &a[i].y)
	}
	sort.Slice(a, func(i, j int) bool { x, y := a[i], a[j]; return x.x+x.y < y.x+y.y })
	cur := pair{-1e9, 0}
	for _, p := range a {
		if p.x-cur.x >= p.y+cur.y {
			ans++
			cur = p
		}
	}
	Fprint(out, ans)
}

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

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Split(bufio.ScanWords)
	if !sc.Scan() {
		panic("could not scan a word from the reader")
	}
	return sc.Text()
}

func nextInt() int {
	i, e := strconv.Atoi(next())
	if e != nil {
		panic(e)
	}
	return i
}

// import "container/heap"
type item struct {
	from, to int
}

func newItem(f, t int) *item {
	return &item{f, t}
}

type priorityQueue []*item

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

func (pq priorityQueue) Less(i, j int) bool {
	return pq[i].to < pq[j].to
}

func (pq priorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *priorityQueue) Push(x interface{}) {
	item := x.(*item)
	*pq = append(*pq, item)
}

func (pq *priorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

func main() {
	N := nextInt()
	pq := make(priorityQueue, 0, 525000)
	heap.Init(&pq)
	for i := 0; i < N; i++ {
		x, w := nextInt(), nextInt()
		heap.Push(&pq, newItem(x-w, x+w))
	}
	res := 0
	pos := -(1 << 30)
	for i := 0; i < N; i++ {
		pt := heap.Pop(&pq).(*item)
		if pos <= pt.from {
			res++
			pos = pt.to
		}
	}
	fmt.Println(res)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF528B(_r io.Reader, out io.Writer) {
	type pair struct{ x, y int }
	in := bufio.NewReader(_r)
	var n, ans int
	Fscan(in, &n)
	a := make([]pair, n)
	for i := range a {
		Fscan(in, &a[i].x, &a[i].y)
	}
	sort.Slice(a, func(i, j int) bool { x, y := a[i], a[j]; return x.x+x.y < y.x+y.y })
	cur := pair{}
	for _, p := range a {
		if p.x >= cur.x {
			ans++
			cur = p
		}
	}
	Fprint(out, ans)
}

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


Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions in the operands are different.For example, if X = 10910 = 11011012, Y = 4110 = 1010012, then:  X xor Y  =  6810  =  10001002. Write a program, which takes two non-negative integers A and B as an input and finds two non-negative integers X and Y, which satisfy the following conditions:   A = X + Y  B  =  X xor Y, where xor is bitwise exclusive or.  X is the smallest number among all numbers for which the first two conditions are true.

The first line contains integer number A and the second line contains integer number B (0 ≤ A, B ≤ 264 - 1).

The only output line should contain two integer non-negative numbers X and Y. Print the only number -1 if there is no answer.

package main

import(
    "fmt"
)

func main(){
    var a uint64
    var b uint64
    fmt.Scanf("%d\n", &a)
    fmt.Scanf("%d\n", &b)
    if (a-b) % 2 == 1 {
        fmt.Println("-1")
    } else {
        fmt.Printf("%d %d\n", (a-b)/2, a-(a-b)/2)
    }
}

package main

import(
    "fmt"
)

func main(){
    var a int
    var b int
    fmt.Scanf("%d\n", &a)
    fmt.Scanf("%d\n", &b)
    if (a-b) % 2 == 1 {
        fmt.Println("-1")
    } else {
        fmt.Printf("%d %d\n", (a-b)/2, a-(a-b)/2)
    }
}

package main

import(
    "fmt"
)

func main(){
    var a int64
    var b int64
    fmt.Scanf("%lld\n", &a)
    fmt.Scanf("%lld\n", &b)
    if (a-b) % 2 == 1 {
        fmt.Println("-1")
    } else {
        fmt.Printf("%lld %lld\n", (a-b)/2, a-(a-b)/2)
    }
}

 package main

import(
    "fmt"
)

func main(){
    var a int
    var b int
    fmt.Scanf("%d", &a)
    fmt.Scanf("%d", &b)
    if (a-b) % 2 == 1 {
        fmt.Println("-1")
    } else {
        fmt.Printf("%d %d\n", (a-b)/2, a-(a-b)/2)
    }
}

package main

import(
    "fmt"
)

func main(){
    var a int64
    var b int64
    fmt.Scanf("%d\n", &a)
    fmt.Scanf("%d\n", &b)
    if (a-b) % 2 == 1 {
        fmt.Println("-1")
    } else {
        fmt.Printf("%d %d\n", (a-b)/2, a-(a-b)/2)
    }
}


There is a weighted tree with $$$n$$$ nodes and $$$n-1$$$ edges. The nodes are conveniently labeled from $$$1$$$ to $$$n$$$. The weights are positive integers at most $$$100$$$. Define the distance between two nodes to be the sum of edges on the unique path between the nodes. You would like to find the diameter of the tree. Diameter is the maximum distance between a pair of nodes.Unfortunately, the tree isn't given to you, but you can ask some questions about it. In one question, you can specify two nonempty disjoint sets of nodes $$$p$$$ and $$$q$$$, and the judge will return the maximum distance between a node in $$$p$$$ and a node in $$$q$$$. In the words, maximum distance between $$$x$$$ and $$$y$$$, where $$$x \in p$$$ and $$$y \in q$$$. After asking not more than $$$9$$$ questions, you must report the maximum distance between any pair of nodes.

NoteIn the first example, the first tree looks as follows: In the first question, we have $$$p = {1}$$$, and $$$q = {2, 3, 4, 5}$$$. The maximum distance between a node in $$$p$$$ and a node in $$$q$$$ is $$$9$$$ (the distance between nodes $$$1$$$ and $$$5$$$).The second tree is a tree with two nodes with an edge with weight $$$99$$$ between them.

package main

import (
	. "fmt"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	var qs [10][2][]int
	var f func(d, tp, l, r int)
	f = func(d, tp, l, r int) {
		if d == 10 {
			return
		}
		for i := l; i < r; i++ {
			qs[d][tp] = append(qs[d][tp], i)
		}
		f(d+1, 0, l, (l+r)/2)
		f(d+1, 1, (l+r)/2, r)
	}
	var t, n int
	for Scan(&t); t > 0; t-- {
		qs = [10][2][]int{}
		Scan(&n)
		f(0, 0, 1, 1+n/2)
		f(0, 1, 1+n/2, n+1)
		ans := 0
		for _, q := range qs {
			if len(q[0]) == 0 || len(q[1]) == 0 {
				break
			}
			Print(len(q[0]), len(q[1]))
			for _, a := range q {
				for _, v := range a {
					Print(" ", v)
				}
			}
			Println()
			Scan(&n)
			if n > ans {
				ans = n
			}
		}
		Println(-1, ans)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	out := bufio.NewWriter(os.Stdout)
	var qs [10][2][]int
	var f func(d, tp, l, r int)
	f = func(d, tp, l, r int) {
		if d == 10 {
			return
		}
		for i := l; i < r; i++ {
			qs[d][tp] = append(qs[d][tp], i)
		}
		f(d+1, 0, l, (l+r)/2)
		f(d+1, 1, (l+r)/2, r)
	}
	var t, n int
	for Scan(&t); t > 0; t-- {
		qs = [10][2][]int{}
		Scan(&n)
		f(0, 0, 1, 1+n/2)
		f(0, 1, 1+n/2, n+1)
		ans := 0
		for _, q := range qs {
			if len(q[0]) == 0 || len(q[1]) == 0 {
				break
			}
			Fprint(out, len(q[0]), len(q[1]))
			for _, a := range q {
				for _, v := range a {
					Fprint(out, " ", v)
				}
			}
			Fprintln(out)
			out.Flush()
			Scan(&n)
			if n > ans {
				ans = n
			}
		}
		Fprintln(out, -1, ans)
		out.Flush()
	}
}

package main

import (
	. "fmt"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	var qs [10][2][]int
	var f func(d, tp, l, r int)
	f = func(d, tp, l, r int) {
		if d == 10 {
			return
		}
		for i := l; i < r; i++ {
			qs[d][tp] = append(qs[d][tp], i)
		}
		f(d+1, 0, l, (l+r)/2)
		f(d+1, 1, (l+r)/2, r)
	}
	var t, n int
	for Scan(&t); t > 0; t-- {
		qs := [10][2][]int{}
		Scan(&n)
		f(0, 0, 1, n/2)
		f(0, 1, n/2, n+1)
		ans := 0
		for _, q := range qs {
			if len(q[0]) == 0 || len(q[1]) == 0 {
				break
			}
			Print(len(q[0]), len(q[1]))
			for _, a := range q {
				for _, v := range a {
					Print(" ", v)
				}
			}
			Println()
			Scan(&n)
			if n > ans {
				ans = n
			}
		}
		Println(-1, ans)
	}
}

package main

import (
	. "fmt"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	var qs [10][2][]int
	var f func(d, tp, l, r int)
	f = func(d, tp, l, r int) {
		if d == 10 {
			return
		}
		for i := l; i < r; i++ {
			qs[d][tp] = append(qs[d][tp], i)
		}
		f(d+1, 0, l, (l+r)/2)
		f(d+1, 1, (l+r)/2, r)
	}
	var t, n int
	for Scan(&t); t > 0; t-- {
		qs = [10][2][]int{}
		Scan(&n)
		f(0, 0, 1, n/2)
		f(0, 1, n/2, n+1)
		ans := 0
		for _, q := range qs {
			if len(q[0]) == 0 || len(q[1]) == 0 {
				break
			}
			Print(len(q[0]), len(q[1]))
			for _, a := range q {
				for _, v := range a {
					Print(" ", v)
				}
			}
			Println()
			Scan(&n)
			if n > ans {
				ans = n
			}
		}
		Println(-1, ans)
	}
}


There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle.    Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code.

The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order.

Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists.

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	pn := make([]int, n + 1)
	pnn := make([]int, n + 1)
	for i := 1;i <= n;i ++ {
		fmt.Fscanf(reader, "%d %d\n", &pn[i], &pnn[i])
	}
	if n == 3 {
		fmt.Printf("1 2 3")
		return
	}

	res := make([]int, n)
	res[0] = 1;
	for i := 0;i < n - 1;i ++ {
		p := res[i]
		if pn[pn[p]] == pnn[p] || pnn[pn[p]] == pnn[p] {
			res[i + 1] = pn[p]
		} else {
			res[i + 1] = pnn[p]
		}
	}
	for i := 0;i < n;i ++ {
		fmt.Printf("%d ", res[i])
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
func swap(a ,b *int) {
	tmp := *a
	*a = *b
	*b = tmp
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d\n", &n)
	ans := make([]int ,n)
	mat := make([][]int,n+1)
	for i:=1;i <= n;i++{
		mat[i] = make([]int,2)
		fmt.Fscanf(buf,"%d %d\n",&mat[i][0],&mat[i][1])
	}
	if n == 3{
		fmt.Printf("1 2 3\n")
		return
	}
	ans[0] = 1

	if mat[mat[1][0]][0] == mat[1][1] || mat[mat[1][0]][1] == mat[1][1]{
		ans[1] = mat[1][0]
	}else{
		ans[1] = mat[1][1]
	}
	for i := 2;i < n;i++{
		if mat[ans[i-2]][0] == ans[i-1]{
			ans[i] = mat[ans[i-2]][1]
		}else{
			ans[i] = mat[ans[i-2]][0]
		}
	}
	for i := 0;i < n;i++{
		if i > 0{
			fmt.Printf(" ")
		}
		fmt.Printf("%d",ans[i])
	}
	fmt.Printf("\n")
}

package main

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

func main() {
	start := time.Now()
	defer func() {
		run := time.Since(start)
		_ = run
		// fmt.Println("Run in", run)
	}()

	var stdin *bufio.Reader
	// LOCAL
	f, _ := os.Open("input.txt")
	stdin = bufio.NewReader(f)

	// ONLINE JUDGE
	stdin = bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(stdin, &n)

	var a1 = make([]int, n)
	var a2 = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(stdin, &a1[i], &a2[i])
		a1[i]--
		a2[i]--
	}

	var HasCommon func(int, int) int
	HasCommon = func(i, j int) int {
		switch {
		case a1[i] == a1[j], a1[i] == a2[j]:
			return a1[i]
		case a2[i] == a1[j], a2[i] == a2[j]:
			return a2[i]
		default:
			return -1
		}
	}

	var res = make([]int, n)
	res[0] = 0

	var common = HasCommon(0, a1[0])
	if common == -1 {
		common = HasCommon(0, a2[0])
		res[1] = a2[0]
	} else {
		res[1] = a1[0]
	}

	for i := 2; i < n; i++ {
		res[i] = HasCommon(res[i-1], res[i-2])
	}

	for _, num := range res {
		fmt.Print(num+1, " ")
	}
	fmt.Println()
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

func scanNum() int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}
func main() {
	scanner.Split(bufio.ScanWords)
	n := scanNum()
	if n == 3 {
		fmt.Println("1 2 3")
		os.Exit(0)
	}
	a := make([][2]int, n+1)
	for i := 0; i < n; i++ {
		a[i+1] = [2]int{scanNum(), scanNum()}
	}

	res := []int{1}
	for len(res) < n {
		cur := res[len(res)-1]
		c1, c2 := a[cur][0], a[cur][1]
		next := c1

		c2IsNext := (a[c1][0] != c2) && (a[c1][1] != c2)
		if c2IsNext {
			next = c2
		}

		res = append(res, next)
	}

	fmt.Print(res[0])
	for i := 1; i < n; i++ {
		fmt.Printf(" %d", res[i])
	}
	fmt.Println()
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

func scanNum() int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}
func main() {
	scanner.Split(bufio.ScanWords)
	n := scanNum()
	a := make([][2]int, n+1)
	for i := 0; i < n; i++ {
		a[i+1] = [2]int{scanNum(), scanNum()}
	}

	res, memo := []int{1}, map[int]bool{1: true}
	for len(res) < n {
		cur := res[len(res)-1]
		c1, c2 := a[cur][0], a[cur][1]
		next := c1

		// I think this memo defense will only be used when n === 3
		if !memo[c1] && !memo[c2] {
			c2IsNext := (a[c1][0] != c2) && (a[c1][1] != c2)
			if c2IsNext {
				next = c2
			}
		} else {
			if memo[c1] {
				next = c2
			}
		}

		res, memo[next] = append(res, next), true
	}

	fmt.Print(res[0])
	for i := 1; i < n; i++ {
		fmt.Printf(" %d", res[i])
	}
	fmt.Println()
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

func scanNum() int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}
func main() {
	scanner.Split(bufio.ScanWords)
	n := scanNum()
	a := make([][2]int, n+1)
	for i := 0; i < n; i++ {
		a[i+1] = [2]int{scanNum(), scanNum()}
	}

	res := []int{1}
	for len(res) < n {
		cur := res[len(res)-1]
		c1, c2 := a[cur][0], a[cur][1]
		c2IsNext := (a[c1][0] != c2) && (a[c1][1] != c2)

		if c2IsNext {
			res = append(res, c2)
		} else {
			res = append(res, c1)
		}
	}

	fmt.Print(res[0])
	for i := 1; i < n; i++ {
		fmt.Printf(" %d", res[i])
	}
	fmt.Println()
}


After reaching your destination, you want to build a new colony on the new planet. Since this planet has many mountains and the colony must be built on a flat surface you decided to flatten the mountains using boulders (you are still dreaming so this makes sense to you).  You are given an array $$$h_1, h_2, \dots, h_n$$$, where $$$h_i$$$ is the height of the $$$i$$$-th mountain, and $$$k$$$ — the number of boulders you have.You will start throwing boulders from the top of the first mountain one by one and they will roll as follows (let's assume that the height of the current mountain is $$$h_i$$$):   if $$$h_i \ge h_{i + 1}$$$, the boulder will roll to the next mountain;  if $$$h_i < h_{i + 1}$$$, the boulder will stop rolling and increase the mountain height by $$$1$$$ ($$$h_i = h_i + 1$$$);  if the boulder reaches the last mountain it will fall to the waste collection system and disappear. You want to find the position of the $$$k$$$-th boulder or determine that it will fall into the waste collection system.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100$$$; $$$1 \le k \le 10^9$$$) — the number of mountains and the number of boulders. The second line contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 100$$$) — the height of the mountains. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$100$$$.

For each test case, print $$$-1$$$ if the $$$k$$$-th boulder will fall into the collection system. Otherwise, print the position of the $$$k$$$-th boulder.

NoteLet's simulate the first case:  The first boulder starts at $$$i = 1$$$; since $$$h_1 \ge h_2$$$ it rolls to $$$i = 2$$$ and stops there because $$$h_2 < h_3$$$.  The new heights are $$$[4,2,2,3]$$$.  The second boulder starts at $$$i = 1$$$; since $$$h_1 \ge h_2$$$ the boulder rolls to $$$i = 2$$$; since $$$h_2 \ge h_3$$$ the boulder rolls to $$$i = 3$$$ and stops there because $$$h_3 < h_4$$$.  The new heights are $$$[4,2,3,3]$$$.  The third boulder starts at $$$i = 1$$$; since $$$h_1 \ge h_2$$$ it rolls to $$$i = 2$$$ and stops there because $$$h_2 < h_3$$$.  The new heights are $$$[4,3,3,3]$$$. The positions where each boulder stopped are the following: $$$[2,3,2]$$$.In the second case, all $$$7$$$ boulders will stop right at the first mountain rising its height from $$$1$$$ to $$$8$$$.The third case is similar to the first one but now you'll throw $$$5$$$ boulders. The first three will roll in the same way as in the first test case. After that, mountain heights will be equal to $$$[4, 3, 3, 3]$$$, that's why the other two boulders will fall into the collection system.In the fourth case, the first and only boulders will fall straight into the collection system.

package main
import (
	"fmt"
	"bufio"
	"os"
)

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

func _solve(){
	var n,k int
	fmt.Fscan(_r, &n, &k)
	h := make([]int, n)
	for i:=0;i<n;i++ { fmt.Fscan(_r, &h[i]) }
	var at int
	for k > 0 {
		at = -1
		for i := 0; i < n-1; i++ {
			if(h[i] < h[i+1]){
				at = i
				break
			}
		}
		if at == -1 { break }
		h[at]++
		k--
	}
	if at == -1 {
		fmt.Fprintln(_w, -1)
	} else {
		fmt.Fprintln(_w, at+1)
	}

}

func main() {

	defer _w.Flush()

	var times int
	fmt.Fscan(_r, &times)
	for t:=0;t<times;t++{
		_solve()
	}

}

package main

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

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

var a [105]int
var n, k int

func gogo() int {
	pos := 1
	for pos <= n && a[pos] >= a[pos+1] {
		pos ++
	}
	if pos > n {
		pos = -1
	} else {
		a[pos]++
	}
	return pos
}

func main() {
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		fmt.Fscan(in, &n, &k)
		a[n+1] = 0
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}

		pos := -1
		for i := 1; i <= k; i++ {
			pos = gogo()
			if pos == -1 {
				break;
			}
		}
		fmt.Fprintln(out, pos)
	}
	out.Flush()
}

package main

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

func main() {
	//problemA()
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var cases int
	Fscan(in,&cases)
	for ;cases>0;cases-- {
		var l int
		var k int
		Fscan(in,&l,&k)
		arr:=make([]int,l)
		for i:=0;i<l;i++{
			Fscan(in,&arr[i])
		}
		result:=roll(0,arr,k,0,-1)
		Println(result)
	}

}

func roll(index int, arr []int, k int, count int, previous int)  int{
	if index == len(arr)-1 {
		return -1
	}
	if count == k {
		return previous+1
	}
	if arr[index]<arr[index+1] {
		arr[index]=arr[index]+1
		return roll(0,arr,k,count+1,index)
	} else {
		return roll(index+1,arr,k,count,index)
	}
}

package main

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

var bytes []byte

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

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

	b := nextByte()

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

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

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

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

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

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

	return builder.String()
}

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

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

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, k := ScanInt(), ScanInt()
		h := make([]int, n)

		for i := range h {
			h[i] = ScanInt()
		}

		ind := -1

		for ; k > 0; k-- {
			for ind = 1; ind < n && h[ind-1] >= h[ind]; ind++ {
			}

			if ind < n {
				h[ind-1]++
			} else {
				ind = -1
				break
			}
		}

		fmt.Println(ind)
	}
}

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--
		n, k := readTwoNums(reader)
		H := readNNums(reader, n)
		res := solve(H, k)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	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(H []int, K int) int {
	n := len(H)
	// H[i] < H[i+1]
	for K > 0 {
		var i int
		for i+1 < n && H[i] >= H[i+1] {
			i++
		}
		if i+1 == n {
			return -1
		}

		// H[i] < H[i+1]
		x := H[i+1] - H[i]
		if i > 0 {
			x = min(x, H[i-1]-H[i])
		}

		if x == 0 {
			x++
		}

		H[i] += x
		K -= x
		if K <= 0 {
			return i + 1
		}
	}
	//return
	return -1
}

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

package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

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

		var h [101]int
		for i := 0; i < n; i++ {
			_, _ = fmt.Fscan(in, &h[i])
		}

		grid := makeGrid(h, n)
		ans := -1
		for i := 0; i < k; i++ {
			ans = dfs(&grid, 0, 100, n)
			if ans == -1 {
				break
			}
		}
		fmt.Println(ans)
	}
}

func makeGrid(h [101]int, n int) [101][101]bool {
	var grid [101][101]bool
	for i := 0; i < n; i++ {
		for j := 0; j < h[i]; j++ {
			grid[i][j] = true
		}
	}
	return grid
}

func dfs(grid *[101][101]bool, x, y, n int) int {
	if (y > 0) && (!grid[x][y-1]) {
		return dfs(grid, x, y-1, n)
	}
	if (x < n-1) && (!grid[x+1][y]) {
		return dfs(grid, x+1, y, n)
	}
	if x == n-1 {
		return -1
	}
	grid[x][y] = true
	return x + 1
}

package main

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

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

	var t, n, k int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &k)
		h := make([]int, n+1)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &h[i])
		}

		lowPoint := 0
		rocks := 0
		for {
			lowPoint = 0
			for ; lowPoint < n && h[lowPoint] >= h[lowPoint+1]; lowPoint++ {
			}
			if lowPoint == n {
				fmt.Println(-1)
				break
			}
			if lowPoint == 0 || h[lowPoint-1] >= h[lowPoint+1] {
				rocks += h[lowPoint+1] - h[lowPoint]
				h[lowPoint] = h[lowPoint+1]
			} else {
				if h[lowPoint-1] == h[lowPoint] {
					rocks++
					h[lowPoint]++
				} else {
					rocks += h[lowPoint-1] - h[lowPoint]
					h[lowPoint] = h[lowPoint-1]
				}
			}
			if rocks >= k {
				fmt.Println(lowPoint + 1)
				break
			}
		}
	}
}

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) {
		var n, k int
		Fscan(in, &n, &k)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		for kk := 1; kk <= k; kk++ {
			i := 0
			for ; i < n-1; i++ {
				if a[i] < a[i+1] {
					a[i]++
					break
				}
			}
			if i == n-1 {
				Fprintln(out, -1)
				return
			}
			if kk == k {
				Fprintln(out, i+1)
			}
		}
	}

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

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

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

package main
import (
	"fmt"
	"bufio"
	"os"
)

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

func _solve(){
	var n,k int
	fmt.Fscan(_r, &n, &k)
	h := make([]int,n)
	for i:=0;i<n;i++{ fmt.Fscan(_r, &h[i]) }
	at := -1
	for k > 0 {
		for i:=0;i<n-1;i++{
			if(h[i]<h[i+1]){
				at=i
				break
			}
		}
		if at == -1 { break }
		h[at]++
		k--
	}
	fmt.Fprintln(_w, at+1)

}

func main() {

	defer _w.Flush()

	var times int
	fmt.Fscan(_r, &times)
	for t:=0;t<times;t++{
		_solve()
	}

}


This is the easy version of this problem. The difference between easy and hard versions is only the constraints on $$$a_i$$$ and on $$$n$$$. You can make hacks only if both versions of the problem are solved.Burenka is the crown princess of Buryatia, and soon she will become the $$$n$$$-th queen of the country. There is an ancient tradition in Buryatia — before the coronation, the ruler must show their strength to the inhabitants. To determine the strength of the $$$n$$$-th ruler, the inhabitants of the country give them an array of $$$a$$$ of exactly $$$n$$$ numbers, after which the ruler must turn all the elements of the array into zeros in the shortest time. The ruler can do the following two-step operation any number of times:   select two indices $$$l$$$ and $$$r$$$, so that $$$1 \le l \le r \le n$$$ and a non-negative integer $$$x$$$, then  for all $$$l \leq i \leq r$$$ assign $$$a_i := a_i \oplus x$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. It takes $$$\left\lceil \frac{r-l+1}{2} \right\rceil$$$ seconds to do this operation, where $$$\lceil y \rceil$$$ denotes $$$y$$$ rounded up to the nearest integer. Help Burenka calculate how much time she will need.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) — 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 5000$$$) — the size of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 5000$$$) — elements of the array.  It is guaranteed that the sum of $$$n$$$ in all tests does not exceed $$$5000$$$.

For each test case, output a single number  — the minimum time that Burenka will need.

NoteIn the first test case, Burenka can choose segment $$$l = 1$$$, $$$r = 4$$$, and $$$x=5$$$. so it will fill the array with zeros in $$$2$$$ seconds.In the second test case, Burenka first selects segment $$$l = 1$$$, $$$r = 2$$$, and $$$x = 1$$$, after which $$$a = [0, 2, 2]$$$, and then the segment $$$l = 2$$$, $$$r = 3$$$, and $$$x=2$$$, which fills the array with zeros. In total, Burenka will spend $$$2$$$ seconds.

package main

import (
	"fmt"
	"os"
)

func main() {
	in := os.Stdin
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		temp := make([]int, n+1)
		f := make([]int, n+1)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &temp[i+1])
			temp[i+1] = temp[i+1] ^ temp[i]
		}
		mp := make(map[int]int)
		mp[0] = 0
		for j := 0; j < n; j++ {
			f[j+1] = f[j] + 1
			if value, ok := mp[temp[j+1]]; ok {
				f[j+1] = min(f[j+1], f[value]+j-value)
			}
			mp[temp[j+1]] = j + 1

		}
		fmt.Println(f[n])
	}
}

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

package main

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

const MOD int64 = 1000000007

var n int

var a[]int

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

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

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n)

		a = make([]int,  n)

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

		fmt.Println(solve())
	}
}

type pair struct {
	v int
	idx []int
}

func solve() int {
	var mps [2]map[int]int

	mps[0] = make(map[int]int)
	mps[1] = make(map[int]int)

	mps[0][a[0]] = 0

	cnt := 0

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

		for k, v := range mps[cnt] {
			if k == 0 {
				if mps[cnt ^ 1][a[i]] == 0 {
					mps[cnt ^ 1][a[i]] = v
				} else {
					mps[cnt ^ 1][a[i]] = min(v, mps[cnt ^ 1][a[i]])
				}

			} else {
				if mps[cnt ^ 1][a[i]] == 0 {
					mps[cnt ^ 1][a[i]] = v + 1
				} else {
					mps[cnt ^ 1][a[i]] = min(v + 1, mps[cnt ^ 1][a[i]])
				}

				if mps[cnt ^ 1][k ^ a[i]] == 0 {
					mps[cnt ^ 1][k ^ a[i]] = v + 1
				} else {
					mps[cnt ^ 1][k ^ a[i]] = min(v + 1, mps[cnt ^ 1][k ^ a[i]])
				}

			}
		}

		for k := range mps[cnt] {
			delete(mps[cnt], k)
		}

		cnt ^= 1
	}

	var m int = n

	var mp map[int]int

	if len(mps[0]) > 0 {
		mp = mps[0]

	} else {
		mp = mps[1]
	}

	for k, v := range mp {
		if k == 0 {
			m = min(m , v)
		} else {
			m = min(m , v + 1)
		}
	}

	return m
}

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

	return b
}

//1 2 4 4 3

//0 - 1
//3 - 1

//IQ = 87

//........105....99...87..87..87..87.87.......87....

//            86

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

package main

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

var _, _, _ = main, rw, do

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

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var n int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}
		w1 := do(n, a)
		fmt.Fprintln(w, w1)
	}
}

func do(n int, a []int) int {
	m := make(map[int]bool)
	s := 0
	d := 0
	for i := range a {
		m[s] = true
		s ^= a[i]
		if m[s] {
			d++
			s = 0
			m = make(map[int]bool)
		}
	}
	return n - d
}

package main

import (
	"fmt"
	"os"
)

func main() {
	in := os.Stdin
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		temp := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &temp[i])
		}
		ans := 0
		j := 0
		for j < n {
			if temp[j] == 0 {
				j++
				continue
			}
			s := j
			j++
			for j < n {
				if temp[j] == temp[s] {
					j++
				} else {
					break
				}
			}
			if j == n {
				ll := j - s + 1
				ans += ll / 2
			} else if temp[j] == 0 {
				ll := j - s + 1
				ans += ll / 2
			} else {
				if j+1 < n && temp[j]^temp[s] == temp[j+1] {
					ll := j - s + 2
					ans += ll / 2
					temp[j] = temp[j] ^ temp[s]
				} else {
					ll := j - s + 1
					if ll%2 == 1 {
						ans += (ll - 1) / 2
					} else {
						ans += ll / 2
						temp[j] = temp[j] ^ temp[s]
					}
				}
			}

		}
		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {
	in := os.Stdin
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		temp := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &temp[i])
		}
		ans := 0
		j := 0
		for j < n {
			if temp[j] == 0 {
				j++
				continue
			}
			s := j
			j++
			for j < n {
				if temp[j] == temp[s] {
					j++
				} else {
					break
				}
			}
			if j == n {
				ll := j - s + 1
				ans += ll / 2
			} else {
				if temp[j] != 0 && (j+1 < n && temp[j]^temp[s] == temp[j+1]) {
					ll := j - s + 2
					ans += ll / 2
					temp[j] = temp[j] ^ temp[s]
				} else {
					ll := j - s + 1
					if ll%2 == 1 || temp[j] == 0 {
						ans += (ll - 1) / 2
					} else {
						ans += ll / 2
						temp[j] = temp[j] ^ temp[s]
					}
				}
			}

		}
		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {
	in := os.Stdin
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		temp := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &temp[i])
		}
		ans := 0
		j := 0
		for j < n {
			if temp[j] == 0 {
				j++
				continue
			}
			s := j
			j++
			for j < n {
				if temp[j] == temp[s] {
					j++
				} else {
					break
				}
			}
			if j == n {
				ll := j - s + 1
				ans += ll / 2
			} else {
				if j+1 < n && temp[j]^temp[s] == temp[j+1] {
					ll := j - s + 2
					ans += ll / 2
					temp[j] = temp[j] ^ temp[s]
				} else {
					ll := j - s + 1
					if ll%2 == 0 {
						ans += ll / 2
						temp[j] = temp[j] ^ temp[s]
					} else {
						ans += (ll - 1) / 2
					}
				}
			}

		}
		fmt.Println(ans)
	}
}

package main

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

const MOD int64 = 1000000007

var n int

var a[]int

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

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

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n)

		a = make([]int,  n)

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

		fmt.Println(solve())
	}
}

type pair struct {
	v int
	idx []int
}

func solve() int {
	var mps [2]map[int]int

	mps[0] = make(map[int]int)
	mps[1] = make(map[int]int)

	mps[0][a[0]] = 0

	cnt := 0

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

		for k, v := range mps[cnt] {
			if k == 0 {
				mps[cnt ^ 1][a[i]] = v

			} else {
				if mps[cnt ^ 1][a[i]] == 0 {
					mps[cnt ^ 1][a[i]] = v + 1
				} else {
					mps[cnt ^ 1][a[i]] = min(v + 1, mps[cnt ^ 1][a[i]])
				}

				if mps[cnt ^ 1][k ^ a[i]] == 0 {
					mps[cnt ^ 1][k ^ a[i]] = v + 1
				} else {
					mps[cnt ^ 1][k ^ a[i]] = min(v + 1, mps[cnt ^ 1][k ^ a[i]])
				}

			}
		}

		for k := range mps[cnt] {
			delete(mps[cnt], k)
		}

		cnt ^= 1
	}

	var m int = n

	var mp map[int]int

	if len(mps[0]) > 0 {
		mp = mps[0]

	} else {
		mp = mps[1]
	}

	for k, v := range mp {
		if k == 0 {
			m = min(m , v)
		} else {
			m = min(m , v + 1)
		}
	}

	return m
}

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

	return b
}

//1 2 4 4 3

//0 - 1
//3 - 1

//IQ = 87

//........105....99...87..87..87..87.87.......87....

//            86

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

package main

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

const MOD int64 = 1000000007

var n int

var a[]int

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

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

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n)

		a = make([]int,  n)

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

		fmt.Println(solve())
	}
}

type pair struct {
	v int
	idx []int
}

func solve() int {
	var mps [2]map[int]int

	mps[0] = make(map[int]int)
	mps[1] = make(map[int]int)

	mps[0][a[0]] = 0

	cnt := 0

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

		for k, v := range mps[cnt] {
			if k == 0 {
				mps[cnt ^ 1][a[i]] = v

			} else {
				if mps[cnt ^ 1][a[i]] == 0 {
					mps[cnt ^ 1][a[i]] = v + 1
				} else {
					mps[cnt ^ 1][a[i]] = min(v + 1, mps[cnt ^ 1][a[i]])
				}

				if mps[cnt ^ 1][k ^ a[i]] == 0 {
					mps[cnt ^ 1][k ^ a[i]] = v + 1
				} else {
					mps[cnt ^ 1][k ^ a[i]] = min(v + 1, mps[cnt ^ 1][k ^ a[i]])
				}

			}
		}

		for k := range mps[cnt] {
			delete(mps[cnt], k)
		}

		cnt ^= 1
	}

	var m int = n + 1

	var mp map[int]int

	if len(mps[0]) > 0 {
		mp = mps[0]

	} else {
		mp = mps[1]
	}

	for k, v := range mp {
		if k == 0 {
			m = min(m , v)
		} else {
			m = min(m , v + 1)
		}
	}

	return m
}

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

	return b
}

//1 2 4 4 3

//0 - 1
//3 - 1

//IQ = 87

//........105....99...87..87..87..87.87.......87....

//            86

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


Little Chris is a huge fan of linear algebra. This time he has been given a homework about the unusual square of a square matrix.The dot product of two integer number vectors x and y of size n is the sum of the products of the corresponding components of the vectors. The unusual square of an n × n square matrix A is defined as the sum of n dot products. The i-th of them is the dot product of the i-th row vector and the i-th column vector in the matrix A.Fortunately for Chris, he has to work only in GF(2)! This means that all operations (addition, multiplication) are calculated modulo 2. In fact, the matrix A is binary: each element of A is either 0 or 1. For example, consider the following matrix A:  The unusual square of A is equal to (1·1 + 1·0 + 1·1) + (0·1 + 1·1 + 1·0) + (1·1 + 0·1 + 0·0) = 0 + 1 + 1 = 0.However, there is much more to the homework. Chris has to process q queries; each query can be one of the following:   given a row index i, flip all the values in the i-th row in A;  given a column index i, flip all the values in the i-th column in A;  find the unusual square of A. To flip a bit value w means to change it to 1 - w, i.e., 1 changes to 0 and 0 changes to 1.Given the initial matrix A, output the answers for each query of the third type! Can you solve Chris's homework?

The first line of input contains an integer n (1 ≤ n ≤ 1000), the number of rows and the number of columns in the matrix A. The next n lines describe the matrix: the i-th line contains n space-separated bits and describes the i-th row of A. The j-th number of the i-th line aij (0 ≤ aij ≤ 1) is the element on the intersection of the i-th row and the j-th column of A. The next line of input contains an integer q (1 ≤ q ≤ 106), the number of queries. Each of the next q lines describes a single query, which can be one of the following:    1 i — flip the values of the i-th row;  2 i — flip the values of the i-th column;  3 — output the unusual square of A.  Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++.

Let the number of the 3rd type queries in the input be m. Output a single string s of length m, where the i-th symbol of s is the value of the unusual square of A for the i-th query of the 3rd type as it appears in the input.

package main

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

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

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

	n := nextInt()

	a := make([][]int, n)
	var result []uint8

	for row:=0; row<n; row++ {
		a[row] = make([]int, n)
		for col:=0; col<n; col++ {
			a[row][col] = nextInt()
		}
	}

	unsusualSquare := 0

	for i:=0; i<n; i++ {
		unsusualSquare += a[i][i]
	}

	unsusualSquare %= 2

	numberOfQueries := nextInt()

	for query:=0; query<numberOfQueries; query++ {
		typeOfQuery := nextInt()

		// switch typeOfQuery {

		// case 1,2 :
		// 	unsusualSquare = 1 - unsusualSquare
		// 	_ = nextInt()
		// case 3:
		// 	// print(unsusualSquare)
		// 	result = append(result, uint8(unsusualSquare + '0'))
		// }

		if typeOfQuery == 3 {
			// result = append(result, uint8(unsusualSquare + '0'))
			result = append(result, []uint8(strconv.Itoa(unsusualSquare))...)
		} else {
			unsusualSquare = 1 - unsusualSquare
			_ = nextInt()
		}
	}
	println(string(result))
}

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

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

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

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

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

	n := nextInt()

	a := make([][]int, n)

	for row:=0; row<n; row++ {
		a[row] = make([]int, n)
		for col:=0; col<n; col++ {
			a[row][col] = nextInt()
		}
	}

	unsusualSquare := 0

	for i:=0; i<n; i++ {
		unsusualSquare += a[i][i]
	}

	unsusualSquare %= 2

	numberOfQueries := nextInt()

	for query:=0; query<numberOfQueries; query++ {
		typeOfQuery := nextInt()

		switch typeOfQuery {
		// case 1:
		// 	// row := nextInt() - 1
		// 	// for i:=0; i<n; i++ {
		// 	// 	a[row][i] = 1 - a[row][i]
		// 	// }
		// case 2:
			// col := nextInt() - 1
			// for i:=0; i<n; i++ {
			// 	a[i][col] = 1 - a[i][col]
			// }
		case 1,2 :
			unsusualSquare = 1 - unsusualSquare
			_ = nextInt()
		case 3:
			// unsusualSquare := 0
			// for i:=0; i<n; i++ {
			// 	for j:=0; j<n; j++ {
			// 		unsusualSquare += (a[i][j] * a[j][i]) % 2
			// 	}
			// }
			// print(unsusualSquare%2)
			print(unsusualSquare)
		}
	}
	println()
}

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

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

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

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

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

    n := ScanInt()
    ans := 0
    for i := 0; i < n; i++ {
        for j := 0; j < n; j++ {
            a := ScanInt()
            if i == j { ans ^= a }
        }
    }
    q := ScanInt()
    for ; q > 0; q-- {
        t := ScanInt()
        if t == 3 {
            a := strconv.Itoa(ans)
            if a != "" {
                writer.WriteString(a)
            }
        } else {
            _ = ScanInt()
            ans ^= 1
        }
    }
    writer.WriteRune('\n')
    writer.Flush()
}

package main

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

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

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

    n := ScanInt()
    ans := 0
    for i := 0; i < n; i++ {
        for j := 0; j < n; j++ {
            a := ScanInt()
            if i == j { ans ^= a }
        }
    }
    q := ScanInt()
    for ; q > 0; q-- {
        t := ScanInt()
        if t == 3 {
            writer.WriteString(strconv.Itoa(ans))
        } else {
            _ = ScanInt()
            ans ^= 1
        }
    }
    writer.WriteRune('\n')
    writer.Flush()
}

/*********************************************************************************
*     File Name           :     C.go
*     Created By          :     YIMMON, yimmon.zhuang@gmail.com
*     Creation Date       :     [2014-03-29 23:16]
*     Last Modified       :     [2014-03-29 23:27]
*     Description         :
**********************************************************************************/

package main

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

func main() {
    scanner.Split(bufio.ScanWords)

    n := scanner.NextInt()
    var a = make([][]int8, n)
    for i := 0; i < n; i++ {
        a[i] = make([]int8, n)
        for j := 0; j < n; j++ {
            a[i][j] = int8(scanner.NextInt())
        }
    }
    ans := int8(0)
    for i := 0; i < n; i++ {
        for j := 0; j < n; j++ {
            ans ^= a[i][j] & a[j][i]
        }
    }
    q := scanner.NextInt()
    res := make([]byte, 0)
    for i := 0; i < q; i++ {
        t := scanner.NextInt()
        if t == 3 {
            res = append(res, byte(ans+'0'))
        } else {
            scanner.NextInt()
            ans ^= 1
        }
    }
    fmt.Println(string(res))
}

type Scanner struct {
    *bufio.Scanner
}

var scanner = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) Next() string {
    if !self.Scan() {
        panic(self.Err())
    }
    return self.Text()
}

func (self *Scanner) NextInt() int {
    x, err := strconv.Atoi(self.Next())
    if err != nil {
        panic(err)
    }
    return x
}

package main

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

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

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

	n := nextInt()

	a := make([][]int, n)
	var result []uint8

	for row:=0; row<n; row++ {
		a[row] = make([]int, n)
		for col:=0; col<n; col++ {
			a[row][col] = nextInt()
		}
	}

	unsusualSquare := 0

	for i:=0; i<n; i++ {
		unsusualSquare += a[i][i]
	}

	unsusualSquare %= 2

	numberOfQueries := nextInt()

	for query:=0; query<numberOfQueries; query++ {
		typeOfQuery := nextInt()

		switch typeOfQuery {
		// case 1:
		// 	// row := nextInt() - 1
		// 	// for i:=0; i<n; i++ {
		// 	// 	a[row][i] = 1 - a[row][i]
		// 	// }
		// case 2:
			// col := nextInt() - 1
			// for i:=0; i<n; i++ {
			// 	a[i][col] = 1 - a[i][col]
			// }
		case 1,2 :
			unsusualSquare = 1 - unsusualSquare
			_ = nextInt()
		case 3:
			// unsusualSquare := 0
			// for i:=0; i<n; i++ {
			// 	for j:=0; j<n; j++ {
			// 		unsusualSquare += (a[i][j] * a[j][i]) % 2
			// 	}
			// }
			// print(unsusualSquare%2)
			// print(unsusualSquare)
			result = append(result, uint8(unsusualSquare + '0'))
		}
	}
	// println()
	println(string(result))
}

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

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

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

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

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

	n := nextInt()

	// a := make([][]int, n)
	var result []uint8
	a, unsusualSquare := 0, 0

	for row:=0; row<n; row++ {
		// a[row] = make([]int, n)
		for col:=0; col<n; col++ {
			// a[row][col] = nextInt()
			a = nextInt()
			if row == col {
				unsusualSquare += a
			}
		}
	}

	// for i:=0; i<n; i++ {
	// 	unsusualSquare += a[i][i]
	// }

	unsusualSquare %= 2

	numberOfQueries := nextInt()

	for query:=0; query<numberOfQueries; query++ {
		typeOfQuery := nextInt()

		// switch typeOfQuery {

		// case 1,2 :
		// 	unsusualSquare = 1 - unsusualSquare
		// 	_ = nextInt()
		// case 3:
		// 	// print(unsusualSquare)
		// 	result = append(result, uint8(unsusualSquare + '0'))
		// }

		if typeOfQuery == 3 {
			// result = append(result, uint8(unsusualSquare + '0'))
			result = append(result, []uint8(strconv.Itoa(unsusualSquare))...)
		} else {
			unsusualSquare = 1 - unsusualSquare
			_ = nextInt()
		}
	}
	println(string(result))
	// println()
}

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

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var n,q int
    fmt.Scan(&n)
    ans := 0
    for i := 0; i < n; i++ {
        for j := 0; j < n; j++ {
            scanner.Scan()
            if i == j {
                a, _ := strconv.Atoi(scanner.Text())
                ans ^= a
            }
        }
    }
    fmt.Scan(&q)
    for ; q > 0; q-- {
        scanner.Scan()
        t, _ := strconv.Atoi(scanner.Text())
        if t == 3 {
            writer.WriteString(strconv.Itoa(ans))
        } else {
            scanner.Scan()
            ans ^= 1
        }
    }
    writer.WriteRune('\n')
    writer.Flush()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var n,q int
    fmt.Scan(&n)
    ans := 0
    for i := 0; i < n; i++ {
        for j := 0; j < n; j++ {
            scanner.Scan()
            if i == j {
                a, _ := strconv.Atoi(scanner.Text())
                ans ^= a
            }
        }
    }
    fmt.Scan(&q)
    for ; q > 0; q-- {
        scanner.Scan()
        t, _ := strconv.Atoi(scanner.Text())
        if t == 3 {
            a := strconv.Itoa(ans)
            if a != "" {
                writer.WriteString(a)
            }
        } else {
            scanner.Scan()
            ans ^= 1
        }
    }
    writer.WriteRune('\n')
    writer.Flush()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var n,q int
    fmt.Scan(&n)
    ans := 0
    for i := 0; i < n; i++ {
        for j := 0; j < n; j++ {
            scanner.Scan()
            if i == j {
                a, _ := strconv.Atoi(scanner.Text())
                ans ^= a
            }
        }
    }
    fmt.Scan(&q)
    for ; q > 0; q-- {
        for scanner.Scan() { if (scanner.Text() == "1") || (scanner.Text() == "2") || (scanner.Text() == "3") { break } }
        t, _ := strconv.Atoi(scanner.Text())
        if t == 3 {
            writer.WriteString(strconv.Itoa(ans))
        } else {
            scanner.Scan()
            ans ^= 1
        }
    }
    writer.WriteRune('\n')
    writer.Flush()
}