Mihai has just learned about the MEX concept and since he liked it so much, he decided to use it right away.Given an array $$$a$$$ of $$$n$$$ non-negative integers, Mihai wants to create a new array $$$b$$$ that is formed in the following way:While $$$a$$$ is not empty:   Choose an integer $$$k$$$ ($$$1 \leq k \leq |a|$$$).  Append the MEX of the first $$$k$$$ numbers of the array $$$a$$$ to the end of array $$$b$$$ and erase them from the array $$$a$$$, shifting the positions of the remaining numbers in $$$a$$$. But, since Mihai loves big arrays as much as the MEX concept, he wants the new array $$$b$$$ to be the lexicographically maximum. So, Mihai asks you to tell him what the maximum array $$$b$$$ that can be created by constructing the array optimally is.An array $$$x$$$ is lexicographically greater than an array $$$y$$$ if in the first position where $$$x$$$ and $$$y$$$ differ $$$x_i > y_i$$$ or if $$$|x| > |y|$$$ and $$$y$$$ is a prefix of $$$x$$$ (where $$$|x|$$$ denotes the size of the array $$$x$$$).The MEX of a set of non-negative integers is the minimal non-negative integer such that it is not in the set. For example, MEX({$$${1, 2, 3}$$$}) $$$= 0$$$ and MEX({$$${0, 1, 2, 4, 5}$$$}) $$$= 3$$$.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the number of elements in the array $$$a$$$. The second line of each test case contains $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \leq a_i \leq n$$$), where $$$a_i$$$ is the $$$i$$$-th integer from the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case print $$$m$$$ — the length of the maximum array $$$b$$$ Mihai can create, followed by $$$m$$$ integers denoting the elements of the array $$$b$$$.

NoteIn the first test case, the lexicographically maximum array $$$b$$$ is obtained by selecting $$$k=5$$$, resulting in the $$$MEX$$$ of the whole array $$$a$$$. It is lexicographically maximum because an array starting with a smaller number than $$$4$$$ is lexicographically smaller, and choosing a $$$k<5$$$ would result in an array starting with a number smaller than $$$4$$$.In the second test case, there are two ways to obtain the maximum array: first selecting $$$k=6$$$, then $$$k=2$$$, or first selecting $$$k=7$$$ and then $$$k=1$$$.

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	t := readInt(input)

	builder := strings.Builder{}
	for i := 0; i < t; i++ {
		builder.WriteString(solve(input))
	}
	fmt.Println(builder.String())
}

func getMex(arr []int, start int) int {
	for i := start; i < len(arr); i++ {
		if arr[i] == 0 {
			return i
		}
	}
	return start
}

func solve(input *bufio.Reader) string {
	n := readInt(input)
	arr := readArrInt(input)

	b := make([]int, 2 * n)
	cnt := make([]int, 2 * n)
	ans := make([]int, 2 * n)
	for i := 0; i < n; i++ {
		cnt[arr[i]]++
	}
	ansLen := 0

	nowMex := getMex(cnt, 0)
	pre := 0
	temp := 0

	for i := 0; i < n; i++ {
		b[arr[i]]++
		temp = getMex(b, temp)

		if nowMex == temp {
			ans[ansLen] = nowMex
			ansLen++
			for j := pre; j <= i; j++ {
				cnt[arr[j]]--
				b[arr[j]]--
			}
			pre = i + 1
			nowMex = getMex(cnt, 0)
			temp = 0
		}
	}

	builder := strings.Builder{}
	builder.WriteString(strconv.Itoa(ansLen) + "\n")
	for i := 0; i < ansLen; i++ {
		builder.WriteString(strconv.Itoa(ans[i]) + " ")
	}
	builder.WriteString("\n")
	return builder.String()
}

func readInt(in *bufio.Reader) int {
nStr, _ := in.ReadString('\n')
nStr = strings.ReplaceAll(nStr, "\r", "")
nStr = strings.ReplaceAll(nStr, "\n", "")
n, _ := strconv.Atoi(nStr)
return n
}

func readLineNumbs(in *bufio.Reader) []string {
line, _ := in.ReadString('\n')
line = strings.ReplaceAll(line, "\r", "")
line = strings.ReplaceAll(line, "\n", "")
numbs := strings.Split(line, " ")
return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

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 main() {
	defer out.Flush()
	var T int;
	scan(&T);
	for t := 0; t < T; t++ {
		var n int;
		scan(&n);
		a := make([]int, n);
		mex := make([]int, n);
		ans := []int{};
		m := map[int]int{};
		mx := 0;
		for i := 0; i < n; i++ {
			scan(&a[i]);
		}
		for i := n - 1; i >= 0; i-- {
			m[a[i]] = 1;
			for m[mx] == 1{
				mx++;
			}
			mex[i] = mx;
		}
		ind := 0;
		mx = 0;

		for k := range m {
			delete(m, k)
		}

		for i := 0; i < n; i++ {
			m[a[i]] = 1;
			for m[mx] == 1{
				mx++;
			}
			if mx == mex[ind] {
				ind = i + 1;
				ans = append(ans, mx);
				mx = 0;
				for k := range m {
					delete(m, k)
				}
			}
		}
		printf("%d \n", len(ans));
		for _, val := range ans {
			printf("%d ", val);
		}
		printf("\n");
	}

}

package main

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

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

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

	a := make([]int, n)

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

	mexSuffix := make([]int, n)
	{
		mexSet := make(map[int]bool)
		mexVal := 0

		for i := n - 1; i >= 0; i-- {
			mexSet[a[i]] = true
			for mexSet[mexVal] {
				mexVal++
			}

			mexSuffix[i] = mexVal
		}
	}

	b := make([]int, 0)

	for p := 0; p < n; p++ {
		mexPN := mexSuffix[p]

		mexSet := make(map[int]bool)
		mexPJ := 0

		for j := p; j < n; j++ {
			mexSet[a[j]] = true
			for mexSet[mexPJ] {
				mexPJ++
			}

			if mexPJ == mexPN {
				b = append(b, mexPJ)
				p = j
				break
			}
		}
	}

	fmt.Fprintln(writer, len(b))
	for _, num := range b {
		fmt.Fprintf(writer, "%d ", num)
	}
	fmt.Fprintln(writer)
}

//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 abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnusedFunction
func findSet(parent []int, v int) int {
	if v == parent[v] {
		return v
	}

	parent[v] = findSet(parent, parent[v])

	return parent[v]
}

//goland:noinspection GoUnusedFunction
func unionSets(parent []int, v, u int) {
	v = findSet(parent, v)
	u = findSet(parent, u)

	if v != u {
		parent[v] = u
	}
}

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 calcMex(flag []bool, val int, mex int) int {
	flag[val] = true
	for flag[mex] {
		mex++
	}
	return mex
}

func solveCase() []int {
	var n int
	scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		scan(&a[i])
	}
	flag := make([]bool, n+2)
	suffixMex := make([]int, n+1)

	for i := n - 1; i >= 0; i-- {
		suffixMex[i] = calcMex(flag, a[i], suffixMex[i+1])
	}

	var ans []int
	for i := 0; i < n; {
		mexi := suffixMex[i]
		ans = append(ans, mexi)
		if mexi == 0 {
			i++
			continue
		}
		for j := 0; j <= mexi; j++ {
			flag[j] = false
		}
		j := i
		mex := 0
		for mex < mexi {
			mex = calcMex(flag, a[j], mex)
			j++
		}
		i = j
	}
	return ans
}

func main() {
	defer out.Flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		ans := solveCase()
		printf("%d\n", len(ans))
		for _, x := range ans {
			printf("%d ", x)
		}
		printf("\n")
	}
}

package main

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

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

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

func scan(a ...interface{})    { fmt.Fscan(reader, a...) }
func print(a ...interface{})   { fmt.Fprint(writer, a...) }
func println(a ...interface{}) { fmt.Fprintln(writer, a...) }

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

var arr []int
var cnt []int
var tmp []int

func main() {
	defer writer.Flush()
	arr = make([]int, 2*100002)
	cnt = make([]int, 2*100002)
	tmp = make([]int, 2*100002)
	var t, n int
	scan(&t)
	for ti := 0; ti < t; ti++ {
		scan(&n)
		for i := 0; i < n; i++ {
			scan(&arr[i])
			cnt[i] = 0
		}
		cnt[n] = 0
		cnt[n+1] = 0
		mex := 0
		for i := 0; i < n; i++ {
			cnt[arr[i]]++
			for j := mex; cnt[j] > 0; j++ {
				mex++
			}
		}
		res := make([]int, 0)
		for i := 0; i < n; {
			res = append(res, mex)
			currMex := -1
			newMex := mex
			r := i
			for currMex != mex && r < n {
				tmp[arr[r]]++
				if currMex == -1{
					currMex++
				}
				for j := currMex; tmp[j] > 0; j++ {
					currMex++
				}
				r++
			}
			for ; i < r && i < n; i++ {
				cnt[arr[i]]--
				tmp[arr[i]]--
				if cnt[arr[i]] == 0 && arr[i] < newMex {
					newMex = arr[i]
				}
			}
/*			cnt[mex]++
			for j := newMex; cnt[j] > 0; j++ {
				newMex++
			}*/
			mex = newMex
		}
		l := len(res)
		println(l)
		for i := 0; i < l; i++ {
			print(res[i], " ")
		}
		println()
	}
}

package main

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

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

var T, N int
var A []int
var C []int
var B []int

func solve() []int {
	res := make([]int, 0, N)
	tar := 0
	bgn := 0
	for i := 0; i <= N; i++ {
		if C[i] == 0 {
			tar = i
			break
		}
	}

	for bgn < N {
		res = append(res, tar)
		for i := 0; i < tar; i++ {
			B[i] = 1
		}
		cnt := tar
		tar1 := tar
		for i := bgn; i < N; i++ {
			a := A[i]
			C[a]--
			if C[a] == 0 {
				tar1 = min(tar1, a)
			}
			if a < tar && B[a] == 1 {
				B[a] = 0
				cnt--
			}
			if cnt == 0 {
				bgn = i + 1
				tar = tar1
				break
			}
		}
	}

	return res
}

func main(){
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &T)
	for ; T > 0; T-- {
		fmt.Fscan(in, &N)
		A = make([]int, N)
		C = make([]int, N + 2)
		B = make([]int, N + 2)
		for i := 0; i < N; i++ {
			fmt.Fscan(in, &A[i])
			C[A[i]]++
		}

		res := solve()
		fmt.Println(len(res))
		for i := 0; i < len(res); i++ {
			fmt.Print(res[i]," ")
		}
		fmt.Print("\n")
	}
}

package main

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

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

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		r := make([]int, n+1)
		for i := range r {
			r[i] = -1
		}
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
			r[a[i]] = i
		}
		ans := []int{}
		vis := make([]int, n+2)
		i := 0
		for k := 1; i <= r[0]; k++ {
			mex := 0
			for ; i <= r[mex]; i++ {
				vis[a[i]] = k
				for vis[mex] == k {
					mex++
				}
			}
			ans = append(ans, mex)
		}
		Fprintln(out, len(ans)+n-i)
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out, strings.Repeat("0 ", n-i))
	}
}

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

package main

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

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

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		pos := make([][]int, n+1)
		for i := range a {
			Fscan(in, &a[i])
			pos[a[i]] = append(pos[a[i]], i)
		}
		ans := []int{}
		i := 0
		for pos[0] != nil && i <= pos[0][len(pos[0])-1] {
			vis := map[int]bool{} // 改成数组
			mex := 0
			for ; pos[mex] != nil && i <= pos[mex][len(pos[mex])-1]; i++ {
				vis[a[i]] = true
				for vis[mex] {
					mex++
				}
			}
			ans = append(ans, mex)
		}
		for ; i < n; i++ {
			ans = append(ans, 0)
		}
		Fprintln(out, len(ans))
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

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

func solve(arr []int) []int {
	ans := []int{}
	n := len(arr)
	mex := make([]int, n)
	vis := make([]bool, n+1)
	var k int
	for i := n - 1; i >= 0; i-- {
		v := arr[i]
		vis[v] = true
		for ; k <= n && vis[k]; k++ {
		}
		mex[i] = k
	}

	var j int
	for i := 0; i < n; i = j + 1 {
		vis = make([]bool, n+1)
		k = 0
		for j = i; j < n; j++ {
			v := arr[j]
			vis[v] = true
			for ; k <= n && vis[k]; k++ {
			}
			if k == mex[i] {
				break
			}
		}
		ans = append(ans, k)
	}
	return ans
}
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t int
	var n int
	arr := make([]int, 2e5+10)
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		for i := 0; i < n; i++ {
			Fscan(in, &arr[i])
		}
		ans := solve(arr[:n])
		Fprintln(out, len(ans))
		for _, v := range ans {
			Fprintf(out, "%d ", v)
		}
		Fprintln(out)
	}
}

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

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	Fscan(in, &n)
	arr := make([]int, n)
	cnt := make([]int, n+1)
	for i := 0; i < n; i++ {
		Fscan(in, &arr[i])
		cnt[arr[i]]++
	}
	i := 0
	var ans []int
	for i < n {
		mex := 0
		for cnt[mex] != 0 {
			mex++
		}
		cc := 0
		vis := make([]bool, mex)
		for i < n {
			if arr[i] < mex && !vis[arr[i]] {
				cc++
				vis[arr[i]] = true
			}
			cnt[arr[i]]--
			i++
			if cc == mex {
				break
			}
		}
		ans = append(ans, mex)
	}
	Fprintln(out, len(ans))
	for _, v := range ans {
		Fprintf(out, "%d ", v)
	}
	Fprintln(out)
}

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	n := 0
	Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

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

func main() {
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	input := bufio.NewReader(os.Stdin)
	t := readInt(input)

	builder := strings.Builder{}
	for i := 0; i < t; i++ {
		builder.WriteString(solve(input))
	}
	fmt.Println(builder.String())
}

func getMex(arr []int, start int) int {
	for i := start; i < len(arr); i++ {
		if arr[i] == 0 {
			return i
		}
	}
	return start
}

func solve(input *bufio.Reader) string {
	n := readInt(input)
	arr := readArrInt(input)

	b := make([]int, 2 * n)
	cnt := make([]int, 2 * n)
	ans := make([]int, 2 * n)
	for i := 0; i < n; i++ {
		cnt[arr[i]]++
	}
	ansLen := 0

	nowMex := getMex(cnt, 0)
	pre := 0
	temp := 0

	for i := 0; i < n; i++ {
		b[arr[i]]++
		temp = getMex(b, temp)

		if nowMex == temp {
			ans[ansLen] = nowMex
			ansLen++
			for j := pre; j <= i; j++ {
				cnt[arr[j]]--
				b[arr[j]]--
			}
			pre = i + 1
			nowMex = getMex(cnt, 0)
			temp = 0
		}
	}

	builder := strings.Builder{}
	builder.WriteString(strconv.Itoa(ansLen) + "\n")
	for i := 0; i < ansLen; i++ {
		builder.WriteString(strconv.Itoa(ans[i]) + " ")
		fmt.Printf("%d ", ans[i])
	}
	builder.WriteString("\n")
	return builder.String()
}

func readInt(in *bufio.Reader) int {
nStr, _ := in.ReadString('\n')
nStr = strings.ReplaceAll(nStr, "\r", "")
nStr = strings.ReplaceAll(nStr, "\n", "")
n, _ := strconv.Atoi(nStr)
return n
}

func readLineNumbs(in *bufio.Reader) []string {
line, _ := in.ReadString('\n')
line = strings.ReplaceAll(line, "\r", "")
line = strings.ReplaceAll(line, "\n", "")
numbs := strings.Split(line, " ")
return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	t := readInt(input)

	for i := 0; i < t; i++ {
		n := readInt(input)
		arr := readArrInt(input)
		if n == 1 {
			printArr([]int{mex(arr)})
			continue
		}
		res := []int{}
		arrMex := mex(arr)
		for i := 0; i < len(arr); i++ {
			if mex(arr[:i]) == arrMex {
				res = append(res, arrMex)
				arr = arr[i:]
				arrMex = mex(arr)
				i = 0
			}
		}
		res = append(res, arrMex)
		printArr(res)
	}
}

func printArr(arr []int) {
	out := bufio.NewWriter(os.Stdout)
	out.WriteString(strconv.Itoa(len(arr)) + "\n")
	for _, num := range arr {
		out.WriteString(strconv.Itoa(num) + " ")
	}
	out.WriteString("\n")
}

func mex(arr []int) int {
	mp := map[int]struct{}{}
	for i := 0; i < len(arr); i++ {
		mp[arr[i]] = struct{}{}
	}
	for i := 0; i < len(arr); i++ {
		if _, ok := mp[i]; !ok {
			return i
		}
	}
	return len(arr)
}

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	t := readInt(input)

	for i := 0; i < t; i++ {
		n := readInt(input)
		arr := readArrInt(input)
		if n == 1 {
			printArr(arr)
			continue
		}
		res := []int{}
		arrMex := mex(arr)
		for i := 0; i < len(arr); i++ {
			if mex(arr[:i]) == arrMex {
				res = append(res, arrMex)
				arr = arr[i:]
				arrMex = mex(arr)
				i = 0
			}
		}
		res = append(res, arrMex)
		printArr(res)
	}
}

func printArr(arr []int) {
	fmt.Println(len(arr))
	for _, num := range arr {
		fmt.Printf("%d ", num)
	}
	fmt.Println()
}

func mex(arr []int) int {
	mp := map[int]struct{}{}
	for i := 0; i < len(arr); i++ {
		mp[arr[i]] = struct{}{}
	}
	for i := 0; i < len(arr); i++ {
		if _, ok := mp[i]; !ok {
			return i
		}
	}
	return len(arr)
}

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

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 main() {
	defer out.Flush()
	var T int;
	scan(&T);
	for t := 0; t < T; t++ {
		var n int;
		scan(&n);
		a := make([]int, n);
		mex := make([]int, n);
		ans := []int{};
		m := map[int]int{};
		mx := 0;
		for i := 0; i < n; i++ {
			scan(&a[i]);
		}
		for i := n - 1; i >= 0; i-- {
			m[a[i]] = 1;
			for m[mx] == 1{
				mx++;
			}
			mex[i] = mx;
		}
		ind := 0;
		mx = 0;

		for k := range m {
			delete(m, k)
		}

		for i := 0; i < n; i++ {
			m[a[i]] = 1;
			for m[mx] == 1{
				mx++;
			}
			if mx == mex[ind] {
				ind = i + 1;
				ans = append(ans, mx);
			}
		}
		printf("%d \n", len(ans));
		for _, val := range ans {
			printf("%d ", val);
		}
		printf("\n");
	}

}

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 calcMex(flag []bool, val int, mex int) int {
	flag[val] = true
	for flag[mex] {
		mex++
	}
	return mex
}

func solveCase() []int {
	var n int
	scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		scan(&a[i])
	}
	flag := make([]bool, n+2)
	suffixMex := make([]int, n+1)

	for i := n - 1; i >= 0; i-- {
		suffixMex[i] = calcMex(flag, a[i], suffixMex[i+1])
	}

	var ans []int
	for i := 0; i < n; {
		mexi := suffixMex[i]
		if mexi == 0 {
			ans = append(ans, 0)
			break
		}
		for j := 0; j <= mexi; j++ {
			flag[j] = false
		}
		j := i
		mex := 0
		for mex < mexi {
			mex = calcMex(flag, a[j], mex)
			j++
		}
		ans = append(ans, mexi)
		i = j
	}
	return ans
}

func main() {
	defer out.Flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		ans := solveCase()
		printf("%d\n", len(ans))
		for _, x := range ans {
			printf("%d ", x)
		}
		printf("\n")
	}
}


You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.A substring s[l...r] (1 ≤ l ≤ r ≤ |s|) of string s  =  s1s2...s|s| (where |s| is the length of string s) is string  slsl + 1...sr.The substring s[l...r] is good, if among the letters  sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] ≠ s[p...q].

The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters. The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on. The third line of the input consists a single integer k (0 ≤ k ≤ |s|) — the maximum acceptable number of bad characters in a good substring.

Print a single integer — the number of distinct good substrings of string s.

NoteIn the first example there are following good substrings: "a", "ab", "b", "ba", "bab".In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".

package main

// http://codeforces.com/problemset/problem/271/D

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

const mx = 1500

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

	mtable [mx]uint64

	pri = uint64(1004271249911446763)
)

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

func Dprint(format string, a ...interface{}) {
	if Debug {
		fmt.Fprintf(os.Stderr, format+"\n", a...)
	}
}

func main() {
	defer writer.Flush()

	// Initialize mtable.
	mtable[0] = 1
	for i := 1; i < 1500; i++ {
		mtable[i] = (mtable[i-1] * 31) % pri
	}

	var s, goodS string
	var k int
	Scanf("%s\n%s\n%d", &s, &goodS, &k)
	Dprint("s=%s,good=%s,k=%d", s, goodS, k)

	// Good says whether an entry is good.
	good := make([]bool, len(goodS))
	for i := 0; i < len(goodS); i++ {
		good[i] = goodS[i] == '1'
	}

	var hashes []uint64

	for start := 0; start < len(s); start++ {
		var hash uint64
		var bads int
		for end := start; end < len(s); end++ {
			si := uint64(s[end] - 'a')
			if !good[si] {
				bads++
			}
			// Dprint("%v, %d, bads=%v,k=%v", good, si, bads, k)
			if bads > k {
				// Too many bad characters.
				break
			}
			hash += ((si + 1) * mtable[end-start]) % pri
			hashes = append(hashes, hash)
			//Dprint("%s=%d", s[start:end+1], hash)
		}
	}

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

	unique := 1
	for i := 1; i < len(hashes); i++ {
		if hashes[i] != hashes[i-1] {
			unique++
		}
	}

	if len(hashes) == 0 {
		unique = 0
	}
	//Dprint("%v", hashes)
	Printf("%d\n", unique)
}

package main

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

var goodChars string
var k, result int

func main() {
	// file, _ := os.Open("input")
	file := os.Stdin
	reader := bufio.NewReader(file)
	var s string
	fmt.Fscanf(reader, "%s\n%s\n%d", &s, &goodChars, &k)

	trie := &trie{}
	n := len(s)
	for i := 0; i < n; i++ {
		subString := s[i:n]
		trie.insert(subString, 0, 0)
	}

	fmt.Println(result)
	return
}

type trie struct {
	chars [26]*trie
}

func (e *trie) insert(s string, i, v int) {
	if i == len(s) {
		return
	}

	pos := s[i] - 'a'
	if goodChars[pos] != '1' {
		v++
	}

	if e.chars[pos] == nil {
		newNode := &trie{}
		e.chars[pos] = newNode

		if v <= k {
			result++
		}
	}

	e.chars[pos].insert(s, i+1, v)
}

package main

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

var goodChars string
var k int

func main() {
	// file, _ := os.Open("input")
	file := os.Stdin
	reader := bufio.NewReader(file)
	var s string
	fmt.Fscanf(reader, "%s\n%s\n%d", &s, &goodChars, &k)

	trie := &trie{}
	n := len(s)
	for i := 0; i < n; i++ {
		subString := s[i:n]
		trie.insert(subString, 0, 0)
	}

	fmt.Println(trie.count() - 1)
	return
}

type trie struct {
	value int
	ok    bool
	chars [26]*trie
}

func (e *trie) insert(s string, i, v int) {
	if i == len(s) {
		return
	}

	pos := s[i] - 'a'
	if goodChars[pos] != '1' {
		v++
	}

	if e.chars[pos] == nil {
		newNode := &trie{}
		e.chars[pos] = newNode
	}

	e.chars[pos].value = v
	e.chars[pos].insert(s, i+1, v)
}

func (e *trie) count() int {
	if e == nil {
		return 0
	}

	count := 0
	for _, c := range e.chars {
		count += c.count()
	}

	if e.value <= k {
		count++
	}

	return count
}

package main

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

var (
	base   = uint64(311)
	hash   = []uint64{}
	hashes = map[uint64]bool{}
)

func solve(s string, k int, n int, value string) int {
	count, hash := 0, uint64(0)
	var id byte

	for i := range s {
		count = 0
		hash = 0
		for j := i; j < n; j++ {
			id = s[j] - 'a'
			if value[id] == '0' {
				count++
				if count > k {
					break
				}
			}
			hash = hash*base + uint64(s[j])
			hashes[hash] = true
		}
	}

	return len(hashes)
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var str, value string
	var k int

	fmt.Fscanf(r, "%s\n", &str)
	fmt.Fscanf(r, "%s\n", &value)
	fmt.Fscanf(r, "%d\n", &k)
	hash = make([]uint64, len(str))

	fmt.Fprintf(os.Stdout, "%d\n", solve(str, k, len(str), value))
}

package main

// http://codeforces.com/problemset/problem/271/D

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

const mx = 1500

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

	mtable [mx]uint64

	pri = uint64(1004271249911446763)
)

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

func Dprint(format string, a ...interface{}) {
	if Debug {
		fmt.Fprintf(os.Stderr, format+"\n", a...)
	}
}

func main() {
	defer writer.Flush()

	// Initialize mtable.
	mtable[0] = 1
	for i := 1; i < 1500; i++ {
		mtable[i] = (mtable[i-1] * 31) % pri
	}

	var s, goodS string
	var k int
	Scanf("%s\n%s\n%d", &s, &goodS, &k)
	Dprint("s=%s,good=%s,k=%d", s, goodS, k)

	// Good says whether an entry is good.
	good := make([]bool, len(goodS))
	for i := 0; i < len(goodS); i++ {
		good[i] = goodS[i] == '1'
	}

	var hashes []uint64

	for start := 0; start < len(s); start++ {
		var hash uint64
		var bads int
		for end := start; end < len(s); end++ {
			si := uint64(s[end] - 'a')
			if !good[si] {
				bads++
			}
			if bads > k {
				// Too many bad characters.
				break
			}
			hash += ((si + 1) * mtable[end-start]) % pri
			hashes = append(hashes, hash)
			//Dprint("%s=%d", s[start:end+1], hash)
		}
	}

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

	unique := 1
	for i := 1; i < len(hashes); i++ {
		if hashes[i] != hashes[i-1] {
			unique++
		}
	}
	//Dprint("%v", hashes)
	Printf("%d\n", unique)
}

package main

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

var (
	base   = uint64(127)
	hash   = []uint64{}
	hashes = map[uint64]bool{}
)

func solve(s string, k int, n int, value string) int {
	count, hash := 0, uint64(0)
	var id byte

	for i := range s {
		count = 0
		hash = 0
		for j := i; j < n; j++ {
			id = s[j] - 'a'
			if value[id] == '0' {
				count++
			}
			if count <= k {
				hash = hash*base + uint64(s[j])
				hashes[hash] = true
			} else {
				break
			}
		}
	}

	return len(hashes)
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var str, value string
	var k int

	fmt.Fscanf(r, "%s\n", &str)
	fmt.Fscanf(r, "%s\n", &value)
	fmt.Fscanf(r, "%d\n", &k)
	hash = make([]uint64, len(str))

	fmt.Fprintf(os.Stdout, "%d\n", solve(str, k, len(str), value))
}

package main

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

var (
	base   = uint64(127)
	mod    = uint64(1e9 + 7)
	hash   = []uint64{}
	hashes = map[uint64]bool{}
)

func solve(s string, k int, n int, value string) int {
	count, hash := 0, uint64(0)
	var id byte

	for i := range s {
		count = 0
		hash = 0
		for j := i; j < n; j++ {
			id = s[j] - 'a'
			if value[id] == '0' {
				count++
				if count > k {
					break
				}
			}
			hash = (hash*base + uint64(s[j])) % mod
			hashes[hash] = true
		}
	}

	return len(hashes)
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var str, value string
	var k int

	fmt.Fscanf(r, "%s\n", &str)
	fmt.Fscanf(r, "%s\n", &value)
	fmt.Fscanf(r, "%d\n", &k)
	hash = make([]uint64, len(str))

	fmt.Fprintf(os.Stdout, "%d\n", solve(str, k, len(str), value))
}

package main

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

var (
	base   = uint64(27)
	hash   = []uint64{}
	hashes = map[uint64]bool{}
)

func solve(s string, k int, n int, value string) int {
	count, hash := 0, uint64(0)
	var id byte

	for i := range s {
		count = 0
		hash = 0
		for j := i; j < n; j++ {
			id = s[j] - 'a'
			if value[id] == '0' {
				count++
			}
			if count <= k {
				hash = hash*base + uint64(s[j])
				hashes[hash] = true
			} else {
				break
			}
		}
	}

	return len(hashes)
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var str, value string
	var k int

	fmt.Fscanf(r, "%s\n", &str)
	fmt.Fscanf(r, "%s\n", &value)
	fmt.Fscanf(r, "%d\n", &k)
	hash = make([]uint64, len(str))

	fmt.Fprintf(os.Stdout, "%d\n", solve(str, k, len(str), value))
}


The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dn - 1 is the distance between the n - 1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t.

The first line contains integer n (3 ≤ n ≤ 100) — the number of stations on the circle line. The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 100) — the distances between pairs of neighboring stations. The third line contains two integers s and t (1 ≤ s, t ≤ n) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces.

Print a single number — the length of the shortest path between stations number s and t.

NoteIn the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13.In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15.In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.

package main

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

func main() {
    defer s.Flush()

	n := s.Next()
	a, sum := make([]int, n), 0
	for i := 0; i < n; i++ {
		a[i] = s.Next()
		sum += a[i]
	}

	x, y := s.Next() - 1, s.Next() - 1

	if x > y {
		x, y = y, x
	}

	d := 0
	for i := x; i < y; i++ {
		d += a[i]
	}

	if sum - d < d {
		s.Println(sum - d)
	} else {
		s.Println(d)
	}
}

var (
	s *InOut
)

func init() {
	s = NewInOut(os.Stdin, os.Stdout)
}

type InOut struct {
	*bufio.Reader
	*bufio.Writer
}

func NewInOut(r io.Reader, w io.Writer) *InOut {
	return &InOut{bufio.NewReader(r), bufio.NewWriter(w)}
}

// Get Next Integer
func (s *InOut) Next() (r int) {
	b, _ := s.ReadByte()
	p := 1
	for (b < '0' || '9' < b) && b != '-' {
		b, _ = s.ReadByte()
	}
	if b == '-' {
		p = -1
		b, _ = s.ReadByte()
	}
	for '0' <= b && b <= '9' {
		r = 10*r + int(b-'0')
		b, _ = s.ReadByte()
	}
	return r * p
}

func (s *InOut) NextInt64() (r int64) {
	b, _ := s.ReadByte()
	p := int64(1)
	for (b < '0' || '9' < b) && b != '-' {
		b, _ = s.ReadByte()
	}
	if b == '-' {
		p = -1
		b, _ = s.ReadByte()
	}
	for '0' <= b && b <= '9' {
		r = 10*r + int64(b-'0')
		b, _ = s.ReadByte()
	}
	return r * p
}

// Get Next Line String
func (s *InOut) NextLine() (r string) {
    b, _ := s.ReadByte()
    for b == '\r' || b == '\n' {
        b, _ = s.ReadByte()
    }
    buf := make([]byte, 0)
    for ; b != '\r' && b != '\n'; b, _ = s.ReadByte() {
        buf = append(buf, b)
    }
    return string(buf)
}

// Get Next String using delimiter whitespace
func (s *InOut) NextStr() (r string) {
    return string(s.NextBytes())
}

// Get Next String using delimiter whitespace
func (s *InOut) NextBytes() (r []byte) {
	b, _ := s.ReadByte()
	for b == '\n' || b == ' ' {
		b, _ = s.ReadByte()
	}
	buf := make([]byte, 0)
	for ; b != '\n' && b != ' '; b, _ = s.ReadByte() {
		buf = append(buf, b)
	}
	return buf
}

// Print Strings using the suitable way to change type
func (s *InOut) Print(os ...interface{}) {
	for _, o := range os {
		switch o.(type) {
		case byte:
			s.WriteByte(o.(byte))
		case string:
			s.WriteString(o.(string))
		case int:
			s.WriteString(strconv.Itoa(o.(int)))
		case int64:
			s.WriteString(strconv.FormatInt(o.(int64), 10))
		default:
			s.WriteString(fmt.Sprint(o))
		}
	}
}

// Print Strings using the suitable way to change type with new line
func (s *InOut) Println(os ...interface{}) {
	for _, o := range os {
		s.Print(o)
	}
	s.Print("\n")
}

// Print immediately with new line (for debug)
func (s *InOut) PrintlnNow(o interface{}) {
	fmt.Println(o)
}

package main
import (
	"fmt"
)
func main() {
	var n,d,s,t,j,x int
	fmt.Scan(&n)
	f := make([]int,102)

	for i:=2;i<(n+2);i++ {
		j=i-1
		fmt.Scan(&d)
		f[i] = f[j]+d
	}
	fmt.Scan(&s,&t)
	if s>t {
		x = s
		s = t
		t = x
	}
	hasil := f[t] - f[s]
	k:=n+1
	h:= f[k]-hasil
	if hasil>h {
		fmt.Println(h)
	} else {fmt.Println(hasil)}
}

package main

import ("fmt")

func calculate(arr []int , start , end ,t int) int{

	if start == end {
		return 0
	}

	var distance int
	for i:=start;i<end;i++{
		distance += arr[i]
	}

	var sec_distance int
	for i:=end;i<start+t;i++{
		sec_distance += arr[i]
	}
	 if distance > sec_distance{
	 	return sec_distance
	 }
	 return distance
}

func main(){
	var t int
	fmt.Scanln(&t)
	arr := make([]int,2*t)
	var temp int
	for i:=0;i<t-1;i++{
		fmt.Scan(&temp)
		arr[i] = temp
		arr[i+t] = temp
	}
	fmt.Scanln(&temp)
	arr[t-1] = temp
	arr[2*t-1] = temp
	var start int
	var end int
	fmt.Scan(&start)
	fmt.Scan(&end)

	if start > end{
		temp := end
		end = start
		start  = temp
	}

	fmt.Println(calculate(arr,start-1,end-1,t))
	//fmt.Println(count)
}

package main

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

func main() {
	var n int
	if _, err := fmt.Scanf("%d\n", &n); err != nil {
		return
	}

	total := 0
	dist := make([]int, n)
	st := make([]int, 2)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		if i < n {
			dist[i] = a
			total += a
		} else {
			st[i-n] = a
		}
	}

	if st[0] > st[1] {
		st[0], st[1] = st[1], st[0]
	}

	path := 0
	for i := st[0] - 1; i < st[1]-1; i++ {
		path += dist[i]
	}

	if total-path < path {
		fmt.Println(total - path)
	} else {
		fmt.Println(path)
	}
}

package main

import "fmt"

func main() {
    var n,s,t int
    var d [105]int
    fmt.Scan(&n)
    total := 0
    for i := 1; i <= n; i++ {
        fmt.Scan(&d[i])
        total += d[i]
    }
    fmt.Scan(&s,&t)
    if s > t { s, t = t, s }
    cnt := 0
    for i := s; i < t; i++ {
        cnt += d[i]
    }
    if cnt < (total-cnt) {
        fmt.Println(cnt)
    } else {
        fmt.Println(total-cnt)
    }
}

package main

import (
	"fmt"
)

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

	dn := make([]int, n, n)
	total := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&dn[i])
		total += dn[i]
	}

	var s, t int
	fmt.Scan(&s, &t)
	ans := 0
	if s > t {
		s, t = t, s
	}
	for i := s - 1; i < t-1; i++ {
		ans += dn[i]
	}

	if ans > total-ans {
		ans = total - ans
	}

	fmt.Println(ans)
}

/* Well... there's only two directions you can take between the stations s and t.
So we can just try going both ways and seeing which one is shorter. */
package main

import (
    "fmt"
    "math"
)

//going forward around the circle starting from s going to t, returns distance
func forward(s, t, station int, stations []int) int {
    sum := 0
    //define stopping point
    finalT := t
    if t < s {
        finalT = t + station
    }
    for i := s-1; i < finalT-1; i++ {
        sum += stations[int(math.Mod(float64(i), float64(station)))]
    }
    return sum
}

//going backward around the circle starting from s going to t, returns distance
func backward(s, t, station int, stations []int) int {
    sum := 0
    //define stopping point
    finalS := s
    if s < t {
        finalS = s + station
    }
    for i := t-1; i < finalS-1; i++ {
        sum += stations[int(math.Mod(float64(i), float64(station)))]
    }
    return sum
}

func main() {
    //read number of stations
    var station int
    fmt.Scan(&station)

    //distance between stations
    stations := make([]int, station)
    for i := 0; i < station; i++ {
        fmt.Scan(&stations[i])
    }

    //stations s and t
    var s, t int
    fmt.Scan(&s)
    fmt.Scan(&t)

    front   := forward(s, t, station, stations)
    back    := backward(s, t, station, stations)

    if front < back {
        fmt.Println(front)
    } else {
        fmt.Println(back)
    }
}


A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:  Is it true that y is strictly larger than number x?  Is it true that y is strictly smaller than number x?  Is it true that y is larger than or equal to number x?  Is it true that y is smaller than or equal to number x? On each question the host answers truthfully, "yes" or "no".Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".

The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:   ">" (for the first type queries),  "<" (for the second type queries),  ">=" (for the third type queries),  "<=" (for the fourth type queries).  All values of x are integer and meet the inequation  - 109 ≤ x ≤ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no"). Consequtive elements in lines are separated by a single space.

Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation  - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).

 package main
import (
	"fmt"
)
func max(a,b int) int {
	if a>b {
		return a
	} else {
		return b
	}
}

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

func main() {
	var x,y string
	var i,j,k,n int
	i=-2000000000
	j=2000000000
	fmt.Scan(&n)
	for d:=0;d<n;d++ {
	     	fmt.Scan(&x,&k,&y)
	     	if(y=="N"){
	         	if(x=="<") {
	         		i=max(i,k)
	         	}
	         	if(x==">") {
	         		j=min(j,k)
	         	}
	         	if(x=="<="){
	         		i=max(i,k+1)
	         	}
	         	if(x==">="){
	         		j=min(j,k-1)
	         	}
	     	} else {
	         	if(x==">="){
	         		i=max(i,k)
	         	}
	         	if(x=="<="){
	         		j=min(j,k)
	         	}
	         	if(x==">"){
	         		i=max(i,k+1)
	         	}
	         	if(x=="<"){
	         		j=min(j,k-1)
	         	}
	     	}
	}
	if(i>j) {
	 	fmt.Println("Impossible")
	}else {
	 	fmt.Println(i)
	}
}


Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	buffer, _ := reader.ReadBytes('}')
	set := make(map[byte]struct{})
	for i := 1; i < len(buffer)-1; i += 3 {
		set[buffer[i]] = struct{}{}
	}
	fmt.Println(len(set))
}

package main

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

func main() {
	var s string
	in := bufio.NewReader(os.Stdin)
	s, _ = in.ReadString('\n')
	//fmt.Fscanln(in, &s)
	//fmt.Println(s)
	ss := s[1:strings.Index(s, "}")]
	if len(ss) == 0 {
		fmt.Println(0)
	} else {
		split := strings.Split(ss, ",")
		distince := make(map[string]bool, 0)
		for _, v := range split {
			distince[strings.TrimSpace(v)] = true
		}
		ans := 0
		for _, _ = range distince {
			ans++
		}
		fmt.Println(ans)
	}
}

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

func main() {
	var(
		data string
		set = make(map[string]int)
	)
	reader := bufio.NewReader(os.Stdin)
	bytes, _, _ := reader.ReadLine()
	data = string(bytes)
	data = strings.Replace(data, "{", "", 1)
	data = strings.Replace(data, "}", "", 1)
	for _, letter := range strings.Split(data, ", "){
		if "" != letter {
			_, ok := set[letter]
			if !ok {
				set[letter] = 1
			}
		}
	}

	fmt.Println(len(set))
}

package main

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

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

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

	line := next()

	line = line[1:len(line) - 1]

	if len(line) == 0 {
		println(0)
		return
	}

	// chars := strings.Split(line, ", ")
	count := 0
	line = strings.Replace(line, ", ", "", -1)

	ch := make([]bool, 26)

	for i := range line {
		ch[line[i] - 'a'] = true
	}

	for i := range ch {
		if ch[i] {
			count++
		}
	}

	println(count)
}

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

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

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	set := scanner.Text()
	values := set[1 : len(set)-1]
	arrStr := strings.Split(values, ", ")

	if len(set) == 2 {
		fmt.Println(0)
		return
	}

	var length, i int64 = int64(len(arrStr)), 0
	temp := make(map[string]int64)
	for i = 0; i < length; i++ {
		_, ok := temp[arrStr[i]]

		if !ok {
			temp[arrStr[i]] = 1
		}
	}

	fmt.Println(len(temp))

}

package main

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

func main(){
    var (
        st string
        sc = bufio.NewScanner(os.Stdin)
        m =make(map[string]int)
        res = 0
        arr = []string{}
    )
    sc.Scan()
    st = sc.Text()
    st = st[1:len(st)-1]
    if st!=""{
        arr = strings.Split(st,",")
    }
    for i:=0;i<len(arr);i++{
        if len(arr[i])>1{
            arr[i]=arr[i][1:]
        }
        if _,ok:=m[arr[i]];ok==false{
            res++
            m[arr[i]]=1
        }
    }
    fmt.Println(res)
}

package main
import (
	"fmt"
	"unicode/utf8"
	"bufio"
	"os"
)
func main() {
	nn:=0
	var s string
	var u int
	input := bufio.NewScanner(os.Stdin)
	input.Scan()
	s = input.Text()
	len:= utf8.RuneCountInString(s)
	v :=make([]int,1005)
	fmt.Println()
	for i:=0;i<len;i++{
		if  (s[i]>='A' && s[i]<='Z') || (s[i]>='a' && s[i]<='z'){
			u =int(s[i]-'A')
			if v[u]==0 {
				nn++
			}
			v[u]=1
		}
	}
	fmt.Println(nn)
}

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    str, _, _ := in.ReadLine()
    mp := map[byte]int{}
    for _, i := range str {
        if i >= 'a' && i <= 'z' {
            mp[i-byte('a')]++
        }
    }
    fmt.Println(len(mp))
}

package main

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

func main() {
	var text string
	var pattern *regexp.Regexp
	var index [][]int
	var alphabet [26]int
	var count int
	var scanner *bufio.Scanner

	pattern = regexp.MustCompile(`\w`)

	scanner = bufio.NewScanner(os.Stdin)
	scanner.Scan()
	text = scanner.Text()
	// fmt.Println(text)
	index = pattern.FindAllStringSubmatchIndex(text, -1)
	for _, second := range index {
		if alphabet[text[second[0]]-97] != 1 {
			count++
			alphabet[text[second[0]]-97] = 1
		}
	}

	fmt.Println(count)
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    var f [26]bool
    ans := 0
    for _, v := range scanner.Text() {
        if (v >= 'a') && (v <= 'z') {
            a := int(v-'a')
            if !f[a] { f[a] = true; ans++ }
        }
    }
    fmt.Println(ans)
}

package main

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

func main() {
	var input string
	// fmt.Scan(&input)
	in := bufio.NewReader(os.Stdin)
	input, _ = in.ReadString('\n')
	var results int
	if len(input) < 3 {
		fmt.Println(results)
		return
	}
	// input = input[1 : len(input)-2]
	records := make(map[rune]bool)
	for _, i := range input {
		if i < 97 || i > 122 {
			continue
		}
		records[i] = true
	}
	// fmt.Println(records)
	fmt.Println(len(records))
}

package main

import (
	"bufio"
	"os"

	"strings"
	"fmt"
)

func getString() string {
	sc := bufio.NewScanner(os.Stdin)
	for sc.Scan() {
		str := sc.Text()
		return str[1:len(str)-1]
	}
	return sc.Text()
}

func unique(str string) int {
	intSlice := []byte(str)
	keys := make(map[byte]bool)
	list := []byte{}
	for _, entry := range intSlice {
		if _, value := keys[entry]; !value {
			keys[entry] = true
			list = append(list, entry)
		}
	}
	return len(list)
}

func main() {
	str := getString()
	str = strings.Replace(str, ",", "", -1)
	str = strings.Replace(str, " ", "", -1)
	fmt.Println(unique(str))
}

package main

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

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1024 * 1024)
	line := readLine(reader)
	out := strings.Split(line[1:len(line)-1], ", ")
	set := make(map[string]bool)
	for _, c := range out {
		if c != "" {
			set[c] = true
		}
	}
	fmt.Println(len(set))
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

func main() {
	s, _ := bufio.NewReader(os.Stdin).ReadString('}')
	ls := strings.Split(strings.Replace(s[1:len(s)-1], " ", "", -1), ",")
	m := make(map[string]bool)
	for _, l := range ls {
		if l != "" {
			m[l] = true
		}
	}
	fmt.Print(len(m))
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	str := scanner.Text()

	if str == "{}" {
		fmt.Println(0)
		return
	}

	res := strings.Split(str, ", ")
	res[0] = string([]byte{byte(res[0][1])})
	res[len(res)-1] = string([]byte{byte(res[len(res)-1][0])})
	unq := map[string]int{}

	for _, x := range res {
		unq[x] = 0
	}

	fmt.Println(len(unq))
}

package main

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

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

func ReadInt() uint64 {
    scanner.Scan()
    ans, _ := strconv.ParseUint(scanner.Text(), 10, 64)
    return ans
}

func PrintInt(value uint64) {
    writer.WriteString(strconv.FormatUint(value, 10))
    writer.WriteByte('\n')
}

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

    scanner.Scan()

    var line string = strings.Trim(scanner.Text(), "{}")
    var letters []string = strings.Split(line, ", ")
    var s map[string]bool = make(map[string]bool, 40)
    for _, val := range letters {
        s[val] = true
    }
    if len(line) > 0 {
        fmt.Println(len(s))
    } else {
        fmt.Println(0)
    }
}

package main

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

func main() {
  letter := make(map[byte]bool)
  bio := bufio.NewReader(os.Stdin)
  for line, hasMoreInLine, err := bio.ReadLine(); err == nil; {
    for _, char := range line {
      if 'a' <= char && char <= 'z' {
        letter[char] = true
      }
    }
    if !hasMoreInLine {
      break
    }
  }
  fmt.Println(len(letter))
}

package main

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

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	_ = stdin.Scan()
	inputLine := stdin.Text()

	alphabetFlags := make([]bool, 26)
	uniqueCount := 0

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

		switch c {
		case '{':
		case '}':
		case ',':
		case ' ':
			break
		default:
			if alphabetFlags[c - 'a'] == false {
				uniqueCount++
			}
			alphabetFlags[c - 'a'] = true
		}
	}

	fmt.Println(uniqueCount)
}

package main

import s "strings"
import "fmt"

func main() {
	var x, a, b, c, chr string

    for {
		n, err := fmt.Scanf("%s", &x)
        if n == 0 || err != nil { break }

		a = s.ReplaceAll(x, ",", "")
		b = s.ReplaceAll(a, "{", "")
		c = s.ReplaceAll(b, "}", "")
		chr += c
	}
	var str [26]int
	count := 0

	for i := 0; i < len(chr); i++ {
		str[chr[i]-'a']++
	}

	for i := 0; i < len(str); i++ {
		if str[i] > 0 {
			count++
		}
	}
	fmt.Println(count)

}

package main

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

func main() {
	sc := NewScanner(os.Stdin)
	s, _ := sc.NextLine()
	res := 0
	for i := 'a'; i <= 'z'; i++ {
		if strings.ContainsRune(s, i) {
			res++
		}
	}
	fmt.Println(res)
}

////////////////////////////////////////////////////////////////
//
//  gojus: retrieved from https://github.com/tnoda/gojus
//

// NewScanner returns a new Scanner to read from r.
func NewScanner(rdr io.Reader) *Scanner {
	sc := Scanner{bufio.NewScanner(rdr), 10}
	return &sc
}

// Errors returned by Scanner
var (
	ErrNoSuchElement = errors.New("gojus.Scanner: input is exhausted.")
)

// Scanner provides a similar interface to the java.util.Scaner's one.
type Scanner struct {
	*bufio.Scanner
	radix int
}

// Next scans and returns the next token of the input.
func (sc *Scanner) Next() (string, error) {
	sc.Split(bufio.ScanWords)
	if !sc.Scan() {
		return "", ErrNoSuchElement
	}
	return sc.Text(), nil
}

// UseRadix sets the scanner's default radix to the specified one.
func (sc *Scanner) UseRadix(radix int) *Scanner {
	sc.radix = radix
	return sc
}

func (sc *Scanner) nextLong() (int64, error) {
	t, e := sc.Next()
	if e != nil {
		return 0, e
	}
	return strconv.ParseInt(t, sc.radix, 64)
}

// NextLong scans and returns the next token of the input as an int64.
func (sc *Scanner) NextLong() (int64, error) {
	return sc.nextLong()
}

// NextDouble scans and returns the next token of the input as a float64
func (sc *Scanner) NextDouble() (float64, error) {
	t, e := sc.Next()
	if e != nil {
		return 0, e
	}
	return strconv.ParseFloat(t, 64)
}

// NextLine advances this scanner past the current line and returns
// the input that was skipped.
func (sc *Scanner) NextLine() (string, error) {
	sc.Split(bufio.ScanLines)
	if !sc.Scan() {
		return "", ErrNoSuchElement
	}
	return sc.Text(), nil
}

package main

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

func main() {
	inputBytes, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		panic(err)
	}

	input := string(inputBytes)
	input = strings.NewReplacer("{", "", "}", "", "\n", "").Replace(input)
	input = strings.TrimSpace(input)

	var seen = map[string]struct{}{}
	var ok bool

	for _, symb := range strings.Split(input, ", ") {
		if _, ok = seen[symb]; ok || symb == "" {
			continue
		}
		seen[symb] = struct{}{}
	}

	fmt.Println(len(seen))
}

package main

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

var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

var s string

func main() {
	sb, _, _ := reader.ReadLine()
	s = string(sb)
	if s == "{}" {
		fmt.Println(0)
		return
	}
	s = s[1 : len(s)-1]
	list := strings.Split(s, ", ")
	m := make(map[string]int)
	for i := 0; i < len(list); i++ {
		m[list[i]] = 1
	}
	fmt.Println(len(m))
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	xm := make(map[string]string)
	var s string

	s, _ = in.ReadString('\n')
	t := strings.ReplaceAll(s, ",", "")
	t = strings.ReplaceAll(t, "{", "")
	t = strings.ReplaceAll(t, "}", "")

	words := strings.Fields(t)
	if len(words) == 0{
		fmt.Println(0)
	}else{
		for i := 0; i < len(words); i++{
			xm[words[i]] = words[i];
		}
		fmt.Println(len(xm))
	}
}

package main

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

func main() {

	var S string

	scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan() // use `for scanner.Scan()` to keep reading

	S = scanner.Text()

	m := make(map[string]int)
	arr := string([]rune(S))
	for i:=0 ; i<len(arr) ;i++{
		if arr[i] == 123 || arr[i] == 125 || arr[i] == 32 || arr[i] == 44 {
			continue
		}else{
			m[string(arr[i])] += 1
		}
	}
	fmt.Println(len(m))
}

package main

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

func main() {
    reader := bufio.NewReader(os.Stdin)
    line, _ := reader.ReadString('\n')

    chars := make([]int, 26, 26)
    for i := 0; i < len(line); i++ {
        if line[i] >= 'a' && line[i] <= 'z' {
            chars[line[i] - 'a'] += 1
        }
    }

    result := 0
    for i := 0; i < 26; i++ {
        if chars[i] != 0 {
            result += 1
        }
    }

    fmt.Println(result)
}

//  URL: http://codeforces.com/problemset/problem/443/A
//  ~ Basic Implementation Problem

package main

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

func solve(s string) int {
	distinctCount := 0
	letterMap := make(map[rune]int)
	for _, elem := range s {
		if 'a' <= elem && elem <= 'z' && letterMap[elem] == 0 {
			letterMap[elem] += 1
			distinctCount += 1
		}
	}
	return distinctCount
}

func main() {
	reader, writer := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	s, _ := reader.ReadString('\n')
	fmt.Fprintf(writer, "%d\n", solve(s))
}

package main

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

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

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

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

func main() {

	in := bufio.NewReader(os.Stdin)
	S, _ := in.ReadString('\n')

	re, _ := regexp.Compile("[^a-zA-Z]")
	values := strings.Split(re.ReplaceAllString(S, ""), "")

	m := map[string]int{}
	for _, v := range values {
		if _, ok := m[v]; !ok {
			m[v] = 1
		}
	}

	fmt.Println(len(m))

}

package main

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

func main() {
	var myChar, firstString string
	var lastChar, currentChar byte
	var result int
	charArr := make([]int, 26)
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &firstString)
	currentChar = firstString[1]
	if currentChar != '}' {
		result++
		charArr[currentChar-97]++
	}
	lastChar = firstString[len(firstString)-1]
	for lastChar != '}' {
		fmt.Fscan(reader, &myChar)
		lastChar = myChar[len(myChar)-1]
		currentChar = myChar[0]
		if charArr[currentChar-97] == 0 {
			result++
			charArr[currentChar-97]++
		}

	}
	fmt.Println(result)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		line := scanner.Text()
		m := make(map[rune]bool)
		for _, c := range line {
			if c >= 'a' && c <= 'z' {
				m[c] = true
			}
		}
		fmt.Println(len(m))
	}
}

package main

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

func main() {
	var s1, s2 string
	var flag bool
	var summ int
	reader := bufio.NewReader(os.Stdin)
	s1, _ = reader.ReadString('\n')
	for i := range s1 {
		flag = false
		if s1[i] >= 'a' && s1[i] <= 'z' {
			for j := range s2 {
				if s1[i] == s2[j] {
					flag = true
					break
				}
			}
			if !flag {
				s2 = s2 + string(s1[i])
				summ++
			}
		}
	}
	fmt.Println(summ)
}

package main

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

func main() {
	// var s string
	// fmt.Scanln(&s)
	// fmt.Println(s)
	in := bufio.NewReader(os.Stdin)
	s, _ := in.ReadString('\n')
	s = strings.TrimSpace(s)

	m := make(map[string]bool)
	for _, tok := range strings.Split(s[1:len(s)-1], ", ") {
		m[tok] = true
	}
	delete(m, "")
	// fmt.Println(m)
	fmt.Println(len(m))
}

package main

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

func check(e error) {
	if e != nil {
		panic(e)
	}
}

func main() {
	var str string
	m := make(map[string]string, 0)
	reader := bufio.NewReader(os.Stdin)
	str, _ = reader.ReadString('\n')
	reg, _ := regexp.Compile("[^a-z,]")
	match := reg.ReplaceAllString(str,"")
	charLength := strings.Split(strings.TrimSpace(match), ",")
	for _, c := range charLength {
		if len(c) > 0 {
			m[c] = c
		}
	}
	printf("%d ", len(m))
}

func printf(format string, x ...interface{}) {
	fmt.Fprintf(os.Stdout, format, x...)
}

func scanf(format string, x ...interface{}) {
	if _, err := fmt.Fscanf(os.Stdin, format, x...); err != nil {
		panic(err)
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	data, _, _ := reader.ReadLine()
	str := string(data)
	if str == "{}" {
		fmt.Println(0)
	} else {
		str = strings.Replace(str, " ", "", -1)
		str = strings.Replace(str, "{", "", -1)
		str = strings.Replace(str, "}", "", -1)
		slice := strings.Split(str, ",")

		temp := make([]string, 0)

		for _, s := range slice {
			flag := false
			for _, t := range temp {
				if s == t {
					flag = true
					break
				}
			}
			if flag == false {
				temp = append(temp, s)
			}
		}
		fmt.Println(len(temp))
	}
}

package main

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

// https://codeforces.com/problemset/problem/443/A
// A. Anton and Letters
// time limit per test
// 2 seconds
// memory limit per test
// 256 megabytes
// input
// standard input
// output
// standard output

// Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.

// Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
// Input

// The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
// Output

// Print a single number — the number of distinct letters in Anton's set.

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	_ = scanner.Scan()
	line := scanner.Text()

	line = line[1 : len(line)-1]

	if len(line) == 0 {
		fmt.Print(0)
		return
	}

	letters := strings.Split(line, ", ")

	set := make(map[string]struct{}, len(letters))
	for _, letter := range letters {
		set[letter] = struct{}{}
	}

	fmt.Print(len(set))
}

package main

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

// https://codeforces.com/problemset/problem/443/A
// комментарии к решению
// Требуется подсчитать кол-во неуникальных латинских букв,,
// поэтому уместно воспользоваться множествами set (map[T]struct{} в go)
func taskSolution(in []byte) int {
	type s struct{}
	exists := s{}
	chars := map[byte]s{}

	for _, c := range in {
		if c >= 'a' && c <= 'z' {
			chars[c] = exists
		}
	}

	return len(chars)
}

func main() {
	inRaw, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		panic(err)
	}

	fmt.Println(taskSolution(inRaw))
}

package main

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

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

	str, err := buf.ReadString('\n')
	if err != nil {
		panic(err)
	}
	// if str == "{}\n" || str == "()\n" {
	// 	fmt.Println("0")
	// 	return
	// }
	newStr := str[strings.Index(str, "{")+1 : strings.Index(str, "}")]
	if newStr == "" {
		fmt.Println("0")
		return
	}
	// fmt.Printf("NEWSTR: %v, len %v\n", newStr, len(newStr))
	res := make(map[string]int)
	chars := strings.Split(newStr, ", ")
	if len(chars) == 1 {
		fmt.Printf("%v\n", 1)
		return
	}
	for _, char := range chars {
		res[char]++
	}
	fmt.Printf("%v\n", len(res))
}

package main

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

func main() {
	var s string
	in := bufio.NewReader(os.Stdin)
	s, _ = in.ReadString('\n')
	//fmt.Fscanln(in, &s)
	//fmt.Println(s)
	ss := s[1 : len(s)-1]
	if len(ss) == 0 {
		fmt.Println(0)
	} else {
		split := strings.Split(ss, ",")
		distince := make(map[string]bool, 0)
		for _, v := range split {

			distince[v] = true
		}
		ans := 0
		for _, _ = range distince {
			ans++
		}
		fmt.Println(ans)
	}
}

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

func main() {
	var(
		data string
		set = make(map[string]int)
	)
	reader := bufio.NewReader(os.Stdin)
	bytes, _, _ := reader.ReadLine()
	data = string(bytes)
	data = strings.Replace(data, "{", "", 1)
	data = strings.Replace(data, "}", "", 1)
	fmt.Println(data)
	for _, letter := range strings.Split(data, ", "){
		if "" != letter {
			_, ok := set[letter]
			if !ok {
				set[letter] = 1
			}
		}
	}

	fmt.Println(len(set))
}

package main
import (
	"fmt"
//	"unicode/utf8"
	"bufio"
	"os"
)
func main() {
	nn:=0
	var s string
	var u int

	input := bufio.NewScanner(os.Stdin)
    	s = input.Text();
	//len:=utf8.RuneCountInString(s)
	//a:=[]rune(s)
	v :=make([]int,1005)
	for i:=0;i<len(s);i++ {
		fmt.Println(s[i])
	}
	for i:=0;i<len(s);i++ {
		if  (s[i]>='A' && s[i]<='Z') || (s[i]>='a' && s[i]<='b'){
			u =int(s[i]-'A')
			if v[u]==0 {
				nn++
			}
			v[u]=1
		}
	}
	fmt.Println(nn)
}

package main
import (
	"fmt"
	"unicode/utf8"
)
func main() {
	var s string
	nn:=0
	fmt.Scan(&s)
	len:=utf8.RuneCountInString(s)
	v :=make([]int,1005)
	for i:=0;i<len;i++ {
	if  (s[i]>='A' && s[i]<='z'){
		u:=int(s[i]-'A')
		if v[u]==0 {
		nn++
		}
		v[u]=1
	}
	}
	fmt.Println(nn)
}

package main
import (
	"fmt"
	"unicode/utf8"
	"bufio"
	"os"
)
func main() {
	nn:=0
	var s string
	var u int
	input := bufio.NewScanner(os.Stdin)
    	s = input.Text();
	len:=utf8.RuneCountInString(s)
	a:=[]rune(s)
	v :=make([]int,1005)
	for i:=0;i<len;i++ {
		fmt.Println(a[i])
	}
	for i:=0;i<len;i++ {
		if  (a[i]>='A' && a[i]<='Z') || (a[i]>='a' && a[i]<='b'){
			u =int(s[i]-'A')
			if v[u]==0 {
				nn++
			}
			v[u]=1
		}
	}
	fmt.Println(nn)
}

package main

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

func main() {
	var input string
	// fmt.Scan(&input)
	in := bufio.NewReader(os.Stdin)
	input, _ = in.ReadString('\n')
	var results int
	if len(input) < 3 {
		fmt.Println(results)
		return
	}
	// input = input[1 : len(input)-2]
	records := make(map[rune]bool)
	for _, i := range input {
		if i == '{' || i == '}' || i == ',' || i == ' ' || i == '\n' {
			continue
		}
		records[i] = true
	}
	// fmt.Println(records)
	fmt.Println(len(records))
}

package main

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

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

func ReadInt() uint64 {
    scanner.Scan()
    ans, _ := strconv.ParseUint(scanner.Text(), 10, 64)
    return ans
}

func PrintInt(value uint64) {
    writer.WriteString(strconv.FormatUint(value, 10))
    writer.WriteByte('\n')
}

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

    scanner.Scan()

    var line string = strings.Trim(scanner.Text(), "{}")
    var letters []string = strings.Split(line, ", ")
    var s map[string]bool = make(map[string]bool, 40)
    for _, val := range letters {
        s[val] = true
    }
    fmt.Println(len(s))
}

package main

import (
  "fmt"
)

const N = 500000

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

var v, stk [N]int

func main() {
  var line string
  letter := make(map[rune]bool)
  fmt.Scanln(&line)
  for _, char := range line {
    if 'a' <= char && char <= 'z' {
      letter[char] = true
    }
  }
  fmt.Println(len(letter))
}

package main

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

func main() {
	inputBytes, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		panic(err)
	}

	input := string(inputBytes)
	input = strings.NewReplacer("{", "", "}", "", "\n", "").Replace(input)

	var seen = map[string]struct{}{}
	var ok bool

	for _, symb := range strings.Split(input, ", ") {
		if _, ok = seen[symb]; ok || symb == "" {
			continue
		}
		seen[symb] = struct{}{}
	}

	fmt.Println(len(seen))
}

package main

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

var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

var s string

func main() {
	sb, _, _ := reader.ReadLine()
	s = string(sb)

	s = s[1:len(s)-1] + ","
	list := strings.Fields(s)
	m := make(map[string]int)
	for i := 0; i < len(list); i++ {
		m[list[i]] = 1
	}
	fmt.Println(len(m))
}

package main

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

type void struct{}

func main() {

	in := bufio.NewReader(os.Stdin)
	line, _ := in.ReadString('\n')

	set := make(map[string]void)
	var member void

	letters := strings.Replace(line, " ", "", -1)
	letters = strings.Replace(letters, "{", "", -1)
	letters = strings.Replace(letters, "}", "", -1)
	letters = strings.Replace(letters, "\n", "", -1)

	//letters := replacer.Replace(line)
	//fmt.Println(letters)
	if len(letters) == 0 {
		fmt.Println(0)
		return
	}
	values := strings.Split(letters, ",")

	for _, v := range values {
		set[v] = member
	}

	fmt.Println(len(set))

}

package main

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

type void struct{}

func main() {

	in := bufio.NewReader(os.Stdin)
	line, _ := in.ReadString('\n')

	set := make(map[string]void)
	var member void

	letters := strings.Trim(line, "{}")
	values := strings.Split(letters, ",")

	for _, v := range values {
		set[v] = member
	}

	fmt.Println(len(set))

}

package main

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

type void struct{}

func main() {

	in := bufio.NewReader(os.Stdin)
	line, _ := in.ReadString('\n')

	set := make(map[string]void)
	var member void

	letters := strings.Replace(line, " ", "", -1)
	letters = strings.Replace(letters, "{", "", -1)
	letters = strings.Replace(letters, "}", "", -1)
	letters = strings.Replace(letters, "\n", "", -1)

	//letters := replacer.Replace(line)
	//fmt.Println(letters)
	values := strings.Split(letters, ",")

	for _, v := range values {
		set[v] = member
	}

	fmt.Println(len(set))

}

package main

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

type void struct{}

func main() {

	in := bufio.NewReader(os.Stdin)
	line, _ := in.ReadString('\n')

	set := make(map[string]void)
	var member void

	letters := strings.Replace(line, " ", "", -1)
	letters = strings.Replace(letters, "{", "", -1)
	letters = strings.Replace(letters, "}", "", -1)
	letters = strings.Replace(letters, "\n", "", -1)

	//letters := replacer.Replace(line)
	fmt.Println(letters)
	values := strings.Split(letters, ",")

	for _, v := range values {
		set[v] = member
	}

	fmt.Println(len(set))

}

package main

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

func main() {
	// var s string
	// fmt.Scanln(&s)
	// fmt.Println(s)
	in := bufio.NewReader(os.Stdin)
	s, _ := in.ReadString('\n')

	m := make(map[string]bool)
	for _, tok := range strings.Split(s[1:len(s)-2], ", ") {
		m[tok] = true
	}
	delete(m, "")
	fmt.Println(m)
	fmt.Println(len(m))
}

package main

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

func main() {
	// var s string
	// fmt.Scanln(&s)
	// fmt.Println(s)
	in := bufio.NewReader(os.Stdin)
	s, _ := in.ReadString('\n')

	m := make(map[string]bool)
	for _, tok := range strings.Split(s[1:len(s)-2], ", ") {
		m[tok] = true
	}
	fmt.Println(len(m))
}

package main

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

func main() {
	// var s string
	// fmt.Scanln(&s)
	// fmt.Println(s)
	in := bufio.NewReader(os.Stdin)
	s, _ := in.ReadString('\n')

	m := make(map[string]bool)
	for _, tok := range strings.Split(s[1:len(s)-2], ", ") {
		m[tok] = true
	}
	delete(m, "")
	// fmt.Println(m)
	fmt.Println(len(m))
}

package main

import (
	"regexp"
	"fmt"
	"os"
	"strings"
)

func check(e error) {
	if e != nil {
		panic(e)
	}
}

func main() {
	var str string
	m := make(map[string]string, 0)
	scanf("%s ", &str)
	reg, _ := regexp.Compile("[^a-z,]")
	match := reg.ReplaceAllString(str,"")

	charLength := strings.Split(match, ",")
	if len(charLength) > 1 {
		for _, c := range charLength {
			m[c] = c
		}
		printf("%d", len(m))
	}else{
		printf("%d", 0)
	}
}

func printf(format string, x ...interface{}) {
	fmt.Fprintf(os.Stdout, format, x...)
}

func scanf(format string, x ...interface{}) {
	if _, err := fmt.Fscanf(os.Stdin, format, x...); err != nil {
		panic(err)
	}
}

package main

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

func check(e error) {
	if e != nil {
		panic(e)
	}
}

func main() {
	var str string
	m := make(map[string]string, 0)
	reader := bufio.NewReader(os.Stdin)
	str, _ = reader.ReadString('\n')
	reg, _ := regexp.Compile("[^a-z,]")
	match := reg.ReplaceAllString(str,"")
	charLength := strings.Split(strings.TrimSpace(match), ",")
	if len(charLength) > 1 {
		idx := 0
		for _, c := range charLength {
			m[c] = c
			idx++
		}
		printf("%d", len(m))
	}else{
		printf("%d", 0)
	}
}

func printf(format string, x ...interface{}) {
	fmt.Fprintf(os.Stdout, format, x...)
}

func scanf(format string, x ...interface{}) {
	if _, err := fmt.Fscanf(os.Stdin, format, x...); err != nil {
		panic(err)
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	data, _, _ := reader.ReadLine()
	str := string(data)
	str = strings.Replace(str, " ", "", -1)
	str = strings.Replace(str, "{", "", -1)
	str = strings.Replace(str, "}", "", -1)
	slice := strings.Split(str, ",")

	temp := make([]string, 0)

	for _, s := range slice {
		flag := false
		for _, t := range temp {
			if s == t {
				flag = true
				break
			}
		}
		if flag == false {
			temp = append(temp, s)
		}
	}
	fmt.Println(len(temp))
}

package main

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

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

	str, err := buf.ReadString('\n')
	if err != nil {
		panic(err)
	}
	// if str == "{}\n" || str == "()\n" {
	// 	fmt.Println("0")
	// 	return
	// }
	newStr := str[strings.Index(str, "{")+1 : strings.Index(str, "}")]
	if newStr == "" {
		fmt.Println("0")
		return
	}
	// fmt.Printf("NEWSTR: %v, len %v\n", newStr, len(newStr))
	res := make(map[string]int)
	chars := strings.Split(newStr, ", ")
	if len(chars) == 1 {
		// fmt.Printf("%v\n", 1)
		return
	}
	for _, char := range chars {
		res[char]++
	}
	fmt.Printf("%v\n", len(res))
}

package main

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

func main() {
	buf := bufio.NewReader(os.Stdin)
	// for {

	str, err := buf.ReadString('\n')
	if err != nil {
		panic(err)
	}
	if str == "{}\n" || str == "()\n" {
		fmt.Println("0")
		return
		// continue
	}
	newStr := str[1 : len(str)-2]
	// fmt.Println(newStr)
	// fmt.Println("%v", len(newStr))
	res := make(map[string]int)
	for _, char := range strings.Split(newStr, ", ") {
		// fmt.Printf("char %v", char)
		res[char]++
	}
	fmt.Printf("%v\n", len(res))
	// fmt.Printf("%#v\n", res)
	// }
}


We say that a positive integer $$$n$$$ is $$$k$$$-good for some positive integer $$$k$$$ if $$$n$$$ can be expressed as a sum of $$$k$$$ positive integers which give $$$k$$$ distinct remainders when divided by $$$k$$$.Given a positive integer $$$n$$$, find some $$$k \geq 2$$$ so that $$$n$$$ is $$$k$$$-good or tell that such a $$$k$$$ does not exist.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases. Each test case consists of one line with an integer $$$n$$$ ($$$2 \leq n \leq 10^{18}$$$).

For each test case, print a line with a value of $$$k$$$ such that $$$n$$$ is $$$k$$$-good ($$$k \geq 2$$$), or $$$-1$$$ if $$$n$$$ is not $$$k$$$-good for any $$$k$$$. If there are multiple valid values of $$$k$$$, you can print any of them.

Note$$$6$$$ is a $$$3$$$-good number since it can be expressed as a sum of $$$3$$$ numbers which give different remainders when divided by $$$3$$$: $$$6 = 1 + 2 + 3$$$.$$$15$$$ is also a $$$3$$$-good number since $$$15 = 1 + 5 + 9$$$ and $$$1, 5, 9$$$ give different remainders when divided by $$$3$$$.$$$20$$$ is a $$$5$$$-good number since $$$20 = 2 + 3 + 4 + 5 + 6$$$ and $$$2,3,4,5,6$$$ give different remainders when divided by $$$5$$$.

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}
func readInt64(in *bufio.Reader) int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n,_ := strconv.ParseInt(nStr, 10, 64)
	return n
}
func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func main() {
	ip := bufio.NewReader(os.Stdin)
	t := readInt(ip)
	for t > 0 {
		t--
		n := readInt64(ip)
		x := n
		for x%2 == 0 {
			x /= 2
		}
		if x == 1 {
			fmt.Println(-1)
		} else {
			fmt.Println(min(n*2/x, x))
		}
	}
}
func min(i, j int64) int64 {
	if i > j {
		return j
	}
	return i
}

package main

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

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

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

package main

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

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

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

	c := 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		var n uint64
		fmt.Fscan(in, &n)
		x := n
		for x % 2 == 0 {
			x /= 2
		}
		if x == 1 {
			fmt.Fprintln(out, -1)
		} else if x <= 2e9 && x*(x+1)/2 <= n {
			fmt.Fprintln(out, x)
		} else {
			fmt.Fprintln(out, n/x*2)
		}
	}
}

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func main() {
	ip := bufio.NewReader(os.Stdin)
	t := readInt(ip)
	for t > 0 {
		t--
		n := readInt(ip)
		x := n
		for x%2 == 0 {
			x /= 2
		}
		if x == 1 {
			fmt.Println(-1)
		} else {
			fmt.Println(int64(min(n*2/x, x)))
		}
	}
}
func min(i, j int) int {
	if i > j {
		return j
	}
	return i
}

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func main() {
	ip, op := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	t := readInt(ip)
	for t > 0 {
		t--
		n := readInt(ip)
		x := n
		for x%2 == 0 {
			x /= 2
		}
		if x == 1 {
			fmt.Fprintln(op, int64(-1))
		} else {
			fmt.Fprintln(op, int64(min(n*2/x, x)))
		}
	}
}
func min(i, j int) int {
	if i > j {
		return j
	}
	return i
}

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func main() {
	ip,op := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	t := readInt(ip)
	for t > 0 {
		t--
		n := readInt(ip)
		x := n
		for x%2 == 0 {
			x /= 2
		}
		if x == 1 {
			fmt.Fprintln(op,-1)
		} else {
			fmt.Fprintln(op,min(n*2/x, x))
		}
	}
}
func min(i, j int) int {
	if i > j {
		return j
	}
	return i
}

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func main() {
	ip := bufio.NewReader(os.Stdin)
	t := readInt(ip)
	for t > 0 {
		t--
		n := readInt(ip)
		x := n
		for x%2 == 0 {
			x /= 2
		}
		if x == 1 {
			fmt.Println(-1)
		} else {
			fmt.Println(min(n*2/x, x))
		}
	}
}
func min(i, j int) int {
	if i > j {
		return j
	}
	return i
}

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func main() {
	ip := bufio.NewReader(os.Stdin)
	t := readInt(ip)
	for t > 0 {
		t--
		n := readInt(ip)
		x := n
		for x%2 == 0 {
			x /= 2
		}
		if x == 1 {
			fmt.Println(-1)
		} else {
			fmt.Println(min(n*2/x, x))
		}
	}
}
func min(i,j int)int{
	if i>j{
		return j
	}
	return i
}

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func main() {
	ip := bufio.NewReader(os.Stdin)
	t := readInt(ip)
	for t > 0 {
		t--
		n := readInt(ip)
		x := n
		for x%2 == 0 {
			x /= 2
		}
		if x == 1 {
			fmt.Println(-1)
		} else if (x*(x+1))/2 <= n {
			fmt.Println(x)
		} else {
			fmt.Println(2 * (n / x))
		}
	}
}

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func main() {
	ip := bufio.NewReader(os.Stdin)
	t := readInt(ip)
	for t > 0 {
		t--
		n := readInt(ip)
		x := n
		for x%2 == 0 {
			x >>=1
		}
		if x == 1 {
			fmt.Println(-1)
		} else {
			fmt.Println(2 * (n / x))
		}
	}
}

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func main() {
	ip := bufio.NewReader(os.Stdin)
	t := readInt(ip)
	for t > 0 {
		t--
		n := readInt(ip)
		x := n
		for x%2 == 0 {
			x /= 2
		}
		if x == 1 {
			fmt.Println(-1)
		} else if x <= 2e9 && (x*(x+1))/2 <= n {
			fmt.Println(x)
		} else {
			fmt.Println(2 * (n / x))
		}
	}
}

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func main() {
	ip := bufio.NewReader(os.Stdin)
	t := readInt(ip)
	for t > 0 {
		t--
		n := readInt(ip)
		x := n
		for x%2 == 0 {
			x /= 2
		}
		if x == 1 {
			fmt.Println(-1)
		} else if x <= 2e9 && (x*(x+1)/2 <= n) {
			fmt.Println(x)
		} else {
			fmt.Println(2 * (n / x))
		}
	}
}

package main

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

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

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

package main

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

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

			}
		}
	}
}

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

package main

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

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

			}
		}
	}
}

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

package main

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

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

			}
		}
	}
}

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

package main

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

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

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


The only difference between this problem and D2 is the bound on the size of the tree.You are given an unrooted tree with $$$n$$$ vertices. There is some hidden vertex $$$x$$$ in that tree that you are trying to find.To do this, you may ask $$$k$$$ queries $$$v_1, v_2, \ldots, v_k$$$ where the $$$v_i$$$ are vertices in the tree. After you are finished asking all of the queries, you are given $$$k$$$ numbers $$$d_1, d_2, \ldots, d_k$$$, where $$$d_i$$$ is the number of edges on the shortest path between $$$v_i$$$ and $$$x$$$. Note that you know which distance corresponds to which query.What is the minimum $$$k$$$ such that there exists some queries $$$v_1, v_2, \ldots, v_k$$$ that let you always uniquely identify $$$x$$$ (no matter what $$$x$$$ is).Note that you don't actually need to output these queries.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2000$$$)  — the number of vertices in the tree. Each of the next $$$n-1$$$ lines contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le n$$$), meaning there is an edges between vertices $$$x$$$ and $$$y$$$ in the tree. It is guaranteed that the given edges form a tree. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$.

For each test case print a single nonnegative integer, the minimum number of queries you need, on its own line.

NoteIn the first test case, there is only one vertex, so you don't need any queries.In the second test case, you can ask a single query about the node $$$1$$$. Then, if $$$x = 1$$$, you will get $$$0$$$, otherwise you will get $$$1$$$.

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 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 gi64() int64     { i,e := strconv.ParseInt(gs(),10,64); if e != nil {panic(e)}; return i }
func gis64(n int) []int64  { res := make([]int64,n); for i:=0;i<n;i++ { res[i] = gi64() }; 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 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 vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
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 ia64(m int) []int64 { return make([]int64,m) }
func iai64(m int,v int64) []int64 { a := make([]int64,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi64(n int,m int,v int64) [][]int64 {
	r := make([][]int64,n); for i:=0;i<n;i++ { x := make([]int64,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill264(m int) ([]int64,[]int64) { a,b := ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i] = gi64(),gi64()}; return a,b }
func fill364(m int) ([]int64,[]int64,[]int64) { a,b,c := ia64(m),ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi64(),gi64(),gi64()}; return a,b,c }
func fill464(m int) ([]int64,[]int64,[]int64,[]int64) { a,b,c,d := ia64(m),ia64(m),ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi64(),gi64(),gi64(),gi64()}; return a,b,c,d }
func abs64(a int64) int64 { if a < 0 { return -a }; return a }
func rev64(a []int64) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max64(a,b int64) int64 { if a > b { return a }; return b }
func min64(a,b int64) int64 { if a > b { return b }; return a }
func maxarr64(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr64(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr64(a []int64) int64 { ans := int64(0); for _,aa := range(a) { ans += aa }; return ans }
func zeroarr64(a []int64) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod64(a,e,mod int64) int64 { res, m := int64(1), a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint64(a,e int64) int64 { res, m := int64(1), a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd64(a,b int64) int64 { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended64(a,b int64) (int64,int64,int64) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended64(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv64(a,m int64) (int64,bool) { g,x,_ := gcdExtended64(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func vecint64string(a []int64) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.FormatInt(a,10) }; return strings.Join(astr," ") }
func makefact64(n int,mod int64) ([]int64,[]int64) {
	fact,factinv := make([]int64,n+1),make([]int64,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * int64(i) % mod }
	factinv[n] = powmod64(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * int64(i+1) % mod }
	return fact,factinv
}
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N := gi(); X,Y := fill2(N-1); for i:=0;i<N-1;i++ { X[i]--; Y[i]-- }
		gr := make([][]int,N)
		for i:=0;i<N-1;i++ { x,y := X[i],Y[i]; gr[x] = append(gr[x],y); gr[y] = append(gr[y],x) }
		best := N+10
		var dfs func(n,p int) int
		dfs = func(n,p int) int {
			ans := 0; z := 0
			for _,c := range gr[n] {
				if c == p { continue }
				r := dfs(c,n); ans += r; if r == 0 { z++ }
			}
			if z > 1 { ans += z-1 }
			return ans
		}
		for i:=0;i<N;i++ { best = min(best,dfs(i,-1)) }
		if N > 1 { best++ }
		fmt.Fprintln(wrtr,best)
	}
}