Even if it's a really easy question, she won't be able to answer it— Perfect Memento in Strict SenseCirno's perfect bitmasks classroom has just started!Cirno gave her students a positive integer $$$x$$$. As an assignment, her students need to find the minimum positive integer $$$y$$$, which satisfies the following two conditions:$$$$$$x\ \texttt{and}\ y > 0$$$$$$ $$$$$$x\ \texttt{xor}\ y > 0$$$$$$Where $$$\texttt{and}$$$ is the bitwise AND operation, and $$$\texttt{xor}$$$ is the bitwise XOR operation.Among the students was Mystia, who was truly baffled by all these new operators. Please help her!

The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of input test cases. For each test case, the only line of input contains one integer $$$x$$$ ($$$1 \leq x \leq 2^{30}$$$).

For each test case, print a single integer — the minimum number of $$$y$$$.

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x int
		fmt.Fscan(in,&x)
		if x == 1 {
			fmt.Fprintln(out,3)
		} else if x & 1 == 1 {
			fmt.Fprintln(out,1)
		} else if isIntegral(math.Log2(float64(x))) == true {
			fmt.Fprintln(out,x+1)
		} else {
			j:= 1
			for j <= x / 2 {
				j <<= 1
				if x & j > 0 {
					fmt.Fprintln(out,j)
					break
				}
			}
		}
	}
}
func isIntegral(x float64) bool {
	return float64(int(x)) == x
}

//

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x int
		fmt.Fscan(in,&x)
		if x < 3 {
			fmt.Fprintln(out,3)
		} else if x & 1 == 1 {
			fmt.Fprintln(out,1)
		} else if isIntegral(math.Log2(float64(x))) == true {
			fmt.Fprintln(out,x+1)
		} else {
			j:= 1
			for j <= x / 2 {
				j <<= 1
				if x & j > 0 {
					fmt.Fprintln(out,j)
					break
				}
			}
		}
	}
}
func isIntegral(x float64) bool {
	return float64(int(x)) == x
}

package main

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

func solve(in *bufio.Reader, out io.Writer) {
	var x uint
	fmt.Fscan(in, &x)
	tmp := x
	tot := 0
	for tmp != 0 {
		if (tmp & 1) != 0 {
			tot++
		}
		tmp >>= 1
	}
	ans := uint(0)
	for i := 0; i <= 30; i++ {
		var p uint
		p = uint(1 << uint(i))
		if (p&x) > 0 && tot > 1 {
			fmt.Fprintln(out, p)
			return
		}
		if (p&x) == 0 && ans == uint(0) {
			ans |= p
		}
		if (p & x) != 0 {
			tot -= 1
		}
	}
	for i := 0; i <= 30; i++ {
		var p uint
		p = uint(1 << uint(i))
		if (p & x) > 0 {
			ans |= p
			fmt.Fprintln(out, ans)

			return
		}
	}

}
func run(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var kase int
	fmt.Fscan(in, &kase)
	for mmm := 1; mmm <= kase; mmm++ {
		solve(in, out)
	}
	fmt.Fprintln(out, os.Getenv("ONLINE_JUDGE"))
}

func main() {

	file, err := os.Open("C:\\Users\\tiany\\GolandProjects\\awesomeProject\\data.txt")
	if err != nil {
		file = os.Stdin
	}
	run(file, os.Stdout)

}

package main

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

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 x int
	scan(&x)
	y := 1
	if x%2 == 1 {
		if x == 1 {
			y = 3
		} else {
			y = 1
		}
	} else {
		one := 0
		for i := 0; (1 << i) <= x; i++ {
			b := (x >> i) & 1
			if b == 1 {
				if one == 0 {
					y = 1 << i
				}
				one++
			}
		}
		if one == 1 {
			y += 1
		}
	}
	printf("%d\n", y)
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

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

func (in *CF1688A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1688A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1688A
Date: 14/06/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1688/A
Problem: CF1688A
**/
func (in *CF1688A) Run() {
	var str strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		ans := 0

		count := 0
		for i:=0;i<31;i++{
			if n&(1<<i) != 0 {
				count++
			}
		}

		and := false
		xor := count > 1

		for i := 0; i <= 30; i++ {
			if n&(1<<i) != 0 {
				if !and {
					ans = ans | (1 << i)
					and = true
				}
			}else {
				if !xor {
					ans = ans | (1 << i)
					xor = true
				}
			}

			if xor && and {
				break
			}
		}
		str.WriteString(fmt.Sprintf("%d\n", ans))
	}
	fmt.Print(str.String())
}

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

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

package main

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

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

func (in *CF1688A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1688A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1688A
Date: 14/06/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1688/A
Problem: CF1688A
**/
func (in *CF1688A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		ans := 0

		count := 0
		for i:=0;i<31;i++{
			if n&(1<<i) != 0 {
				count++
			}
		}

		and := false
		xor := count > 1

		for i := 0; i <= 30; i++ {
			if n&(1<<i) != 0 {
				if !and {
					ans = ans | (1 << i)
					and = true
				}
			}else {
				if !xor {
					ans = ans | (1 << i)
					xor = true
				}
			}

			if xor && and {
				break
			}
		}
		fmt.Println(ans)
	}
}

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

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

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 x, y int64
		fmt.Fscan(scanner, &x)
		for y = 1; x&y == 0; y = y << 1 {
		}
		for x&y == 0 || x^y == 0 {
			y++
		}
		fmt.Fprintln(writer, y)
	}
}

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++ {
		X := gi(); ans := 0
		if X == 1 {
			ans = 3
		} else {
			ans = 1
			for X & ans == 0 { ans = ans << 1 }
			if X ^ ans == 0 { ans |= 1 }
		}
		fmt.Fprintln(wrtr,ans)
	}
}

// 给定x 求最小的y使得x和y按位与和按位异或得到结果均大于0
//https://codeforces.com/contest/1688/problem/A#
/**
0&0 0
0&1 0
1&0 0
1&1 1

0^0 0
0^1 1
1^0 1
1^1 0

按位与 得到1xxxxxx，找到x二进制最高位数，设置为1，后续位数根据异或判定
若异或结果非0 此时为最小y
若异或结果0，从最小位开始增加直到不为0结束
**/

package main

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

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

	var testCases int
	Fscan(in, &testCases)

	for c := 0; c < testCases; c++ {
		var x, y int
		Fscan(in, &x)

		for i := 0; i < 31; i++ {
			y = 1 << i
			if x&y > 0 {
				break
			}
		}

		if x^y == 0 {
			for i := 0; i < 31; i++ {
				num := y | (1 << i)
				if x^num > 0 {
					y = num
					break
				}
			}
		}

		Fprintln(out, y)
	}

}

package main

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

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

	var testCases int
	Fscan(in, &testCases)

	for c := 0; c < testCases; c++ {
		var n int
		Fscan(in, &n)

		Fprintln(out, solve(n))
	}

}

func solve(n int) int {
	first_one := -1
	second_one := -1
	for i := 0; n > 0; i++ {
		d := n % 2
		if d == 1 {
			if first_one == -1 {
				first_one = i
			} else if second_one == -1 {
				second_one = i
			}
		}

		n = n / 2
	}

	bits := make([]int, max(first_one, second_one)+5)

	bits[first_one] = 1

	if second_one == -1 {
		if first_one > 0 {
			bits[0] = 1
		} else {

			bits[first_one+1] = 1
		}
	}

	ans := 0
	p := 1
	for i := range bits {
		ans = ans + bits[i]*p
		p = p * 2
	}
	return ans
}

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

package main

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

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

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

		if n&1 > 0 && n^1 > 0 {
			fmt.Fprintln(out, 1)
		} else if n == 1 {
			fmt.Fprintln(out, 3)
		} else {
			z := bits.TrailingZeros64(n)
			g := uint64(1 << z)
			if n&g > 0 && n^g > 0 {
				fmt.Fprintln(out, g)
			} else {
				fmt.Fprintln(out, g+1)
			}
		}
	}
}

package main

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

/*
0101
0001
0001
0100

1010
0010
0010
1001

0010
0011
0010
0001

*/

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

	y := 0

	for i := 0; i < 31; i++ {
		num := 1 << i
		if x&num > 0 {
			y = num
			break
		}
	}

	if x^y == 0 {
		for i := 0; i < 31; i++ {
			num := y | (1 << i)
			if x&num > 0 && x^num > 0 {
				y = num
				break
			}
		}
	}

	fmt.Fprintln(writer, y)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

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

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

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

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

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

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

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

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

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

	var T int
	var x int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &x)

		ans := 0
		if x == 1 {
			ans = 3
		} else if x%2 == 0 {
			lb := x & -x
			ans = lb
			if lb == x {
				ans++
			}
		} else {
			ans = 1
		}

		Fprintln(out, ans)
	}
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove() {
	var n int
	fmt.Fscan(r, &n)
	ans := 0
	i := 0
	cnt := 0
	for n != 0{
		if n % 2 == 1 {
			if ans == 0 {
				ans += (1<<i)
			}
			cnt++
		}
		n /= 2
		i++
	}
	if cnt == 1 {
		if ans == 1 {
			ans = 3
		} else {
			ans += 1
		}
	}
	fmt.Fprintln(w, ans)
}

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

func A1() {
	_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() {
		var n int
		Fscan(in, &n)
		if n == 1 {
			Fprintln(out, 3)
			return
		}
		var pos, cnt int
		for i := 30; i >= 0; i-- {
			if n&(1<<i) != 0 {
				cnt++
				pos = i
			}
		}
		if cnt == 1 {
			Fprintln(out, n+1)
			return
		}
		Fprintln(out, 1<<pos)
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A1() }

package main

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

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

func main() {
	defer out.Flush()

	var tc int
	for fmt.Fscan(in, &tc); tc > 0; tc-- {
		var x, y int
		fmt.Fscan(in, &x)
		if x == 1 {
			fmt.Fprintln(out, 3)
			continue
		}
		for y = 1; x&y == 0; y *= 2 {
		}
		if x == y {
			y++
		}
		fmt.Fprintln(out, y)
	}
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x int
		fmt.Fscan(in,&x)
		if x & 1 == 1 {
			fmt.Fprintln(out,1)
		} else if isIntegral(math.Log2(float64(x))) == true {
			fmt.Fprintln(out,x+1)
		} else {
			j:= 1
			for j <= x / 2 {
				j <<= 1
				if x & j > 0 {
					fmt.Fprintln(out,j)
					break
				}
			}
		}
	}
}
func isIntegral(x float64) bool {
	return float64(int(x)) == x
}

//

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x int
		fmt.Fscan(in,&x)
		for j:=1;j<=1000000;j++{
			if x & j > 0 && x ^ j > 0 {
				fmt.Fprintln(out,j)
				break
			}
		}
	}
}

package main

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

func run(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var kase int
	fmt.Fscan(in, &kase)
	for mmm := 1; mmm <= kase; mmm++ {

		var x int64
		fmt.Fscan(in, &x)
		tmp := x
		tot := 0
		for tmp != 0 {
			tot++
			tmp >>= 1
		}
		var ans uint
		ans = 0
		for i := 0; i <= 30; i++ {
			p := uint(1 << uint(i))
			if (uint(x) & p) == 0 {
				ans = (uint(x) | p)
				break
			}
		}
		fmt.Fprintln(out, ans)

	}
	fmt.Fprintln(out, os.Getenv("ONLINE_JUDGE"))
}

func main() {

	file, _ := os.Open("C:\\Users\\tiany\\GolandProjects\\awesomeProject\\data.txt")
	run(file, os.Stdout)

}

package main

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

func run(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var kase int
	fmt.Fscan(in, &kase)
	for mmm := 1; mmm <= kase; mmm++ {

		var x int64
		fmt.Fscan(in, &x)
		tmp := x
		tot := 0
		for tmp != 0 {
			tot++
			tmp >>= 1
		}
		var ans uint
		ans = 0
		for i := 0; i <= 30; i++ {
			p := uint(1 << uint(i))
			if (uint(x) & p) == 0 {
				ans = (uint(x) | p)
				break
			}
		}
		fmt.Fprintln(out, ans)
	}
}

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

package main

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

func run(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var kase int
	fmt.Scan(in, &kase)
	for mmm := 1; mmm <= kase; mmm++ {

		var x int64
		fmt.Fscan(in, &x)
		tmp := x
		tot := 0
		for tmp != 0 {
			tot++
			tmp >>= 1
		}
		var ans uint
		ans = 0
		for i := 0; i <= 30; i++ {
			p := uint(1 << uint(i))
			if (uint(x) & p) == 0 {
				ans = (uint(x) | p)
				break
			}
		}
		fmt.Fprintln(out, ans)
	}
}

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


It is winter now, and Max decided it's about time he watered the garden.The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned on, then after one second has passed, the bed xi will be watered; after two seconds have passed, the beds from the segment [xi - 1, xi + 1] will be watered (if they exist); after j seconds have passed (j is an integer number), the beds from the segment [xi - (j - 1), xi + (j - 1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [xi - 2.5, xi + 2.5] will be watered after 2.5 seconds have passed; only the segment [xi - 2, xi + 2] will be watered at that moment.  The garden from test 1. White colour denotes a garden bed without a tap, red colour — a garden bed with a tap.   The garden from test 1 after 2 seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour — a watered bed. Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!

The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 200). Then t test cases follow. The first line of each test case contains two integers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n) — the number of garden beds and water taps, respectively. Next line contains k integers xi (1 ≤ xi ≤ n) — the location of i-th water tap. It is guaranteed that for each  condition xi - 1 < xi holds. It is guaranteed that the sum of n over all test cases doesn't exceed 200. Note that in hacks you have to set t = 1.

For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.

NoteThe first example consists of 3 tests:  There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered.  There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes.  There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4.

package main

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

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	testsCount := ReadInt32()
	for testNumber := 1; testNumber <= testsCount; testNumber++ {
		bedsCount := ReadInt32()
		tapsCount := ReadInt32()
		answer := ReadInt32()
		preveousTapPosition := answer
		for tapNumber := 2; tapNumber <= tapsCount; tapNumber++ {
			tapPosition := ReadInt32()
			answer = max(answer, 1+(tapPosition-preveousTapPosition)/2)
			preveousTapPosition = tapPosition
		}
		writer.WriteString(strconv.Itoa(max(answer, 1+bedsCount-preveousTapPosition))+"\n")
	}
}

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

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

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


You are given an array $$$a$$$ consisting of $$$n$$$ integers (it is guaranteed that $$$n$$$ is even, i.e. divisible by $$$2$$$). All $$$a_i$$$ does not exceed some integer $$$k$$$.Your task is to replace the minimum number of elements (replacement is the following operation: choose some index $$$i$$$ from $$$1$$$ to $$$n$$$ and replace $$$a_i$$$ with some integer in range $$$[1; k]$$$) to satisfy the following conditions:  after all replacements, all $$$a_i$$$ are positive integers not greater than $$$k$$$;  for all $$$i$$$ from $$$1$$$ to $$$\frac{n}{2}$$$ the following equation is true: $$$a_i + a_{n - i + 1} = x$$$, where $$$x$$$ should be the same for all $$$\frac{n}{2}$$$ pairs of elements. 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 two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5, 1 \le k \le 2 \cdot 10^5$$$) — the length of $$$a$$$ and the maximum possible value of some $$$a_i$$$ correspondingly. It is guratanteed that $$$n$$$ is even (i.e. divisible by $$$2$$$). The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le k$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ (as well as the sum of $$$k$$$) over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$, $$$\sum k \le 2 \cdot 10^5$$$).

For each test case, print the answer — the minimum number of elements you have to replace in $$$a$$$ to satisfy the conditions from the problem statement.

package main

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

const MAX_N int = 4e5+10
const INF int = 0x3f3f3f3f

type Node struct {
	first int
	second int
}

type DifferArray struct {
	array [MAX_N]int
	num [MAX_N]int
}
func (this *DifferArray) add(left int, right int, num int) {
	if left > right {
		return
	}
	this.array[left] += num
	this.array[right+1] -= num
}
func (this *DifferArray) init(n int) {
	for i:=0; i<=n; i++ {
		this.array[i] = 0
	}
}
func (this *DifferArray) cal(n int) {
	this.num[0] = this.array[0]
	for i:=1; i<=n; i++ {
		this.num[i] = this.num[i-1]+this.array[i]
	}
}

func swap(a *int, b *int) {
	var c int = *a
	*a = *b
	*b = c
}

var read *bufio.Reader = bufio.NewReader(os.Stdin)
var write *bufio.Writer = bufio.NewWriter(os.Stdout)
var node [MAX_N]Node
var diff DifferArray

func main() {
	defer write.Flush()
	var t int
	fmt.Fscan(read, &t)
	for ; t>0; t-- {
		var n, k int
		fmt.Fscan(read, &n, &k)
		diff.init(k*2)
		for i:=0; i<n/2; i++ {
			fmt.Fscan(read, &node[i].first)
		}
		for i:=n/2-1; i>=0; i-- {
			fmt.Fscan(read, &node[i].second)
			if node[i].first>node[i].second {
				swap(&node[i].first, &node[i].second)
			}
		}
		for i:=0; i<n/2; i++ {
			var left int = 1+node[i].first
			var right int = k+node[i].second
			var mid int = node[i].first+node[i].second
			diff.add(2, left-1, 2)
			diff.add(left, mid-1, 1)
			diff.add(mid+1, right, 1)
			diff.add(right+1, k*2, 2)
		}
		diff.cal(k*2)
		var ans int = INF
		for i:=2; i<=k*2; i++ {
			if ans>diff.num[i] {
				ans = diff.num[i]
			}
		}
		fmt.Fprintln(write, ans)
		//write.Flush()
	}
}

package main

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

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 main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	for tc > 0 {
		tc--
		N, K := readTwoNums(reader)

		A := readNNums(reader, N)

		fmt.Println(solve(N, K, A))
	}
}

func solve(N int, K int, A []int) int {
	// double with 2, to avoid divide 2 get non-integer points
	// K *= 2

	h := N >> 1
	// var R int

	// ps := make([]Pair, h)
	cnt := make([]int, 2*K+1)

	for i := 0; i < h; i++ {
		cnt[A[i]+A[N-1-i]]++
	}

	pref := make([]int, 2*K+2)

	for i := 0; i < h; i++ {
		a, b := A[i], A[N-1-i]
		if a > b {
			a, b = b, a
		}
		// a < b
		pref[a+1]++
		pref[b+K+1]--
	}

	for i := 1; i < len(pref); i++ {
		pref[i] += pref[i-1]
	}

	best := N

	for sum := 2; sum <= 2*K; sum++ {
		temp := pref[sum] - cnt[sum] + (h-pref[sum])*2
		if temp < best {
			best = temp
		}
	}

	return best
}

// https://acm.timus.ru/problem.aspx?space=1&num=1741
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main () {
	var (
		T, n, K 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++ {
		fmt.Fscan(input, &n, &K)
		a := make([]int, n)
		for k := 0; k < n; k++ {
			fmt.Fscan(input, &a[k])
		}

		m := n / 2
		pref := make([]int, 2*K + 2)
		for k := 0; k < m; k++ {
			l := min(a[k], a[n - 1 - k]) + 1
			r := max(a[k], a[n - 1 - k]) + K
			pref[l]++
			pref[r + 1]--
		}

		for k := 1; k < len(pref); k++ {
			pref[k] = pref[k] + pref[k - 1]
		}

		x := make(map[int]int)
		for k := 0; k < m; k++ {
			x[a[k] + a[n - 1 - k]]++
		}

		ans := int(1e9)
		for k := 2; k <= 2*K; k++ {
			ans = min(ans, n - pref[k] - x[k])
		}

		fmt.Println(ans)
	}
}

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
}

/*
URL:
https://codeforces.com/problemset/problem/1343/D
*/

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, k int
	A    []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, k = ReadInt2()
		A = ReadIntSlice(n)

		solve()
	}
	stdout.Flush()
}

func solve() {
	ans := INF_BIT30

	cnts := make([]int, 2*k+100)
	prefs := make([]int, 2*k+100)

	for i := 0; i < n/2; i++ {
		l, r := A[i], A[n-1-i]

		cnts[l+r]++
		prefs[Min(l, r)+1]++
		prefs[Max(l, r)+k+1]--
	}
	for i := 1; i <= 2*k+10; i++ {
		prefs[i] += prefs[i-1]
	}

	for x := 2; x <= 2*k; x++ {
		tmp := prefs[x] - cnts[x] + (n/2-prefs[x])*2
		ChMin(&ans, tmp)
	}

	PrintfBufStdout("%d\n", ans)
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// func solve() {
// 	ans := INF_BIT30

// 	for x := 2; x <= 2*k; x++ {
// 		tmp := BinarySearch(n, -1, func(mid int) bool {
// 			cnt := 0
// 			for i := 0; i < n/2; i++ {
// 				l, r := A[i], A[n-1-i]
// 				s := l + r

// 				if s == x {
// 					continue
// 				}

// 				if (x-r >= 1 && x-r <= k) || (x-l >= 1 && x-l <= k) {
// 					cnt++
// 				} else {
// 					cnt += 2
// 				}

// 				if cnt > mid {
// 					return false
// 				}
// 			}

// 			return cnt <= mid
// 		})

// 		ChMin(&ans, tmp)
// 	}

// 	PrintfBufStdout("%d\n", ans)
// }

func BinarySearch(initOK, initNG int, isOK func(mid int) bool) (ok int) {
	ng := initNG
	ok = initOK
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}

	return ok
}

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

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

/*********** 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"
)

func main() {
	var i int32
	inBuf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(inBuf, "%d\n", &i)
	for ; i > 0; i-- {
		var n int32
		var k int32
		fmt.Fscanf(inBuf, "%d %d\n", &n, &k)
		var ans int32 = n
		numbers := make([]int32, n)
		format := "%d"
		for t := int32(0); t < n; t++ {
			fmt.Fscanf(inBuf, format, &numbers[t])
			format = " %d"
		}

		fmt.Fscanf(inBuf, "\n", nil)
		res := make([]int32, k*2+2)
		for t := int32(0); t < n/2; t++ {
			sum := numbers[t] + numbers[n-t-1]
			low := sum
			if numbers[t] < numbers[n-t-1] {
				low = sum - (numbers[n-t-1] - 1)
			} else {
				low = sum - (numbers[t] - 1)
			}
			high := sum
			if numbers[t] < numbers[n-t-1] {
				high = sum + (k - numbers[t])
			} else {
				high = sum + (k - numbers[n-t-1])
			}
			res[0] += 2
			res[low] += -1
			res[high+1] += 1
			res[sum] += -1
			res[sum+1] += 1
		}
		for t := int32(1); t <= k*2+1; t++ {
			res[t] += res[t-1]
			if ans > res[t] {
				ans = res[t]
			}
		}
		fmt.Println(ans)
	}
}

package main

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

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

	var t, n, k int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		ps := make([]int, 2*k+2)
		for i, v := range a[:n/2] {
			w := a[n-1-i]
			if v > w {
				v, w = w, v
			}
			ps[v+1]--
			ps[v+w]--
			ps[v+w+1]++
			ps[w+k+1]++
		}
		ans := n
		c := n
		for _, d := range ps {
			c += d
			if c < ans {
				ans = c
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1343D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ v, delta int }

	var t, n, k int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		ps := make([]pair, 0, 2*n)
		for i, v := range a[:n/2] {
			w := a[n-1-i]
			if v > w {
				v, w = w, v
			}
			ps = append(ps, pair{v+1, -1}, pair{v + w, -1}, pair{v + w + 1, 1}, pair{w + k + 1, 1})
		}
		sort.Slice(ps, func(i, j int) bool { return ps[i].v < ps[j].v })
		ans := n
		c := n
		for i := 0; i < 2*n; {
			c += ps[i].delta
			for i++; i < 2*n && ps[i].v == ps[i-1].v; i++ {
				c += ps[i].delta
			}
			if c < ans {
				ans = c
			}
		}
		Fprintln(out, ans)
	}
}

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

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/1343/D

package main

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

type Pair struct {
	L int
	R int
}

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
}

func Solve(n int, k int, a []int) int {
	pairs := make([]Pair, n/2)
	sums := make(map[int]int)
	for i := 0; i < n/2; i++ {
		x := a[i]
		y := a[n-i-1]
		pairs[i] = Pair{min(x, y) + 1, max(x, y) + k}
		sums[x+y] += 1
	}
	prefix := make([]int, 2*k+2)
	for _, p := range pairs {
		prefix[p.L] += 1
		prefix[p.R+1] -= 1
	}
	for i := 1; i < 2*k+1; i++ {
		prefix[i] += prefix[i-1]
	}
	ans := math.MaxInt32
	for i := 2; i <= 2*k; i++ {
		ans = min(ans, prefix[i]-sums[i]+2*(n/2-prefix[i]))
	}
	return ans
}

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, k int
		fmt.Fscanf(reader, "%d %d\n", &n, &k)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &a[i])
		}
		fmt.Fscanf(reader, "\n")
		fmt.Fprintf(writer, "%d\n", Solve(n, k, a))
	}
}

package main

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

const MAX_N int = 4e5+10
const INF int = 0x3f3f3f3f

type Node struct {
	first int
	second int
}

type DifferArray struct {
	array [MAX_N]int
	num [MAX_N]int
}
func (this *DifferArray) add(left int, right int, num int) {
	if left > right {
		return
	}
	this.array[left] += num
	this.array[right+1] -= num
}
func (this *DifferArray) init(n int) {
	for i:=0; i<=n; i++ {
		this.array[i] = 0
	}
}
func (this *DifferArray) cal(n int) {
	this.num[0] = this.array[0]
	for i:=1; i<=n; i++ {
		this.num[i] = this.num[i-1]+this.array[i]
	}
}

func swap(a *int, b *int) {
	var c int = *a
	*a = *b
	*b = c
}

var read *bufio.Reader = bufio.NewReader(os.Stdin)
var write *bufio.Writer = bufio.NewWriter(os.Stdout)
var node [MAX_N]Node
var diff DifferArray

func main() {
	defer write.Flush()
	var t int
	fmt.Fscan(read, &t)
	for ; t>0; t-- {
		var n, k int
		fmt.Fscan(read, &n, &k)
		diff.init(k*2)
		for i:=0; i<n/2; i++ {
			fmt.Fscan(read, &node[i].first)
		}
		for i:=n/2-1; i>=0; i-- {
			fmt.Fscan(read, &node[i].second)
			if node[i].first<node[i].second {
				swap(&node[i].first, &node[i].second)
			}
		}
		for i:=0; i<n/2; i++ {
			var left int = 1+node[i].first
			var right int = k+node[i].second
			var mid int = node[i].first+node[i].second
			diff.add(2, left-1, 2)
			diff.add(left, mid-1, 1)
			diff.add(mid+1, right, 1)
			diff.add(right+1, k*2, 2)
		}
		diff.cal(k*2)
		var ans int = INF
		for i:=2; i<=k*2; i++ {
			if ans>diff.num[i] {
				ans = diff.num[i]
			}
		}
		fmt.Fprintln(write, ans)
		//write.Flush()
	}
}

package main

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

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 main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	for tc > 0 {
		tc--
		N, K := readTwoNums(reader)

		A := readNNums(reader, N)

		fmt.Println(solve(N, K, A))
	}
}

func solve(N int, K int, A []int) int {
	// double with 2, to avoid divide 2 get non-integer points
	// K *= 2
	mem := make(map[int]int)
	y := NewBit(yy, MAX_K)
	h := N >> 1
	// var R int

	// ps := make([]Pair, h)

	for i := 0; i < h; i++ {
		a, b := A[i], A[N-1-i]
		if a > b {
			a, b = b, a
		}
		y.Set(b, 1)
		// ps[i] = Pair{a, b}
		mem[a+b]++
	}

	// sort.Sort(Pairs(ps))

	// D := ps[0].x + ps[0].y

	var best = N

	for d := 2 * K; d > 0; d-- {
		// cnt0 is the points at x + y == d
		var cnt0 int = mem[d]

		cnt := h - cnt0

		if d > K {
			// d - y > k
			// y < d - k
			// x0 + y0 < d
			// inorder to get x + y0 == d, the better way is to make x = d - y
			// but if y0 < d / 2, it will make x > d / 2 => x > K,
			// so we cant just replace one, instead, we need to replace two
			// because x <= y for all points
			cnt2 := y.Get(d - K - 1)
			cnt = 2*cnt2 + (h - cnt2 - cnt0)
		} else {
			// we can't replace any elements as 0,
			// x + y = d, if y >= d, then we have to make x = 0
			cnt2 := h - y.Get(d-1)
			cnt = 2*cnt2 + (h - cnt2 - cnt0)
		}

		if cnt < best {
			best = cnt
		}
	}

	return best
}

type Pair struct {
	x int
	y int
}

type Pairs []Pair

func (ps Pairs) Len() int {
	return len(ps)
}

func (ps Pairs) Less(i, j int) bool {
	return ps[i].x+ps[i].y > ps[j].x+ps[j].y
}

func (ps Pairs) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}

const MAX_K = 200000

// var xx []int
var yy []int

func init() {
	// xx = make([]int, MAX_K+1)
	yy = make([]int, MAX_K+1)
}

type Bit struct {
	arr []int
	n   int
}

func NewBit(arr []int, n int) Bit {

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

	return Bit{arr[:n+1], n}
}

func (bit *Bit) Set(pos int, v int) {
	pos++
	for pos <= bit.n {
		bit.arr[pos] += v
		pos += pos & -pos
	}
}

func (bit Bit) Get(pos int) int {
	pos++
	var res int
	for pos > 0 {
		res += bit.arr[pos]
		pos -= pos & -pos
	}
	return res
}

package main

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

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 main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	for tc > 0 {
		tc--
		N, K := readTwoNums(reader)

		A := readNNums(reader, N)

		fmt.Println(solve(N, K, A))
	}
}

func solve(N int, K int, A []int) int {
	// double with 2, to avoid divide 2 get non-integer points
	// K *= 2
	mem := make(map[int]int)
	y := NewBit(yy, MAX_K)
	h := N >> 1
	// var R int

	// ps := make([]Pair, h)

	for i := 0; i < h; i++ {
		a, b := A[i], A[N-1-i]
		if a > b {
			a, b = b, a
		}
		y.Set(b, 1)
		// ps[i] = Pair{a, b}
		mem[a+b]++
	}

	// sort.Sort(Pairs(ps))

	// D := ps[0].x + ps[0].y

	var best = N

	for d := 2 * K; d > 0; d-- {
		// cnt0 is the points at x + y == d
		var cnt0 int = mem[d]

		y.Set(d, -cnt0)

		// if y >= d, x + y == d, then x <= 0, which should be avoided
		// and d - K - 1 < d - 1 < d
		var cnt2 int = h - y.Get(d-1)

		y.Set(d, cnt0)

		if d > K {
			// d - y > k
			// y < d - k
			// x0 + y0 < d
			// inorder to get x + y0 == d, the better way is to make x = d - y
			// but if y0 < d - k, it will make x = d - y0 > k
			// so we cant just replace one, instead, we need to replace two
			// because x <= y for all points
			cnt2 += y.Get(d - K - 1)
		}

		cnt := 2*cnt2 + (h - cnt2 - cnt0)

		if cnt < best {
			best = cnt
		}
	}

	return best
}

type Pair struct {
	x int
	y int
}

type Pairs []Pair

func (ps Pairs) Len() int {
	return len(ps)
}

func (ps Pairs) Less(i, j int) bool {
	return ps[i].x+ps[i].y > ps[j].x+ps[j].y
}

func (ps Pairs) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}

const MAX_K = 200000

// var xx []int
var yy []int

func init() {
	// xx = make([]int, MAX_K+1)
	yy = make([]int, MAX_K+1)
}

type Bit struct {
	arr []int
	n   int
}

func NewBit(arr []int, n int) Bit {

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

	return Bit{arr[:n+1], n}
}

func (bit *Bit) Set(pos int, v int) {
	pos++
	for pos <= bit.n {
		bit.arr[pos] += v
		pos += pos & -pos
	}
}

func (bit Bit) Get(pos int) int {
	pos++
	var res int
	for pos > 0 {
		res += bit.arr[pos]
		pos -= pos & -pos
	}
	return res
}

package main

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

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 main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	for tc > 0 {
		tc--
		N, K := readTwoNums(reader)

		A := readNNums(reader, N)

		fmt.Println(solve(N, K, A))
	}
}

func solve(N int, K int, A []int) int {
	// double with 2, to avoid divide 2 get non-integer points
	// K *= 2
	mem := make(map[int]int)
	y := NewBit(yy, MAX_K)
	h := N >> 1
	// var R int

	// ps := make([]Pair, h)

	for i := 0; i < h; i++ {
		a, b := A[i], A[N-1-i]
		if a > b {
			a, b = b, a
		}
		y.Set(b, 1)
		// ps[i] = Pair{a, b}
		mem[a+b]++
	}

	// sort.Sort(Pairs(ps))

	// D := ps[0].x + ps[0].y

	var best = N

	for d := 2 * K; d > 0; d-- {
		// cnt0 is the points at x + y == d
		var cnt0 int = mem[d]

		// if y >= d, x + y == d, then x <= 0, which should be avoided
		// and d - K - 1 < d - 1
		var cnt2 int = h - y.Get(d-1)

		if d > K {
			// d - y > k
			// y < d - k
			// x0 + y0 < d
			// inorder to get x + y0 == d, the better way is to make x = d - y
			// but if y0 < d / 2, it will make x > d / 2 => x > K,
			// so we cant just replace one, instead, we need to replace two
			// because x <= y for all points
			cnt2 += y.Get(d - K - 1)
		}

		cnt := 2*cnt2 + (h - cnt2 - cnt0)

		if cnt < best {
			best = cnt
		}
	}

	return best
}

type Pair struct {
	x int
	y int
}

type Pairs []Pair

func (ps Pairs) Len() int {
	return len(ps)
}

func (ps Pairs) Less(i, j int) bool {
	return ps[i].x+ps[i].y > ps[j].x+ps[j].y
}

func (ps Pairs) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}

const MAX_K = 200000

// var xx []int
var yy []int

func init() {
	// xx = make([]int, MAX_K+1)
	yy = make([]int, MAX_K+1)
}

type Bit struct {
	arr []int
	n   int
}

func NewBit(arr []int, n int) Bit {

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

	return Bit{arr[:n+1], n}
}

func (bit *Bit) Set(pos int, v int) {
	pos++
	for pos <= bit.n {
		bit.arr[pos] += v
		pos += pos & -pos
	}
}

func (bit Bit) Get(pos int) int {
	pos++
	var res int
	for pos > 0 {
		res += bit.arr[pos]
		pos -= pos & -pos
	}
	return res
}

// https://acm.timus.ru/problem.aspx?space=1&num=1741
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main () {
	var (
		T, n, kk 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++ {
		fmt.Fscan(input, &n, &kk)
		pp := 0
		a := make([]int, n)
		for k := 0; k < n; k++ {
			fmt.Fscan(input, &a[k])
		}

		m := n / 2
		x := make(map[int]int)

		for k := 0; k < m; k++ {
			if a[k] < kk && a[n - 1 - k] < kk {
				pp ++
			}
			x[a[k] + a[n - 1 - k]]++
		}

		maxV := 0
		for _, v := range x {
			maxV = max(v, maxV)
		}

		fmt.Println(m - maxV + pp)
	}
}

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

// https://acm.timus.ru/problem.aspx?space=1&num=1741
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main () {
	var (
		T, n, K 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++ {
		fmt.Fscan(input, &n, &K)
		a := make([]int, n)
		for k := 0; k < n; k++ {
			fmt.Fscan(input, &a[k])
		}

		m := n / 2
		pref := make([]int, 2*K + 2)
		for k := 0; k < m; k++ {
			l := min(a[k], a[n - 1 - k]) + 1
			r := max(a[k], a[n - 1 - k]) + K
			pref[l]++
			pref[r + 1]--
		}

		for k := 1; k < len(pref); k++ {
			pref[k] = pref[k] + pref[k - 1]
		}

		x := make(map[int]int)
		for k := 0; k < m; k++ {
			x[a[k] + a[n - 1 - k]]++
		}

		ans := int(1e9)
		for k := 0; k < 2*K; k++ {
			ans = min(ans, n - pref[k] - x[k])
		}

		fmt.Println(ans)
	}
}

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
}

package main

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

func main() {
	var i int32
	inBuf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(inBuf, "%d\n", &i)
	for ; i > 0; i-- {
		var n int32
		var k int32
		fmt.Fscanf(inBuf, "%d %d\n", &n, &k)
		var ans int32 = n
		numbers := make([]int32, n)
		format := "%d"
		for t := int32(0); t < n; t++ {
			fmt.Fscanf(inBuf, format, &numbers[t])
			format = " %d"
		}

		fmt.Fscanf(inBuf, "\n", nil)
		res := make([]int32, k*2+2)
		for t := int32(0); t < n/2; t++ {
			sum := numbers[t] + numbers[n-t-1]
			low := sum
			if numbers[t] < numbers[n-t-1] {
				low = sum - (numbers[n-t-1] - 1)
			} else {
				low = sum - (numbers[t] - 1)
			}
			high := sum
			if numbers[t] < numbers[n-t-1] {
				high = sum + (k - numbers[t])
			} else {
				high = sum + (k - numbers[n-t-1])
			}
			res[0] += 2
			res[low-1] += -1
			res[high+1] += 1
			res[sum] += -1
			res[sum+1] += 1
		}
		for t := int32(1); t <= k*2+1; t++ {
			res[t] += res[t-1]
			if ans > res[t] {
				ans = res[t]
			}
		}
		fmt.Println(ans)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1343D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ v, delta int }

	var t, n, k int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		ps := make([]pair, 0, 2*n)
		for i, v := range a[:n/2] {
			w := a[n-1-i]
			if v > w {
				v, w = w, v
			}
			ps = append(ps, pair{v, -1}, pair{v + w, -1}, pair{v + w + 1, 1}, pair{w + k + 1, 1})
		}
		sort.Slice(ps, func(i, j int) bool { return ps[i].v < ps[j].v })
		ans := n
		c := n
		for i := 0; i < 2*n; {
			c += ps[i].delta
			for i++; i < 2*n && ps[i].v == ps[i-1].v; i++ {
				c += ps[i].delta
			}
			if c < ans {
				ans = c
			}
		}
		Fprintln(out, ans)
	}
}

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


There are $$$n$$$ segments $$$[l_i, r_i]$$$ for $$$1 \le i \le n$$$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.To optimize testing process you will be given multitest.

The first line contains one integer $$$T$$$ ($$$1 \le T \le 50000$$$) — the number of queries. Each query contains description of the set of segments. Queries are independent. First line of each query contains single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — number of segments. It is guaranteed that $$$\sum{n}$$$ over all queries does not exceed $$$10^5$$$. The next $$$n$$$ lines contains two integers $$$l_i$$$, $$$r_i$$$ per line ($$$1 \le l_i \le r_i \le 2 \cdot 10^5$$$) — the $$$i$$$-th segment.

For each query print $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$ ($$$t_i \in \{1, 2\}$$$) — for each segment (in the same order as in the input) $$$t_i$$$ equals $$$1$$$ if the $$$i$$$-th segment will belongs to the first group and $$$2$$$ otherwise. If there are multiple answers, you can print any of them. If there is no answer, print $$$-1$$$.

NoteIn the first query the first and the second segments should be in different groups, but exact numbers don't matter.In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $$$-1$$$.In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $$$6$$$ possible is correct.

package main

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

type otr [3]int
type test []otr
type tests []test

func (s test) Len() int {
	return len(s)
}
func (s test) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
func (s test) Less(i, j int) bool {
	return s[i][0] < s[j][0]
}

func ansver(a test) string {
	n := len(a)
	ares := make([]string, n)
	res := "-1"
	for i := 0; i < n; i++ {
		ares[i] = "2"
	}
	sort.Slice(a, func(i, j int) bool { return a[i][0] < a[j][0] })
	//sort.Sort(a)
	ares[a[0][2]] = "1"
	amax := a[0][1]
	r := false
	for _, ai := range a {
		if amax < ai[0] {
			r = true
			break
		} else {
			ares[ai[2]] = "1"
			if amax < ai[1] {
				amax = ai[1]
			}
		}
	}
	if r {
		res = strings.Join(ares, " ")
	}
	return res
}

func main() {

	read := bufio.NewReader(os.Stdin)
	write := bufio.NewWriter(os.Stdout)
	var t int
	//fmt.Scan(&t)
	fmt.Fscan(read, &t)

	tsts := make([]test, t)
	for i := 0; i < t; i++ {
		var n int
		//fmt.Scan(&n)
		fmt.Fscan(read, &n)
		tsi := make(test, n)
		for j := 0; j < n; j++ {
			var x, y int
			//fmt.Scan(&x, &y)
			fmt.Fscan(read, &x, &y)
			oj := otr{x, y, j}
			tsi[j] = oj
		}
		tsts[i] = tsi
	}
	for i := 0; i < t; i++ {
		//fmt.Println(ansver(tsts[i]))
		fmt.Fprintln(write, ansver(tsts[i]))
	}

	write.Flush()
}

package main

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

type LR struct{ L, R, I uint32 }

type CaseInput struct {
	lrs []LR
}

func readCaseInput(scanner *bufio.Scanner) CaseInput {
	size := readInt(scanner)
	nums := make([]LR, size)
	for i := range nums {
		nums[i] = LR{
			uint32(readInt(scanner)),
			uint32(readInt(scanner)),
			uint32(i),
		}
	}
	return CaseInput{nums}
}

type caseOutput struct {
	Grouping []bool
}

func writeCaseOutput(writer *bufio.Writer, out caseOutput) {
	if len(out.Grouping) == 0 {
		writef(writer, "-1\n")
	} else {
		for _, g := range out.Grouping {
			if g {
				writef(writer, "2 ")
			} else {
				writef(writer, "1 ")
			}
		}
		writef(writer, "\n")
	}
}

type LRSlice []LR

func (lrs LRSlice) Len() int           { return len(lrs) }
func (lrs LRSlice) Less(i, j int) bool { return lrs[i].L < lrs[j].L || lrs[i].L == lrs[j].L && lrs[i].R < lrs[j].R }
func (lrs LRSlice) Swap(i, j int)      { lrs[i], lrs[j] = lrs[j], lrs[i] }

func solveCase(in CaseInput) caseOutput {
	sort.Sort(LRSlice(in.lrs))

	maxR := in.lrs[0].R
	for i, lr := range in.lrs {
		if i == 0 {
			continue
		}

		if lr.L > maxR {
			grouping := make([]bool, len(in.lrs))
			for _, resLR := range in.lrs[:i] {
				grouping[resLR.I] = true
			}
			return caseOutput{ grouping }
		}

		if maxR < lr.R {
			maxR = lr.R
		}
	}

	return caseOutput{make([]bool, 0)}
}

func solveSequential(scanner *bufio.Scanner, writer *bufio.Writer) {
	caseNum := readInt(scanner)
	for i := 0; i < caseNum; i++ {
		writeCaseOutput(writer, solveCase(readCaseInput(scanner)))
	}
}

func main() {
	var scanner *bufio.Scanner
	if len(os.Args) > 1 {
		reader, err := os.Open(os.Args[1])
		if err != nil {
			panic(err)
		}
		defer reader.Close()
		scanner = bufio.NewScanner(reader)
	} else {
		scanner = bufio.NewScanner(os.Stdin)
	}
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 0, 1024*1024), 1024*1024)

	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	solveSequential(scanner, writer)
}

func readInt64(sc *bufio.Scanner) int64 {
	if !sc.Scan() {
		panic("failed to scan next token")
	}

	res, err := strconv.ParseInt(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func readInt(sc *bufio.Scanner) int {
	return int(readInt64(sc))
}

func writef(writer *bufio.Writer, formatStr string, values ...interface{}) {
	out := fmt.Sprintf(formatStr, values...)
	_, err := writer.WriteString(out)
	if err != nil {
		panic(err)
	}
}

package main

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

type pair struct {
	x, y, z int
}

func (a pair) greaterThan(b pair) bool {
	if a.x >= b.x {
		return true
	}
	return false
}

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

func swap(arr []pair, x, y int) {
	var tmp = arr[x]
	arr[x] = arr[y]
	arr[y] = tmp
}

func heapify(arr []pair, root int) {
	var n = len(arr)
	var l, r = 2*root + 1, 2*root + 2
	var pos = root
	if l < n && arr[l].greaterThan(arr[pos]) {
		pos = l
	}
	if r < n && arr[r].greaterThan(arr[pos]) {
		pos = r
	}
	if pos != root {
		swap(arr, root, pos)
		heapify(arr, pos)
	}
}

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)

	// Heap sort
	var t, n int
	fmt.Fscan(stdin, &t)

	for t > 0 {
		t--
		fmt.Fscan(stdin, &n)
		var arr = make([]pair, n)
		var mark = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(stdin, &arr[i].x, &arr[i].y)
			arr[i].z = i
		}
		// Build max heap
		for i := n/2 - 1; i >= 0; i-- {
			heapify(arr, i)
		}

		for i := n; i > 0; i-- {
			swap(arr, 0, i-1)
			heapify(arr[:i-1], 0)
		}

		var res = []pair{arr[0]}
		mark[arr[0].z] = 1
		for i := 1; i < n; i++ {
			var last = len(res) - 1
			if res[last].x <= arr[i].x && arr[i].x <= res[last].y {
				res[last].y = max(arr[i].y, res[last].y)
				mark[arr[i].z] = last + 1
			} else {
				res = append(res, arr[i])
				mark[arr[i].z] = last + 2
			}
		}
		if len(res) == 1 {
			fmt.Println(-1)
		} else {
			for i := 0; i < n; i++ {
				if mark[i] > 1 {
					fmt.Print(2, " ")
				} else {
					fmt.Print(1, " ")
				}
			}
			fmt.Println()
		}
	}

}

package main

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

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

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

func init() {
	// const maxCapacity = SIZE
	// buf := make([]byte, maxCapacity)
	// scanner.Buffer(buf, maxCapacity)
	scanner.Split(bufio.ScanWords)
}

type ii struct {
	ini, fim int
}

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 main() {
	defer writer.Flush()

	t := ReadInt()

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

		n := ReadInt()

		v := make([]ii, n)

		mapa := make(map[ii][]int)

		for i := 0; i < n; i++ {
			v[i] = ii{ReadInt(), ReadInt()}
			mapa[v[i]] = append(mapa[v[i]], i)
		}

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

		resp := make([]int, n)

		fim := v[0].fim
		resp[0] = 1

		comeca := -1

		for i := 1; i < n; i++ {
			if fim >= v[i].ini {
				fim = max(fim, v[i].fim)
				resp[i] = 1
			} else {
				comeca = i
				break
			}
		}

		respFinal := make([]int, n)

		if comeca != -1 {
			for i, elem := range resp {
				if elem == 0 {
					respFinal[mapa[v[i]][0]] = 2
					mapa[v[i]] = mapa[v[i]][1:]
				} else {
					respFinal[mapa[v[i]][0]] = 1
					mapa[v[i]] = mapa[v[i]][1:]
				}
			}

			for _, elem := range respFinal {
				writer.WriteString(strconv.Itoa(elem))
				writer.WriteString(" ")
			}
			writer.WriteString("\n")
		} else {
			writer.WriteString("-1\n")
		}
	}
}

package main

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

type caseInput struct {
	BayanStr string
}

func readCaseInput(scanner *bufio.Scanner) caseInput {
	return caseInput{readString(scanner)}
}

type caseOutput struct {
	BayanLen int32
}

func writeCaseOutput(writer *bufio.Writer, out caseOutput) {
	writef(writer, "%d\n", out.BayanLen)
}

func solveCase(in caseInput) caseOutput {
	opened := false
	firstColonSeen := false
	closingColonSeen := false
	closed := false

	pipesTotal := uint32(0)
	pipesCloseable := uint32(0)
	pipesPendingClose := uint32(0)

	for _, c := range []rune(in.BayanStr) {
		if !opened {
			if c == '[' {
				opened = true
			}
			continue
		}

		if opened && !firstColonSeen {
			if c == ':' {
				firstColonSeen = true
			}
			continue
		}

		if opened && firstColonSeen {
			if c == '|' {
				pipesPendingClose += 1
			} else if c == ':' {
				pipesCloseable += pipesPendingClose
				pipesPendingClose = 0
				closingColonSeen = true
			} else if c == ']' {
				if closingColonSeen {
					closed = true
					pipesTotal = pipesCloseable
				}
			}
		}

	}

	if closed {
		return caseOutput{int32(4 + pipesTotal)}
	}
	return caseOutput{int32(-1)}
}

func solveSequential(scanner *bufio.Scanner, writer *bufio.Writer) {
	writeCaseOutput(writer, solveCase(readCaseInput(scanner)))
}

func main() {
	var scanner *bufio.Scanner
	if len(os.Args) > 1 {
		reader, err := os.Open(os.Args[1])
		if err != nil {
			panic(err)
		}
		defer reader.Close()
		scanner = bufio.NewScanner(reader)
	} else {
		scanner = bufio.NewScanner(os.Stdin)
	}
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 0, 1024*1024), 1024*1024)

	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	solveSequential(scanner, writer)
}

func readString(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic("failed to scan next token")
	}

	return sc.Text()
}

func writef(writer *bufio.Writer, formatStr string, values ...interface{}) {
	out := fmt.Sprintf(formatStr, values...)
	_, err := writer.WriteString(out)
	if err != nil {
		panic(err)
	}
}

package main

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

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

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

func init() {
	// const maxCapacity = SIZE
	// buf := make([]byte, maxCapacity)
	// scanner.Buffer(buf, maxCapacity)
	scanner.Split(bufio.ScanWords)
}

type ii struct {
	ini, fim int
}

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

func main() {
	defer writer.Flush()

	t := ReadInt()

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

		n := ReadInt()

		v := make([]ii, n)

		for i := 0; i < n; i++ {
			v[i] = ii{ReadInt(), ReadInt()}
		}

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

		leftMax := v[0].fim
		rightMin := v[len(v)-1].ini

		fim := false

		if leftMax >= rightMin {
			fim = true
		}

		for i := 1; i < n-1; i++ {
			leftMax = max(leftMax, v[i].fim)
			if leftMax >= rightMin {
				fim = true
				break
			}
		}

		if fim {
			writer.WriteString("-1\n")
			continue
		}

		for i := 0; i < n-1; i++ {
			writer.WriteString("1 ")
		}
		writer.WriteString("2\n")
	}

}

package main

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

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

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

func init() {
	// const maxCapacity = SIZE
	// buf := make([]byte, maxCapacity)
	// scanner.Buffer(buf, maxCapacity)
	scanner.Split(bufio.ScanWords)
}

type ii struct {
	ini, fim int
}

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 main() {
	defer writer.Flush()

	t := ReadInt()

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

		n := ReadInt()

		v := make([]ii, n)

		for i := 0; i < n; i++ {
			v[i] = ii{ReadInt(), ReadInt()}
		}

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

		leftMax := v[0].fim
		rightMin := v[len(v)-1].ini

		fim := false

		if leftMax >= rightMin {
			fim = true
		}

		for i := 1; i < n-1; i++ {
			leftMax = max(leftMax, v[i].fim)
			if leftMax >= rightMin {
				fim = true
				break
			}
		}

		if fim {

			fim = false

			leftMax = v[len(v)-1].ini
			rightMin := v[0].fim

			if rightMin >= leftMax {
				fim = true
			}

			for i := n-2; i > 0; i-- {
				leftMax = min(leftMax, v[i].ini)
				if rightMin >= leftMax {
					fim = true
					break
				}
			}

			if fim {
				writer.WriteString("-1\n")
			} else {
				writer.WriteString("1")
				for i := 0; i < n-1; i++ {
					writer.WriteString(" 2")
				}
				writer.WriteString("\n")
			}

		} else {
			for i := 0; i < n-1; i++ {
				writer.WriteString("1 ")
			}
			writer.WriteString("2\n")
		}
	}

}

package main

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

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

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

func init() {
	// const maxCapacity = SIZE
	// buf := make([]byte, maxCapacity)
	// scanner.Buffer(buf, maxCapacity)
	scanner.Split(bufio.ScanWords)
}

type ii struct {
	ini, fim int
}

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

func main() {
	defer writer.Flush()

	t := ReadInt()

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

		n := ReadInt()

		v := make([]ii, n)

		for i := 0; i < n; i++ {
			v[i] = ii{ReadInt(), ReadInt()}
		}

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

		leftMax := v[0].fim
		rightMin := v[len(v)-1].ini

		fim := false

		for i := 1; i < n-1; i++ {
			leftMax = max(leftMax, v[i].fim)
			if leftMax >= rightMin {
				writer.WriteString("-1\n")
				fim = true
				break
			}
		}

		if fim {
			continue
		}

		for i := 0; i < n-1; i++ {
			writer.WriteString("1 ")
		}
		writer.WriteString("2\n")
	}

}

package main

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

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

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

func init() {
	// const maxCapacity = SIZE
	// buf := make([]byte, maxCapacity)
	// scanner.Buffer(buf, maxCapacity)
	scanner.Split(bufio.ScanWords)
}

type ii struct {
	ini, fim int
}

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 main() {
	defer writer.Flush()

	t := ReadInt()

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

		n := ReadInt()

		v := make([]ii, n)

		for i := 0; i < n; i++ {
			v[i] = ii{ReadInt(), ReadInt()}
		}

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

		resp := make([]int, n)

		fim := v[0].fim
		resp[0] = 1

		comeca := -1

		for i := 1; i < n; i++ {
			if fim >= v[i].ini {
				fim = max(fim, v[i].fim)
				resp[i] = 1
			} else {
				comeca = i
				break
			}
		}

		if comeca != -1 {
			for _, elem := range resp {
				if elem == 0 {
					writer.WriteString("2 ")
				} else {
					writer.WriteString("1 ")
				}
			}
			writer.WriteString("\n")
			continue
		}

		ini := v[len(v) - 1].ini
		resp = make([]int, n)
		resp[len(v)-1] = 2

		comeca = -1

		for i := len(v)-2; i >= 0; i-- {
			if ini > v[i].fim {
				comeca = i
				break
			} else {
				ini = v[i].ini
				resp[i] = 2
			}
		}

		if comeca != -1 {
			for _, elem := range resp {
				if elem == 0 {
					writer.WriteString("1 ")
				} else {
					writer.WriteString("2 ")
				}
			}
			writer.WriteString("\n")
			continue
		}

		writer.WriteString("-1\n")
	}

}


Let's call two numbers similar if their binary representations contain the same number of digits equal to $$$1$$$. For example:  $$$2$$$ and $$$4$$$ are similar (binary representations are $$$10$$$ and $$$100$$$);  $$$1337$$$ and $$$4213$$$ are similar (binary representations are $$$10100111001$$$ and $$$1000001110101$$$);  $$$3$$$ and $$$2$$$ are not similar (binary representations are $$$11$$$ and $$$10$$$);  $$$42$$$ and $$$13$$$ are similar (binary representations are $$$101010$$$ and $$$1101$$$). You are given an array of $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$. You may choose a non-negative integer $$$x$$$, and then get another array of $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$, where $$$b_i = a_i \oplus x$$$ ($$$\oplus$$$ denotes bitwise XOR).Is it possible to obtain an array $$$b$$$ where all numbers are similar to each other?

If it is impossible to choose $$$x$$$ so that all elements in the resulting array are similar to each other, print one integer $$$-1$$$. Otherwise, print any non-negative integer not exceeding $$$2^{30} - 1$$$ that can be used as $$$x$$$ so that all elements in the resulting array are similar.

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"os"
)

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

	var n int
	Fscan(in, &n)
	op := [30][100]int8{}
	baseOnes := [100]int8{}
	for j := 0; j < n; j++ {
		var v uint
		Fscan(in, &v)
		for i := range op {
			if v>>uint(i)&1 == 0 {
				op[i][j] = 1
			} else {
				op[i][j] = -1
			}
		}
		baseOnes[j] = int8(bits.OnesCount(v))
	}

	const sz = 15
	for ones := int8(0); ones <= 30; ones++ {
		mp := map[[100]int8]uint{}
		for i := uint(0); i < 1<<sz; i++ {
			sum := [100]int8{}
			for j := uint(0); j < sz; j++ {
				if i>>j&1 == 1 {
					for k, v := range op[j] {
						sum[k] += v
					}
				}
			}
			mp[sum] = i
		}
		curOnes := [100]int8{}
		for i := 0; i < n; i++ {
			curOnes[i] = ones - baseOnes[i]
		}
		for i := uint(0); i < 1<<sz; i++ {
			curOnesCopy := [100]int8{}
			for j, v := range curOnes {
				curOnesCopy[j] = v
			}
			for j := uint(0); j < sz; j++ {
				if i>>j&1 == 1 {
					for k, v := range op[j+sz] {
						curOnesCopy[k] -= v
					}
				}
			}
			if v, ok := mp[curOnesCopy]; ok {
				Fprint(out, i<<15|v)
				return
			}
		}
	}
	Fprint(out, -1)
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"os"
)

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

	var n int
	Fscan(in, &n)
	op := [30][100]int8{}
	baseOnes := [100]int8{}
	for j := 0; j < n; j++ {
		var v uint
		Fscan(in, &v)
		for i := range op {
			if v>>uint(i)&1 == 0 {
				op[i][j] = 1
			} else {
				op[i][j] = -1
			}
		}
		baseOnes[j] = int8(bits.OnesCount(v))
	}

	for ones := int8(0); ones <= 30; ones++ {
		mp := map[[100]int8]uint{}
		for i := uint(0); i < 1<<15; i++ {
			sum := [100]int8{}
			for j := uint(0); j < 15; j++ {
				if i>>j&1 == 1 {
					for k, v := range op[j] {
						sum[k] += v
					}
				}
			}
			mp[sum] = i
		}
		curOnes := [100]int8{}
		for i := 0; i < n; i++ {
			curOnes[i] = ones - baseOnes[i]
		}
		for i := uint(0); i < 1<<15; i++ {
			curOnesCopy := [100]int8{}
			for j, v := range curOnes {
				curOnesCopy[j] = v
			}
			for j := uint(0); j < 15; j++ {
				if i>>j&1 == 1 {
					for k, v := range op[j+15] {
						curOnesCopy[k] -= v
					}
				}
			}
			if v, ok := mp[curOnesCopy]; ok {
				Fprint(out, i<<15|v)
				return
			}
		}
	}
	Fprint(out, -1)
}

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