Harry came to know from Dumbledore that Salazar Slytherin's locket is a horcrux. This locket was present earlier at 12 Grimmauld Place, the home of Sirius Black's mother. It was stolen from there and is now present in the Ministry of Magic in the office of Dolorous Umbridge, Harry's former Defense Against the Dark Arts teacher. Harry, Ron and Hermione are infiltrating the Ministry. Upon reaching Umbridge's office, they observed a code lock with a puzzle asking them to calculate count of magic numbers between two integers l and r (both inclusive). Harry remembered from his detention time with Umbridge that she defined a magic number as a number which when converted to a given base b, all the digits from 0 to b - 1 appear even number of times in its representation without any leading zeros.You have to answer q queries to unlock the office. Each query has three integers bi, li and ri, the base and the range for which you have to find the count of magic numbers.

First line of input contains q (1 ≤ q ≤ 105) — number of queries. Each of the next q lines contain three space separated integers bi, li, ri (2 ≤ bi ≤ 10, 1 ≤ li ≤ ri ≤ 1018).

You have to output q lines, each containing a single integer, the answer to the corresponding query.

NoteIn sample test case 1, for first query, when we convert numbers 4 to 9 into base 2, we get:   4 = 1002,  5 = 1012,  6 = 1102,  7 = 1112,  8 = 10002,  9 = 10012. Out of these, only base 2 representation of 9 has even number of 1 and 0. Thus, the answer is 1.

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int64 {
	if !in.Scan() {
		panic(in.Err())
	}
	res := int64(0)
	for _, b := range in.Bytes() {
		res = res*10 + int64(b-'0')
	}
	return res
}

const (
	maxBase = 10
	maxLen  = 60
)

var cnt [maxBase + 1][maxLen + 1][1 << maxBase]int64

func init() {
	for base := 2; base <= maxBase; base++ {
		cnt[base][0][0] = 1
		for le := 0; le < maxLen; le++ {
			for i, v := range cnt[base][le] {
				for digit := 0; digit < base; digit++ {
					cnt[base][le+1][i^(1<<uint(digit))] += v
				}
			}
		}
	}
}

func numSmaller(b, x int64) int64 {
	if x == 0 {
		return 0
	}
	var digits []int
	for x > 0 {
		digits = append(digits, int(x%b))
		x /= b
	}

	ret := int64(0)
	for le := 2; le < len(digits); le++ {
		for d := 1; d < int(b); d++ {
			ret += cnt[b][le-1][1<<uint(d)]
		}
	}

	m := 0
	for pos := len(digits) - 1; pos >= 0; pos-- {
		if pos < len(digits) - 1 && digits[pos] != 0 {
			ret += cnt[b][pos][m^1]
		}
		for d := 1; d < digits[pos]; d++ {
			ret += cnt[b][pos][m^(1<<uint(d))]
		}
		m ^= 1 << uint(digits[pos])
	}
	if m == 0 {
		ret++
	}
	return ret
}

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

	for q := readInt(); q > 0; q-- {
		b := readInt()
		l := readInt()
		r := readInt()
		fmt.Fprintln(out, numSmaller(b, r)-numSmaller(b, l-1))
	}
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int64 {
	if !in.Scan() {
		panic(in.Err())
	}
	res := int64(0)
	for _, b := range in.Bytes() {
		res = res*10 + int64(b-'0')
	}
	return res
}

const (
	maxBase = 10
	maxLen  = 60
)

var cnt [maxBase + 1][maxLen + 1][1 << maxBase]int64

func init() {
	for base := 2; base <= maxBase; base++ {
		for i := 0; i < base; i++ {
			cnt[base][1][1<<uint(i)] = 1
		}
		for le := 1; le < maxLen; le++ {
			for i, v := range cnt[base][le] {
				for digit := 0; digit < base; digit++ {
					cnt[base][le+1][i^(1<<uint(digit))] += v
				}
			}
		}
	}
}

func numSmaller(b, x int64) int64 {
	if x == 0 {
		return 0
	}
	var digits []int
	for x > 0 {
		digits = append(digits, int(x%b))
		x /= b
	}
	ret := int64(0)
	for le := 2; le < len(digits); le++ {
		for d := 1; d <= int(b); d++ {
			ret += cnt[b][le-1][1<<uint(d)]
		}
	}

	m := 0
	for pos := len(digits) - 1; pos >= 0; pos-- {
		for d := 1; d < digits[pos]; d++ {
			ret += cnt[b][pos][m^(1<<uint(d))]
		}
		m ^= 1 << uint(digits[pos])
	}
	if m == 0 {
		ret++
	}
	return ret
}

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

	for q := readInt(); q > 0; q-- {
		b := readInt()
		l := readInt()
		r := readInt()
		fmt.Fprintln(out, numSmaller(b, r)-numSmaller(b, l-1))
	}
}


Sam is a kindergartener, and there are $$$n$$$ children in his group. He decided to create a team with some of his children to play "brawl:go 2".Sam has $$$n$$$ power-ups, the $$$i$$$-th has type $$$a_i$$$. A child's strength is equal to the number of different types among power-ups he has.For a team of size $$$k$$$, Sam will distribute all $$$n$$$ power-ups to $$$k$$$ children in such a way that each of the $$$k$$$ children receives at least one power-up, and each power-up is given to someone.For each integer $$$k$$$ from $$$1$$$ to $$$n$$$, find the minimum sum of strengths of a team of $$$k$$$ children Sam can get.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3 \cdot 10^5$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$).  The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — types of Sam's power-ups. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

For every test case print $$$n$$$ integers. The $$$k$$$-th integer should be equal to the minimum sum of strengths of children in the team of size $$$k$$$ that Sam can get.

package main

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

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

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

		m := make(map[int64]bool)
		var u int64
		for i := int64(0); i < n; i++ {
			var v int64
			fmt.Fscan(in, &v)

			if !m[v] {
				u++
			}
			m[v] = true
		}

		for i := int64(0); i < u; i++ {
			fmt.Fprintf(out, "%d ", u)
		}

		for i := u + 1; i <= n; i++ {
			fmt.Fprintf(out, "%d ", i)
		}
		fmt.Fprintln(out)
	}
}

// LUOGU_RID: 91700269
package main

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

func main() {
	// 快速输入输出
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	var t, n, i int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var a int
		fmt.Fscan(f, &n)
		m := map[int]int{}
		for i = 0; i < n; i++ {
			fmt.Fscan(f, &a)
			m[a]++
		}
		l := len(m)
		for i = 1; i <= l; i++ {
			fmt.Fprint(w, l, " ")
		}
		for i = l + 1; i <= n; i++ {
			fmt.Fprint(w, i, " ")
		}
		fmt.Fprintln(w, "") // 换行
	}
	w.Flush()
}

package main

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

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

	var T, n, x int
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		Fscan(r, &n)
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			Fscan(r, &x)
			mp[x]++
		}
		for i := 1; i <= n; i++ {
			if i <= len(mp) {
				Fprintf(w, "%d ", len(mp))
			} else {
				Fprintf(w, "%d ", i)
			}
		}
		Fprintln(w)
	}

}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		o, p := map[int]int{}, 0
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &p)
			o[p]++
		}
		l := len(o)
		for j := 0; j < l; j++ {
			fmt.Fprint(w, l, " ")
		}
		for j := l + 1; j <= n; j++ {
			fmt.Fprint(w, j, " ")
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

/*
1
6
2 5 4 4 1 1
---
4 4 4 4 5 5 6
1  1  4  | 4 | 2 | 5
=======
2
3
1 1 1
5
1 1 1 2 2
---
1 2 3
2 2 3 4 5
1 | 1 | 1 | 2 | 2

2       5

*/

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

	a := make([]int, n)

	typeToCnt := make(map[int]int)

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

		typeToCnt[a[i]]++
	}
	scanf("\n")

	type pair struct {
		num int
		cnt int
	}

	nums := make([]pair, 0)

	for num, cnt := range typeToCnt {
		nums = append(nums, pair{num, cnt})
	}

	sort.Slice(nums, func(i, j int) bool {
		return nums[i].cnt >= nums[j].cnt
	})

	base := len(nums)
	//diff := 0

	for k := 1; k <= n; k++ {
		ans := base

		if k > base {
			ans = k
		}

		fmt.Fprintf(writer, "%d ", ans)

		//nums[len(nums)-1].cnt--
		//if nums[len(nums)-1].cnt == 0 {
		//	nums = nums[:len(nums)-1]
		//} else {
		//	diff++
		//}
	}
	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 int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int64) int64 {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

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

	return nums[idx], idx
}

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

//nolint
package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

//}

func Solve() {
	var n, tp int
	scan(&n)
	flag := make(map[int]bool)
	for i := 0; i < n; i++ {
		scan(&tp)
		flag[tp] = true
	}
	l := len(flag)
	for i := 1; i <= n; i++ {
		if i <= l {
			print(l, " ")
		} else {
			print(i, " ")
		}
	}
	println()
}

package main

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

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

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

func main() {
	defer out.Flush()

	var tc int
	fmt.Fscan(in, &tc)
	for ; tc > 0; tc-- {
		var n int
		fmt.Fscan(in, &n)
		types := map[int]bool{}
		for i := 0; i < n; i++ {
			var t int
			fmt.Fscan(in, &t)
			types[t] = true
		}
		typecnt := len(types)
		for i := 1; i <= n; i++ {
			fmt.Fprint(out, max(i, typecnt), " ")
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

	type pair struct {
		val, cnt int
	}
	var T, n, x int
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		Fscan(r, &n)
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			Fscan(r, &x)
			mp[x]++
		}
		var p []pair
		for k, v := range mp {
			p = append(p, pair{k, v})
		}
		sort.Slice(p, func(i, j int) bool {
			return p[i].cnt >= p[j].cnt
		})
		k := 0
		for len(p) > 0 {
			Fprintf(w, "%d ", len(p)+k)
			if p[len(p)-1].cnt == 1 {
				p = p[:len(p)-1]
			} else {
				p[len(p)-1].cnt--
			}
			k++
		}
		Fprintln(w)
	}

}

package main

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

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

	type pair struct {
		val, cnt int
	}
	var T, n, x int
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		Fscan(r, &n)
		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			Fscan(r, &x)
			mp[x]++
		}
		var p []pair
		for k, v := range mp {
			p = append(p, pair{k, v})
		}
		sort.Slice(p, func(i, j int) bool {
			return p[i].cnt > p[j].cnt
		})
		k := 0
		for len(p) > 0 {
			Fprintf(w, "%d ", len(p)+k)
			if p[len(p)-1].cnt == 1 {
				p = p[:len(p)-1]
			} else {
				p[len(p)-1].cnt--
			}
			k++
		}
		Fprintln(w)
	}

}

package main

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

/*
1
6
2 5 4 4 1 1
---
4 4 4 4 5 5 6
1  1  4  | 4 | 2 | 5
*/

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

	a := make([]int, n)

	typeToCnt := make(map[int]int)

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

		typeToCnt[a[i]]++
	}
	scanf("\n")

	type pair struct {
		num int
		cnt int
	}

	nums := make([]pair, 0)

	for num, cnt := range typeToCnt {
		nums = append(nums, pair{num, cnt})
	}

	sort.Slice(nums, func(i, j int) bool {
		return nums[i].cnt >= nums[j].cnt
	})

	base := len(nums)
	diff := 0

	for k := 0; k < n; k++ {
		ans := base + diff

		fmt.Fprintf(writer, "%d ", ans)

		nums[len(nums)-1].cnt--
		if nums[len(nums)-1].cnt == 0 {
			nums = nums[:len(nums)-1]
		} else {
			diff++
		}
	}
	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 int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int64) int64 {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

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

	return nums[idx], idx
}

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


You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s < h_i < h_b$$$ and $$$w_s < w_i < w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).

The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s < h_b,\ w_s < w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.

Note  In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 < 2$$$ (comparing heights) and $$$1 < 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 < 3$$$ (comparing heights) and $$$3 < 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.

package main

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

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

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

		mm := make([][]int64, 1001)
		for i := range mm {
			mm[i] = make([]int64, 1001)
		}

		for i := 0; i < n; i++ {
			var h, w int64
			fmt.Fscan(in, &h, &w)

			mm[h][w] += h * w
		}
		for i := 1; i <= 1000; i++ {
			for j := 1; j <= 1000; j++ {
				mm[i][j] += mm[i-1][j] + mm[i][j-1] - mm[i-1][j-1]
			}
		}

		for i := 0; i < q; i++ {
			var h1, w1, h2, w2 int
			fmt.Fscan(in, &h1, &w1, &h2, &w2)

			fmt.Fprintln(out, mm[h1][w1]+mm[h2-1][w2-1]-mm[h2-1][w1]-mm[h1][w2-1])
		}
	}
}

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func solve() {
	var n, q int
	var h, w int64
	scan(&n, &q)
	a := make([][]int64, 1001)
	for i := 0; i <= 1000; i++ {
		a[i] = make([]int64, 1001)
	}
	for i := 0; i < n; i++ {
		scan(&h, &w)
		a[h][w] += h * w
	}
	for h := 1; h <= 1000; h++ {
		for w := 1; w <= 1000; w++ {
			a[h][w] += a[h-1][w] + a[h][w-1] - a[h-1][w-1]
		}
	}
	var hs, ws, hb, wb int
	for i := 0; i < q; i++ {
		scan(&hs, &ws, &hb, &wb)
		hb--
		wb--
		printf("%d\n", a[hb][wb]+a[hs][ws]-a[hb][ws]-a[hs][wb])
	}
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

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

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

		var n, q, h, w, H, W int
		fmt.Fscan(rr, &n, &q)

		dp := make([][]int, 1002)
		for i := range dp { dp[i] = make([]int, 1002) }

		for i := 0; i < n; i++ {
			fmt.Fscan(rr, &h, &w)
			dp[h][w] += h*w
		}

		for i := 1; i <= 1001; i++ {
			for j := 1; j <= 1001; j++ {
				dp[i][j] += dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1]
			}
		}

		for i := 0; i < q; i++ {
			fmt.Fscan(rr, &h, &w, &H, &W)
			fmt.Fprintln(ww, dp[H-1][W-1] - dp[H-1][w] - dp[h][W-1] + dp[h][w])
		}
	}

}

package main

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

var pre [1005][1005]int64
var a [1005][1005]int64

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n, q int
		fmt.Fscan(in, &n, &q)
		for i := 0; i <= 1004; i++ {
			for j := 0; j <= 1004; j++ {
				pre[i][j] = 0
				a[i][j] = 0
			}
		}
		for i := 1; i <= n; i++ {
			var x int64
			var y int64
			fmt.Fscan(in, &x, &y)
			a[x][y] += x * y
		}
		for i := 1; i <= 1000; i++ {
			for j := 1; j <= 1000; j++ {
				pre[i][j] = pre[i-1][j] + pre[i][j-1] - pre[i-1][j-1] + a[i][j]
			}
		}
		for i := 1; i <= q; i++ {
			var x, y, x1, y1 int
			fmt.Fscan(in, &x, &y, &x1, &y1)
			fmt.Fprintln(out, pre[x1-1][y1-1]-pre[x1-1][y]-pre[x][y1-1]+pre[x][y])
		}
	}
}

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func solve() {
	var n, q int
	var h, w int64
	scan(&n, &q)
	a := make([][]int64, 1001)
	for i := 0; i <= 1000; i++ {
		a[i] = make([]int64, 1001)
	}
	for i := 0; i < n; i++ {
		scan(&h, &w)
		a[h][w] += h * w
	}
	for h := 1; h <= 1000; h++ {
		for w := 1; w <= 1000; w++ {
			a[h][w] += a[h-1][w] + a[h][w-1] - a[h-1][w-1]
		}
	}
	var hs, ws, hb, wb int
	for i := 0; i < q; i++ {
		scan(&hs, &ws, &hb, &wb)
		hb--
		ws--
		printf("%d\n", a[hb][wb]+a[hs][ws]-a[hb][ws]-a[hs][wb])
	}
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}


A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example:   If x = 6 and the crossword is 111011, then its encoding is an array {3, 2};  If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1};  If x = 5 and the crossword is 11111, then its encoding is an array {5};  If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!

The first line contains two integer numbers n and x (1 ≤ n ≤ 100000, 1 ≤ x ≤ 109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 10000) — the encoding.

Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.

package main

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

func main() {
	var n, x int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n)
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &x)

	for i := 0; i < n; i++ {
		var a int
		scanner.Scan()
		fmt.Sscan(scanner.Text(), &a)
		x -= a
	}

	if x-n+1 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

var scanner *bufio.Scanner

func main() {
	setup()
	n, x := readInt(), readInt()

	for i := 0; i < n; i++ {
		x -= readInt()
	}

	if x-n+1 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func setup() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
}

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

package main

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

func main() {
	var (
		n, x int
	)

	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d%d\n", &n, &x)

	var sum int = 0
	for i := 0; i < n; i++ {
		var a int
		fmt.Fscanf(in, "%d", &a)
		sum += a
	}

	if sum+n-1 == x {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

import(
	"fmt"
	"bufio"
	"os"
)
func main() {
	cin := bufio.NewReader(os.Stdin)

	var n,x int
	fmt.Fscanf(cin,"%d%d",&n,&x)
	var tmp,sum int
	for i:= 0;i < n;i++{
		fmt.Fscan(cin,&tmp)
		sum += tmp
	}

	if sum + n - 1 == x{
		fmt.Println("YES")
	} else{
		fmt.Println("NO")
	}
}

// Codeforces 884 B. Japanese Crosswords Strike Back, train
package main

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

var in *bufio.Reader

func readFive() (int, int, int, int, int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i := 0; i < len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0], a[1], a[2], a[3], a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for j := 0; j < n; j++ {
		aa, err := strconv.Atoi(ss[j])
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[j] = aa
	}
	return a
}

var n,x int
var a []int
var ans string

// readData read data for out problem.
func readData() {
	in = bufio.NewReader(os.Stdin)
	// reading string a
	n,x,_,_,_ = readFive()
	a = readLineNumbs(n)
}

// solve func solves our problem.
func solve() {
	suml := 0
	for _,aa := range a {
		suml += aa
	}
	if suml + n - 1 == x {
		ans = "YES"
	} else {
		ans = "NO"
	}
}

// printRes print problem solution in expected format.
func printRes() {
	fmt.Println(ans)
}

func main() {
	readData()
	solve()
	printRes()
}

package main

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

func main() {
	var n, x int
	in := bufio.NewReader(os.Stdin)

	fmt.Fscanf(in, "%d%d\n", &n, &x)
	//fmt.Println(n, x)
	for i := 0; i < n; i++ {
		var p int

		fmt.Fscanf(in, "%d", &p)
		//fmt.Println(x, p, i)

		x -= p
	}

	if x-n+1 == 0 {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}

}

package main

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

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

	var n, x int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n, &x)

	scanner.Scan()
	text := scanner.Text()
	for text == "" {
		scanner.Scan()
		text = scanner.Text()
	}

	for _, i := range strings.Split(text, " ") {
		ai, _ := strconv.Atoi(i)
		x -= ai
	}

	if x-n+1 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

func main() {
	var n, x int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n, &x)

	scanner.Scan()
	for _, i := range strings.Split(scanner.Text(), " ") {
		ai, _ := strconv.Atoi(i)
		x -= ai
	}

	if x-n+1 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

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

	var n, x int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n, &x)

	scanner.Scan()
	for _, i := range strings.Split(scanner.Text(), " ") {
		ai, _ := strconv.Atoi(i)
		x -= ai
	}

	if x-n+1 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

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

	var n, x int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n, &x)
	tes := x

	max := 0
	a := make([]int, n)
	scanner.Scan()
	for idx, i := range strings.Split(scanner.Text(), " ") {
		ai, _ := strconv.Atoi(i)
		x -= ai
		a[idx] = ai
		max = idx + 1
	}

	if x-n+1 == 0 {
		fmt.Println("YES")
	} else if tes == 649637 {
		fmt.Println(x-n+1, n, len(a), max)
	} else {
		fmt.Println("NO")
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var n, x int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n, &x)
	tes := x

	max := 0
	a := make([]int, n)
	scanner.Scan()
	text := scanner.Text()
	for text == "" {
		scanner.Scan()
		text = scanner.Text()
	}
	for idx, i := range strings.Split(text, " ") {
		ai, _ := strconv.Atoi(i)
		x -= ai
		a[idx] = ai
		max = idx + 1
	}

	if x-n+1 == 0 {
		fmt.Println("YES")
	} else if tes == 649637 {
		fmt.Println(x-n+1, n, len(a), max, text)
	} else {
		fmt.Println("NO")
	}
}

package main

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

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

	var n, x int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n, &x)
	tes := x

	var a []int
	scanner.Scan()
	for _, i := range strings.Split(scanner.Text(), " ") {
		ai, _ := strconv.Atoi(i)
		x -= ai
		a = append(a, ai)
	}

	if x-n+1 == 0 {
		fmt.Println("YES")
	} else if tes == 649637 {
		fmt.Println(x-n+1, n, len(a))
	} else {
		fmt.Println("NO")
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var n, x int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n, &x)
	tes := x

	max := 0
	a := make([]int, n)
	scanner.Scan()
	awd := scanner.Text()
	for idx, i := range strings.Split(awd, " ") {
		ai, _ := strconv.Atoi(i)
		x -= ai
		a[idx] = ai
		max = idx + 1
	}

	if x-n+1 == 0 {
		fmt.Println("YES")
	} else if tes == 649637 {
		fmt.Println(x-n+1, n, len(a), max, awd)
	} else {
		fmt.Println("NO")
	}
}

package main

import "fmt"

func main() {
	var (
		n, x int64
	)

	fmt.Scanf("%d%d", &n, &x)

	var sum int64 = 0
	for i := int64(0); i < n; i++ {
		var a int64
		fmt.Scanf("%d", &a)
		sum += a
	}

	if sum+n-1 == x {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


In this problem you will have to help Berland army with organizing their command delivery system.There are $$$n$$$ officers in Berland army. The first officer is the commander of the army, and he does not have any superiors. Every other officer has exactly one direct superior. If officer $$$a$$$ is the direct superior of officer $$$b$$$, then we also can say that officer $$$b$$$ is a direct subordinate of officer $$$a$$$.Officer $$$x$$$ is considered to be a subordinate (direct or indirect) of officer $$$y$$$ if one of the following conditions holds:  officer $$$y$$$ is the direct superior of officer $$$x$$$;  the direct superior of officer $$$x$$$ is a subordinate of officer $$$y$$$. For example, on the picture below the subordinates of the officer $$$3$$$ are: $$$5, 6, 7, 8, 9$$$.The structure of Berland army is organized in such a way that every officer, except for the commander, is a subordinate of the commander of the army.Formally, let's represent Berland army as a tree consisting of $$$n$$$ vertices, in which vertex $$$u$$$ corresponds to officer $$$u$$$. The parent of vertex $$$u$$$ corresponds to the direct superior of officer $$$u$$$. The root (which has index $$$1$$$) corresponds to the commander of the army.Berland War Ministry has ordered you to give answers on $$$q$$$ queries, the $$$i$$$-th query is given as $$$(u_i, k_i)$$$, where $$$u_i$$$ is some officer, and $$$k_i$$$ is a positive integer.To process the $$$i$$$-th query imagine how a command from $$$u_i$$$ spreads to the subordinates of $$$u_i$$$. Typical DFS (depth first search) algorithm is used here.Suppose the current officer is $$$a$$$ and he spreads a command. Officer $$$a$$$ chooses $$$b$$$ — one of his direct subordinates (i.e. a child in the tree) who has not received this command yet. If there are many such direct subordinates, then $$$a$$$ chooses the one having minimal index. Officer $$$a$$$ gives a command to officer $$$b$$$. Afterwards, $$$b$$$ uses exactly the same algorithm to spread the command to its subtree. After $$$b$$$ finishes spreading the command, officer $$$a$$$ chooses the next direct subordinate again (using the same strategy). When officer $$$a$$$ cannot choose any direct subordinate who still hasn't received this command, officer $$$a$$$ finishes spreading the command.Let's look at the following example:  If officer $$$1$$$ spreads a command, officers receive it in the following order: $$$[1, 2, 3, 5 ,6, 8, 7, 9, 4]$$$.If officer $$$3$$$ spreads a command, officers receive it in the following order: $$$[3, 5, 6, 8, 7, 9]$$$.If officer $$$7$$$ spreads a command, officers receive it in the following order: $$$[7, 9]$$$.If officer $$$9$$$ spreads a command, officers receive it in the following order: $$$[9]$$$.To answer the $$$i$$$-th query $$$(u_i, k_i)$$$, construct a sequence which describes the order in which officers will receive the command if the $$$u_i$$$-th officer spreads it. Return the $$$k_i$$$-th element of the constructed list or -1 if there are fewer than $$$k_i$$$ elements in it.You should process queries independently. A query doesn't affect the following queries.

The first line of the input contains two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 2 \cdot 10^5, 1 \le q \le 2 \cdot 10^5$$$) — the number of officers in Berland army and the number of queries. The second line of the input contains $$$n - 1$$$ integers $$$p_2, p_3, \dots, p_n$$$ ($$$1 \le p_i < i$$$), where $$$p_i$$$ is the index of the direct superior of the officer having the index $$$i$$$. The commander has index $$$1$$$ and doesn't have any superiors. The next $$$q$$$ lines describe the queries. The $$$i$$$-th query is given as a pair ($$$u_i, k_i$$$) ($$$1 \le u_i, k_i \le n$$$), where $$$u_i$$$ is the index of the officer which starts spreading a command, and $$$k_i$$$ is the index of the required officer in the command spreading sequence.

Print $$$q$$$ numbers, where the $$$i$$$-th number is the officer at the position $$$k_i$$$ in the list which describes the order in which officers will receive the command if it starts spreading from officer $$$u_i$$$. Print "-1" if the number of officers which receive the command is less than $$$k_i$$$. You should process queries independently. They do not affect each other.

package main

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

func main(){
	in:=bufio.NewReader(os.Stdin)
	out:=bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n,q int
	Fscan(in,&n,&q)
	g:=make([][]int,n+1)
	for i:=0;i<n-1;i++{
		var p int
		Fscan(in,&p)
		g[p]=append(g[p],i+2)
	}
	orders:=make([]int,n)
	index:=0
	pos:=make([]int,n+1)
	stack:=[]int{1}
	lenStack:=1
	for lenStack>0{
		top:=stack[lenStack-1]
		stack=stack[:lenStack-1]
		orders[index]=top
		pos[top]=index
		index++
		lenG:=len(g[top])
		for i:=lenG-1;i>=0;i--{
			stack=append(stack,g[top][i])
		}
		lenStack=len(stack)
	}
	maxLens:=make([]int,n+1)
	for i:=n;i>0;i--{
		maxLens[i]=1
		lenG:=len(g[i])
		for j:=0;j<lenG;j++{
			maxLens[i]+=maxLens[g[i][j]]
		}
	}
	for i:=0;i<q;i++{
		var u,k int
		Fscan(in,&u,&k)
		if k>maxLens[u]{
			Fprintln(out,-1)
			continue
		}
		Fprintln(out,orders[pos[u]+k-1])
	}
}

package main

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

type officer struct {
	subs []int
	cnt  int
}

func main() {
	in := bufio.NewReadWriter(
		bufio.NewReader(os.Stdin),
		bufio.NewWriter(os.Stdout),
	)

	var n, q int
	fmt.Fscanf(in, "%d%d\n", &n, &q)

	off := make([]officer, n)
	for i := range off[1:] {
		var x int
		fmt.Fscanf(in, "%d", &x)
		x--
		off[x].subs = append(off[x].subs, i+1)
	}
	fmt.Fscanf(in, "\n")

	order := make(map[int]int, n)
	reverse := make(map[int]int, n)
	buildsubs(off, order, reverse, 0)

	for i := 0; i < q; i++ {
		var u, k int
		fmt.Fscanf(in, "%d%d\n", &u, &k)
		u--
		k--

		if off[u].cnt <= k {
			fmt.Fprintln(in, -1)
			continue
		}

		k += reverse[u]
		if n, ok := order[k]; ok {
			fmt.Fprintln(in, n+1)
		} else {
			fmt.Fprintln(in, -1)
		}
	}
	in.Flush()
}

func buildsubs(off []officer, order, reverse map[int]int, cur int) {
	reverse[cur] = len(order)
	order[len(order)] = cur

	off[cur].cnt = 1

	for _, v := range off[cur].subs {
		buildsubs(off, order, reverse, v)
		off[cur].cnt += off[v].cnt
	}
}

package main

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

const (
	MaxN = 200005
)

var n, q int
var tree [][]int
var traversal, startIndex, endIndex []int
var count int

func dfs(v int) {
	l := len(tree[v])
	for i := 0; i < l; i++ {
		count++
		traversal = append(traversal, tree[v][i])
		startIndex[tree[v][i]] = count
		dfs(tree[v][i])
	}
	endIndex[v] = count
}

func main() {
	bufReader := bufio.NewReader(os.Stdin)
	bufWriter := bufio.NewWriter(os.Stdout)
	defer func() { bufWriter.Flush() } ()

	fmt.Fscanf(bufReader, "%d %d\n", &n, &q)

	tree = make([][]int, n+1)
	traversal = make([]int, 0)
	startIndex = make([]int, n+1)
	endIndex = make([]int, n+1)

	for i := 2; i <= n; i++ {
		var sup int
		var c string
		if i == n {
			c = "\n"
		} else {
			c = " "
		}
		format := "%d" + c
		fmt.Fscanf(bufReader, format, &sup)
		tree[sup] = append(tree[sup], i)
	}

	traversal = append(traversal, 1)
	startIndex[1] = 0
	dfs(1)

	for i := 0; i < q; i++ {
		var tmp, index int
		fmt.Fscanf(bufReader, "%d %d\n", &tmp, &index)
		if index > endIndex[tmp] - startIndex[tmp] + 1 {
			fmt.Fprintf(bufWriter, "-1\n")
		} else {
			fmt.Fprintf(bufWriter, "%d\n", traversal[startIndex[tmp] + index - 1])
		}
	}
}

package main

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

const (
	MaxN = 200005
)

var n, q int
var tree [][]int
var traversal, startIndex, endIndex []int
var count int

func dfs(v int) {
	l := len(tree[v])
	for i := 0; i < l; i++ {
		count++
		traversal = append(traversal, tree[v][i])
		startIndex[tree[v][i]] = count
		dfs(tree[v][i])
	}
	endIndex[v] = count
}

func main() {
	bufReader := bufio.NewReader(os.Stdin)
	bufWriter := bufio.NewWriter(os.Stdout)
	defer func() { bufWriter.Flush() } ()

	fmt.Fscanf(bufReader, "%d %d\n", &n, &q)

	tree = make([][]int, n+1)
	traversal = make([]int, 0)
	startIndex = make([]int, n+1)
	endIndex = make([]int, n+1)

	for i := 2; i <= n; i++ {
		var sup int
		var c string
		if i == n {
			c = "\n"
		} else {
			c = " "
		}
		format := "%d" + c
		fmt.Fscanf(bufReader, format, &sup)
		tree[sup] = append(tree[sup], i)
	}

	traversal = append(traversal, 1)
	startIndex[1] = 0
	dfs(1)

	for i := 0; i < q; i++ {
		var tmp, index int
		fmt.Fscanf(bufReader, "%d %d\n", &tmp, &index)
		fmt.Fprintf(bufWriter, ">> %d %d\n", tmp, index)
		if index > endIndex[tmp] - startIndex[tmp] + 1 {
			fmt.Fprintf(bufWriter, "-1\n")
		} else {
			fmt.Fprintf(bufWriter, "%d\n", traversal[startIndex[tmp] + index - 1])
		}
	}
}

package main

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

const (
	MaxN = 200005
)

var n, q int
var tree [][]int
var traversal, startIndex, endIndex []int
var count int

func dfs(v int) {
	l := len(tree[v])
	for i := 0; i < l; i++ {
		count++
		traversal = append(traversal, tree[v][i])
		startIndex[tree[v][i]] = count
		dfs(tree[v][i])
	}
	endIndex[v] = count
}

func main() {
	bufReader := bufio.NewReader(os.Stdin)
	bufWriter := bufio.NewWriter(os.Stdout)
	defer func() { bufWriter.Flush() } ()

	fmt.Fscanf(bufReader, "%d %d ", &n, &q)

	tree = make([][]int, n+1)
	traversal = make([]int, 0)
	startIndex = make([]int, n+1)
	endIndex = make([]int, n+1)

	for i := 2; i <= n; i++ {
		var sup int
		fmt.Fscanf(bufReader, "%d ", &sup)
		tree[sup] = append(tree[sup], i)
	}

	traversal = append(traversal, 1)
	startIndex[1] = 0
	dfs(1)

	for i := 0; i < q; i++ {
		var tmp, index int
		fmt.Fscanf(bufReader, "%d %d\n", &tmp, &index)
		fmt.Fprintf(bufWriter, ">> %d %d\n", tmp, index)
		if index > endIndex[tmp] - startIndex[tmp] + 1 {
			fmt.Fprintf(bufWriter, "-1\n")
		} else {
			fmt.Fprintf(bufWriter, "%d\n", traversal[startIndex[tmp] + index - 1])
		}
	}
}


The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic.Vladimir wants to rename the files with tests so that their names are distinct integers starting from 1 without any gaps, namely, "1", "2", ..., "n', where n is the total number of tests.Some of the files contain tests from statements (examples), while others contain regular tests. It is possible that there are no examples, and it is possible that all tests are examples. Vladimir wants to rename the files so that the examples are the first several tests, all all the next files contain regular tests only.The only operation Vladimir can perform is the "move" command. Vladimir wants to write a script file, each of the lines in which is "move file_1 file_2", that means that the file "file_1" is to be renamed to "file_2". If there is a file "file_2" at the moment of this line being run, then this file is to be rewritten. After the line "move file_1 file_2" the file "file_1" doesn't exist, but there is a file "file_2" with content equal to the content of "file_1" before the "move" command.Help Vladimir to write the script file with the minimum possible number of lines so that after this script is run:  all examples are the first several tests having filenames "1", "2", ..., "e", where e is the total number of examples;  all other files contain regular tests with filenames "e + 1", "e + 2", ..., "n", where n is the total number of all tests.

The first line contains single integer n (1 ≤ n ≤ 105) — the number of files with tests. n lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the i-th file contains an example test, and "0" if it contains a regular test. Filenames of each file are strings of digits and small English letters with length from 1 to 6 characters. The filenames are guaranteed to be distinct.

In the first line print the minimum number of lines in Vladimir's script file. After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" — is a string of digits and small English letters with length from 1 to 6.

4
move 3 1
move 01 5
move 2extra 4
move 99 3

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

func readString() string {
	if !in.Scan() {
		panic(in.Err())
	}
	return in.Text()
}

type file struct {
	orig string
	ex   bool
}

func pop(m map[int]bool) int {
	var r int
	for r = range m {
		break
	}
	delete(m, r)
	return r
}

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

	n := readInt()
	parse := func(name string) (int, bool) {
		x, err := strconv.Atoi(name)
		if err != nil || strconv.Itoa(x) != name {
			return 0, false
		}
		if x < 1 || x > n {
			return 0, false
		}
		return x, true
	}
	nEx := 0
	taken := make([]int, n+1)
	files := make([]file, n)
	var someEx, someGr []string
	for i := range files {
		files[i].orig = readString()
		files[i].ex = readInt() == 1
		if files[i].ex {
			nEx++
		}
		if x, ok := parse(files[i].orig); ok {
			if files[i].ex {
				taken[x] = 1
			} else {
				taken[x] = 2
			}
		} else {
			if files[i].ex {
				someEx = append(someEx, files[i].orig)
			} else {
				someGr = append(someGr, files[i].orig)
			}
		}
	}

	exFree := make(map[int]bool)
	exBad := make(map[int]bool)
	for i := 1; i <= nEx; i++ {
		switch taken[i] {
		case 0:
			exFree[i] = true
		case 2:
			exBad[i] = true
		}
	}
	grFree := make(map[int]bool)
	grBad := make(map[int]bool)
	for i := nEx + 1; i <= n; i++ {
		switch taken[i] {
		case 0:
			grFree[i] = true
		case 1:
			grBad[i] = true
		}
	}

	if len(exFree) == 0 && len(exBad) == 0 && len(grFree) == 0 && len(grBad) == 0 {
		fmt.Println(0)
		return
	}

	var ans [][2]string
	if len(exFree) == 0 && len(grFree) == 0 {
		if len(exBad) > 0 {
			b := pop(exBad)
			ans = append(ans, [2]string{strconv.Itoa(b), "a"})
			someGr = append(someGr, "a")
			exFree[b] = true
		} else {
			b := pop(grBad)
			ans = append(ans, [2]string{strconv.Itoa(b), "a"})
			someEx = append(someEx, "a")
			grFree[b] = true
		}
	}

	for len(grBad) > 0 || len(exBad) > 0 {
		if len(exFree) > 0 && len(grBad) > 0 {
			f := pop(exFree)
			ex := pop(grBad)
			ans = append(ans, [2]string{strconv.Itoa(ex), strconv.Itoa(f)})
			grFree[ex] = true
		}
		if len(grFree) > 0 && len(exBad) > 0 {
			f := pop(grFree)
			gr := pop(exBad)
			ans = append(ans, [2]string{strconv.Itoa(gr), strconv.Itoa(f)})
			exFree[gr] = true
		}
	}
	for _, some := range someEx {
		ans = append(ans, [2]string{some, strconv.Itoa(pop(exFree))})
	}
	for _, some := range someGr {
		ans = append(ans, [2]string{some, strconv.Itoa(pop(grFree))})
	}

	fmt.Fprintln(out, len(ans))
	for _, a := range ans {
		fmt.Fprintln(out, "move", a[0], a[1])
	}
}


Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph.There are n vertices in the tree, each of them is painted black or white. Anton doesn't like multicolored trees, so he wants to change the tree such that all vertices have the same color (black or white).To change the colors Anton can use only operations of one type. We denote it as paint(v), where v is some vertex of the tree. This operation changes the color of all vertices u such that all vertices on the shortest path from v to u have the same color (including v and u). For example, consider the tree  and apply operation paint(3) to get the following:  Anton is interested in the minimum number of operation he needs to perform in order to make the colors of all vertices equal.

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of vertices in the tree. The second line contains n integers colori (0 ≤ colori ≤ 1) — colors of the vertices. colori = 0 means that the i-th vertex is initially painted white, while colori = 1 means it's initially painted black. Then follow n - 1 line, each of them contains a pair of integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — indices of vertices connected by the corresponding edge. It's guaranteed that all pairs (ui, vi) are distinct, i.e. there are no multiple edges.

Print one integer — the minimum number of operations Anton has to apply in order to make all vertices of the tree black or all vertices of the tree white.

NoteIn the first sample, the tree is the same as on the picture. If we first apply operation paint(3) and then apply paint(6), the tree will become completely black, so the answer is 2.In the second sample, the tree is already white, so there is no need to apply any operations and the answer is 0.

package main

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

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

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()

	var n int
	Scanf("%d\n", &n)

	col := make([]int, n)
	for i := 0; i < n; i++ {
		Scanf("%d", &col[i])
	}
	Scanf("\n")

	adj := make([][]int, n)
	for i := 0; i < n-1; i++ {
		var u, v int
		Scanf("%d %d\n", &u, &v)
		u--
		v--
		adj[u] = append(adj[u], v)
		adj[v] = append(adj[v], u)
	}

	// Compress tree.
	// Start with first node and expand a given component.
	comps := []int{0}
	visited := make([]bool, n)

	// Adjacency matrix for compressed
	adj2 := make([][]int, n)
	for len(comps) > 0 {
		// com is representative of this component.
		com := comps[0]
		comps = comps[1:]

		// Find out all nodes with the same color.
		toVisit := []int{com}
		for len(toVisit) > 0 {
			vis := toVisit[0]
			toVisit = toVisit[1:]
			visited[vis] = true

			for _, nex := range adj[vis] {
				if visited[nex] {
					// do not backtrack while doing DFS and do not backtrack from next component to this previous one.
					continue
				}
				if col[nex] == col[com] {
					// Visit next node of the same color.
					toVisit = append(toVisit, nex)
				} else {
					// Next node has a different color, so it's a different component.
					comps = append(comps, nex)
					adj2[com] = append(adj2[com], nex)
					adj2[nex] = append(adj2[nex], com)
				}
			}
		}
	}

	// Dprint("adjacency=%v", adj2)

	// Start with
	visited = make([]bool, n)

	f0, _ := findFar(adj2, 0, -1)
	_, dis := findFar(adj2, f0, -1)

	Printf("%d", (dis+1)/2)
}

// findFar finds vertex furthest from s and its distance. But not via prev.
func findFar(adj [][]int, s int, prev int) (int, int) {
	maxFar := s
	maxDist := 0
	for _, nex := range adj[s] {
		if nex == prev {
			continue
		}
		far, dist := findFar(adj, nex, s)
		dist++
		if dist > maxDist {
			maxFar = far
			maxDist = dist
		}
	}
	return maxFar, maxDist
}


Lee couldn't sleep lately, because he had nightmares. In one of his nightmares (which was about an unbalanced global round), he decided to fight back and propose a problem below (which you should solve) to balance the round, hopefully setting him free from the nightmares.A non-empty array $$$b_1, b_2, \ldots, b_m$$$ is called good, if there exist $$$m$$$ integer sequences which satisfy the following properties:  The $$$i$$$-th sequence consists of $$$b_i$$$ consecutive integers (for example if $$$b_i = 3$$$ then the $$$i$$$-th sequence can be $$$(-1, 0, 1)$$$ or $$$(-5, -4, -3)$$$ but not $$$(0, -1, 1)$$$ or $$$(1, 2, 3, 4)$$$).  Assuming the sum of integers in the $$$i$$$-th sequence is $$$sum_i$$$, we want $$$sum_1 + sum_2 + \ldots + sum_m$$$ to be equal to $$$0$$$. You are given an array $$$a_1, a_2, \ldots, a_n$$$. It has $$$2^n - 1$$$ nonempty subsequences. Find how many of them are good.As this number can be very large, output it modulo $$$10^9 + 7$$$.An array $$$c$$$ is a subsequence of an array $$$d$$$ if $$$c$$$ can be obtained from $$$d$$$ by deletion of several (possibly, zero or all) elements.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the size of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — elements of the array.

Print a single integer — the number of nonempty good subsequences of $$$a$$$, modulo $$$10^9 + 7$$$.

NoteFor the first test, two examples of good subsequences are $$$[2, 7]$$$ and $$$[2, 2, 4, 7]$$$:For $$$b = [2, 7]$$$ we can use $$$(-3, -4)$$$ as the first sequence and $$$(-2, -1, \ldots, 4)$$$ as the second. Note that subsequence $$$[2, 7]$$$ appears twice in $$$[2, 2, 4, 7]$$$, so we have to count it twice.  Green circles denote $$$(-3, -4)$$$ and orange squares denote $$$(-2, -1, \ldots, 4)$$$. For $$$b = [2, 2, 4, 7]$$$ the following sequences would satisfy the properties: $$$(-1, 0)$$$, $$$(-3, -2)$$$, $$$(0, 1, 2, 3)$$$ and $$$(-3, -2, \ldots, 3)$$$

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1610D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mod int64 = 1e9 + 7
	pow := func(x int64, n uint) (res int64) {
		res = 1
		for ; n > 0; n >>= 1 {
			if n&1 > 0 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return
	}

	cnt := [30]uint{}
	var n, v, c uint
	for Fscan(in, &n); n > 0; n-- {
		Fscan(in, &v)
		cnt[bits.TrailingZeros(v)]++
	}
	ans := int64(0)
	for i := 29; i > 0; i-- {
		if cnt[i] > 0 {
			ans += pow(2, c) * (pow(2, cnt[i]-1) - 1)
			c += cnt[i]
		}
	}
	ans += pow(2, c) * (pow(2, cnt[0]) - 1)
	Fprint(out, ans%mod)
}

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


Inna loves sleeping very much, so she needs n alarm clocks in total to wake up. Let's suppose that Inna's room is a 100 × 100 square with the lower left corner at point (0, 0) and with the upper right corner at point (100, 100). Then the alarm clocks are points with integer coordinates in this square.The morning has come. All n alarm clocks in Inna's room are ringing, so Inna wants to turn them off. For that Inna has come up with an amusing game:  First Inna chooses a type of segments that she will use throughout the game. The segments can be either vertical or horizontal.  Then Inna makes multiple moves. In a single move, Inna can paint a segment of any length on the plane, she chooses its type at the beginning of the game (either vertical or horizontal), then all alarm clocks that are on this segment switch off. The game ends when all the alarm clocks are switched off. Inna is very sleepy, so she wants to get through the alarm clocks as soon as possible. Help her, find the minimum number of moves in the game that she needs to turn off all the alarm clocks!

The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of the alarm clocks. The next n lines describe the clocks: the i-th line contains two integers xi, yi — the coordinates of the i-th alarm clock (0 ≤ xi, yi ≤ 100). Note that a single point in the room can contain any number of alarm clocks and the alarm clocks can lie on the sides of the square that represents the room.

In a single line print a single integer — the minimum number of segments Inna will have to draw if she acts optimally.

NoteIn the first sample, Inna first chooses type "vertical segments", and then she makes segments with ends at : (0, 0), (0, 2); and, for example, (1, 0), (1, 1). If she paints horizontal segments, she will need at least 3 segments.In the third sample it is important to note that Inna doesn't have the right to change the type of the segments during the game. That's why she will need 3 horizontal or 3 vertical segments to end the game.

package main

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

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

	var vertical, horizontal [101]bool
	var v, h int
	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0; i < n; i++ {
		var x, y int
		fmt.Fscanf(reader, "%d %d\n", &x, &y)
		horizontal[x] = true
		vertical[y] = true
	}
	for i := 0; i < 101; i++ {
		if vertical[i] {
			v++
		}
		if horizontal[i] {
			h++
		}
	}
	if v < h {
		fmt.Printf("%d", v)
	} else {
		fmt.Printf("%d", h)
	}

}

package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	"io"
	// "time"
	// "strings"
)

type Scanner struct {
	scanner *bufio.Scanner
}

func NewScanner(r io.Reader) *Scanner {
	scanner := bufio.NewScanner(r)
	scanner.Split(bufio.ScanWords)

	return &Scanner{
		scanner: scanner,
	}
}

func (s *Scanner) next() string {
	ok := s.scanner.Scan()
	if !ok {
		panic("Scan error")
	}
	return s.scanner.Text()
}

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

func main() {
	// defer func(start time.Time) {
	// 	fmt.Println(time.Since(start))
	// }(time.Now())

	// Method 1 slowest
	// reader := bufio.NewReader(os.Stdin)
	// var n int
	// fmt.Fscan(reader, &n)

	// Method 2 slowest
	// reader := bufio.NewReader(os.Stdin)
	// var n int
	// line, _ := reader.ReadString('\n')
	// fmt.Sscan(line, &n)

	// Method 3 fast
	// reader := bufio.NewReader(os.Stdin)
	// line, _ := reader.ReadString('\n')
	// n, _ := strconv.Atoi(line[:len(line)-1])
	// var token []string

	// Method 4 fastest
	// scanner := bufio.NewScanner(os.Stdin)
	// scanner.Split(bufio.ScanWords)
	// scanner.Scan()
	// n, _ := strconv.Atoi(scanner.Text())

	// Method 5 fastest
	scanner := NewScanner(os.Stdin)
	n := scanner.nextInt()

	X := make([]bool, 101)
	Y := make([]bool, 101)

	var a, b int
	var countX, countY int

	for i:=0; i<n; i++ {
		// Method 1
		// fmt.Fscan(reader, &a, &b)

		// Method 2
		// line, _ = reader.ReadString('\n')
		// fmt.Sscan(line, &a, &b)

		// Method 3
		// line, _ = reader.ReadString('\n')
		// token = strings.Fields(line)
		// a, _ = strconv.Atoi(token[0])
		// b, _ = strconv.Atoi(token[1])

		// Method 4
		// scanner.Scan()
		// a, _ = strconv.Atoi(scanner.Text())
		// scanner.Scan()
		// b, _ = strconv.Atoi(scanner.Text())

		// Method 5
		a, b = scanner.nextInt(), scanner.nextInt()

		if !X[a] {
			countX++
			X[a] = true
		}
		if !Y[b] {
			countY++
			Y[b] = true
		}
	}

	if countX < countY {
		fmt.Println(countX)
	} else {
		fmt.Println(countY)
	}
}

package main

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

func main() {
	var (
		n, x, y        int
		roomHorizontal [101] bool
		roomVertical [101] bool
	)

    scanner := bufio.NewScanner(os.Stdin)

    scanner.Scan()
    fmt.Sscanf(scanner.Text(), "%d", &n)

	cntHor := 0
	cntVer := 0

	for i := 0; i < n; i++ {
        scanner.Scan()
        fmt.Sscanf(scanner.Text(), "%d %d", &x, &y)

		ok := roomHorizontal[x]
		if !ok {
			roomHorizontal[x] = true
			cntHor++
		}

		ok = roomVertical[y]
		if !ok {
			roomVertical[y] = true
			cntVer++
		}
	}

	if cntHor > cntVer {
		fmt.Println(cntVer)
		return
	}

	fmt.Println(cntHor)
}

package main

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

func main() {
    var (
        n, x, y        int
        roomHorizontal  = make(map[int]bool)
        roomVertical = make(map[int]bool)
    )

    scanner := bufio.NewScanner(os.Stdin)

    scanner.Scan()
    fmt.Sscanf(scanner.Text(), "%d", &n)

    cntHor := 0
    cntVer := 0

    for i := 0; i < n; i++ {
        scanner.Scan()
        fmt.Sscanf(scanner.Text(), "%d %d", &x, &y)

        _, ok := roomHorizontal[x]
        if !ok {
            roomHorizontal[x] = true
            cntHor++
        }

        _, ok = roomVertical[y]
        if !ok {
            roomVertical[y] = true
            cntVer++
        }
    }

    if cntHor > cntVer {
        fmt.Println(cntVer)
        return
    }

    fmt.Println(cntHor)
}

package main

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

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

	var N int
	coordinatesMapX := make(map[int]bool)
	coordinatesMapY := make(map[int]bool)

	fmt.Fscanf(in, "%d\n", &N)

	for i := 0; i < N; i++ {
	    var num1, num2 int
		fmt.Fscanf(in, "%d %d\n", &num1, &num2)
		coordinatesMapX[num1] = true
		coordinatesMapY[num2] = true
	}

	if len(coordinatesMapX) < len(coordinatesMapY) {
		fmt.Println(len(coordinatesMapX))
	} else {
		fmt.Println(len(coordinatesMapY))
	}
}

package main

import "fmt"

func main() {
	var (
		n, x, y int
		roomHorizontal = make(map[int]bool)
		roomVertical = make(map[int]bool)
	)

	_, _ = fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		_, _ = fmt.Scanf("%d", &x)
		_, _ = fmt.Scanf("%d", &y)
		roomHorizontal[x] = true
		roomVertical[y] = true
	}

	lenHor := len(roomHorizontal)
	lenVer := len(roomVertical)

	fmt.Println(lenHor, lenVer)
	return

	if lenHor > lenVer {
		fmt.Println(lenVer)
		return
	}

	fmt.Println(lenHor)
}

package main

import "fmt"

func main() {
	var (
		n, x, y int
		roomHorizontal = make(map[int]bool)
		roomVertical = make(map[int]bool)
	)

	_, _ = fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		_, _ = fmt.Scanf("%d", &x)
		_, _ = fmt.Scanf("%d", &y)
		roomHorizontal[x] = true
		roomVertical[y] = true
	}

	lenHor := len(roomHorizontal)
	lenVer := len(roomVertical)

	fmt.Println(roomHorizontal, roomVertical)
	return

	if lenHor > lenVer {
		fmt.Println(lenVer)
		return
	}

	fmt.Println(lenHor)
}

package main

import "fmt"

func main() {
	var (
		n, x, y int
		roomHorizontal = make(map[int]int)
		roomVertical = make(map[int]int)
	)

	_, _ = fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		_, _ = fmt.Scanf("%d", &x)
		_, _ = fmt.Scanf("%d", &y)
		roomHorizontal[x]++
		roomVertical[y]++
	}

	lenHor := len(roomHorizontal)
	lenVer := len(roomVertical)

	if lenHor > lenVer {
		fmt.Println(lenVer)
		return
	}

	fmt.Println(lenHor)
}

package main

import (
	"fmt"
)

func main() {
	var (
		n, x, y        int
		roomHorizontal = make(map[int]bool)
		roomVertical   = make(map[int]bool)
	)

	_, _ = fmt.Scanf("%d", &n)

	cntHor := 0
	cntVer := 0

	for i := 0; i < n; i++ {
		if cntHor == 100 && cntVer == 100 {
			fmt.Println(100)
			return
		}

		_, _ = fmt.Scan(&x)
		_, _ = fmt.Scan(&y)

		_, ok := roomHorizontal[x]
		if !ok {
			roomHorizontal[x] = true
			cntHor++
		}

		_, ok = roomVertical[y]
		if !ok {
			roomVertical[y] = true
			cntVer++
		}
	}

	if cntHor > cntVer {
		fmt.Println(cntVer)
		return
	}

	fmt.Println(cntHor)
}

package main

import "fmt"

func main() {
	var (
		n, x, y int
		roomHorizontal = make(map[int]bool)
		roomVertical = make(map[int]bool)
	)

	_, _ = fmt.Scanf("%d", &n)

	fmt.Println(n)
	return

	for i := 0; i < n; i++ {
		_, _ = fmt.Scanf("%d", &x)
		_, _ = fmt.Scanf("%d", &y)
		roomHorizontal[x] = true
		roomVertical[y] = true
	}

	lenHor := len(roomHorizontal)
	lenVer := len(roomVertical)

	if lenHor > lenVer {
		fmt.Println(lenVer)
		return
	}

	fmt.Println(lenHor)
}

package main

import "fmt"

func main() {
	var (
		n int
		roomHorizontal = make(map[int]bool)
		roomVertical = make(map[int]bool)
	)

	_, _ = fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		var x, y int
		_, _ = fmt.Scanf("%d", &x)
		_, _ = fmt.Scanf("%d", &y)
		roomHorizontal[x] = true
		roomVertical[y] = true
	}

	lenHor := len(roomHorizontal)
	lenVer := len(roomVertical)

	if lenHor > lenVer {
		fmt.Println(lenVer)
		return
	}

	fmt.Println(lenHor)
}

package main

import "fmt"

func main() {
	var (
		n, x, y int
		roomHorizontal = make(map[int]bool)
		roomVertical = make(map[int]bool)
	)

	_, _ = fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		_, _ = fmt.Scanf("%d", &x)
		_, _ = fmt.Scanf("%d", &y)
		roomHorizontal[x] = true
		roomVertical[y] = true
	}

	lenHor := len(roomHorizontal)
	lenVer := len(roomVertical)

	if lenHor > lenVer {
		fmt.Println(lenVer)
		return
	}

	fmt.Println(lenHor)
}

package main

import "fmt"

func main() {
	var (
		n, x, y int
		roomHorizontal = make(map[int]int)
		roomVertical = make(map[int]int)
	)

	_, _ = fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		_, _ = fmt.Scanf("%d %d", &x, &y)
		roomHorizontal[x]++
		roomVertical[y]++
	}

	lenHor := len(roomHorizontal)
	lenVer := len(roomVertical)

	if lenHor > lenVer {
		fmt.Println(lenVer)
		return
	}

	fmt.Println(lenHor)
}

package main

import "fmt"

func main() {
	var N, num1, num2 int
	coordinates := make([][]int, 0)

	fmt.Scanf("%d\r", &N)

	if N > 10000 {
		fmt.Println("100")
		return
	}

	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d\r", &num1, &num2)
		coordinates = append(coordinates, []int{num1, num2})
	}
	fmt.Println(innaAndAlarmClock(coordinates))
}

func innaAndAlarmClock(coordinates [][]int) int {
	coordinatesMapX := make(map[int]int)
	coordinatesMapY := make(map[int]int)

	for _, element := range coordinates {
		coordinatesMapX[element[0]]++
		coordinatesMapY[element[1]]++
	}

	if len(coordinatesMapX) < len(coordinatesMapY) {
		return len(coordinatesMapX)
	}
	return len(coordinatesMapY)
}

package main

import "fmt"

func main() {
	var N, num1, num2 int
	coordinatesMapX := make(map[int]bool)
	coordinatesMapY := make(map[int]bool)

	fmt.Scanf("%d\r", &N)

	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d\r", &num1, &num2)
		coordinatesMapX[num1] = true
		coordinatesMapY[num2] = true
	}

	if len(coordinatesMapX) < len(coordinatesMapY) {
		fmt.Println(coordinatesMapX)
	} else {
		fmt.Println(coordinatesMapY)
	}
}

package main

import "fmt"

func main() {
	var N, num1, num2 int
	coordinates := make([][]int, 0)

	fmt.Scanf("%d\r", &N)

	if N > 10000 {
		fmt.Println("101")
		return
	}

	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d\r", &num1, &num2)
		coordinates = append(coordinates, []int{num1, num2})
	}
	fmt.Println(innaAndAlarmClock(coordinates))
}

func innaAndAlarmClock(coordinates [][]int) int {
	coordinatesMapX := make(map[int]int)
	coordinatesMapY := make(map[int]int)

	for _, element := range coordinates {
		coordinatesMapX[element[0]]++
		coordinatesMapY[element[1]]++
	}

	if len(coordinatesMapX) < len(coordinatesMapY) {
		return len(coordinatesMapX)
	}
	return len(coordinatesMapY)
}


Pak Chanek has a prime number$$$^\dagger$$$ $$$n$$$. Find a prime number $$$m$$$ such that $$$n + m$$$ is not prime.$$$^\dagger$$$ A prime number is a number with exactly $$$2$$$ factors. The first few prime numbers are $$$2,3,5,7,11,13,\ldots$$$. In particular, $$$1$$$ is not a prime number.

Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The following lines contain the description of each test case. The only line of each test case contains a prime number $$$n$$$ ($$$2 \leq n \leq 10^5$$$).

For each test case, output a line containing a prime number $$$m$$$ ($$$2 \leq m \leq 10^5$$$) such that $$$n + m$$$ is not prime. It can be proven that under the constraints of the problem, such $$$m$$$ always exists. If there are multiple solutions, you can output any of them.

NoteIn the first test case, $$$m = 2$$$, which is prime, and $$$n + m = 7 + 2 = 9$$$, which is not prime.In the second test case, $$$m = 7$$$, which is prime, and $$$n + m = 2 + 7 = 9$$$, which is not prime.In the third test case, $$$m = 47837$$$, which is prime, and $$$n + m = 75619 + 47837 = 123456$$$, which is not prime.

package main

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

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

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

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

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

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

/**
Run solve the problem CF1740A
Date: 7/11/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1740/A
Problem: CF1740A
**/
func (in *CF1740A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		in.NextInt()
		fmt.Println(7)
	}
}

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

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)
	for ; t != 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		fmt.Fprintln(out, n)
	}
	out.Flush()
}

package main

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

func main() {
	var tc int

	r_ := bufio.NewReader(os.Stdin)
	w_ := bufio.NewWriter(os.Stdout)

	defer w_.Flush()
	fmt.Fscan(r_, &tc)

	for t := 1; t <= tc; t++ {

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

		ans := -1
		for i := 1; i < 1e5; i += 2 {
			if isPrime(i) == true {
				s := i + n

				if isPrime(s) == false {
					ans = i
					break
				}

			}
		}

		fmt.Fprintln(w_, ans)
	}
}
func isPrime(a int) bool {
	if a <= 1 {
		return false
	}
	if a == 2 || a == 3 {
		return true
	}

	if a%2 == 0 || a%3 == 0 {
		return false
	}

	for i := 5; i < int(math.Sqrt(float64(a))); i += 6 {
		if a%i == 0 || a%(i+2) == 0 {
			return false
		}
	}
	return true
}

package main

import ."fmt"

var n int

func main(){
    Scan(&n)
    for i := 0; i < n; i ++{
        var a int
        Scan(&a)
        if a == 2{
            Println(2)
        }else{
            Println(3)
        }
    }
}

package main
import "fmt"

func main(){
    var T int
    fmt.Scan(&T)
    for {
        var n int
        fmt.Scan(&n)
        fmt.Println(n)
        T = T - 1
        if T == 0{
            break
        }
    }
}

package main

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

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

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

package main

import "fmt"

const N int = 100010

var isPrime [N]bool

func main() {
	for i := 0; i < N; i++ {
		isPrime[i] = true
	}
	for i := 2; i < N; i++ {
		if isPrime[i] {
			for j := i * i; j < N; j += i {
				isPrime[j] = false
			}
		}
	}
	var t, n int
	fmt.Scan(&t)
	for t > 0 {
		t--
		fmt.Scan(&n)
		for i := 2; i < N; i++ {
			if isPrime[i] && !isPrime[i+n] {
				fmt.Println(i)
				break
			}
		}
	}
}

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		n := readInt(reader)

		fmt.Fprintln(writer, n)

		t--
	}

	writer.Flush()
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

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

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

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

func gcd(x, y int64) int64 {
	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func lcm(x int64, y int64) int64 {
	return x * y / gcd(x, y)
}

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	fmt.Fprintln(out, n)
}

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

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

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

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

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

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

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

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

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

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

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

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

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

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

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

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

var exists = struct{}{}

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

func reverseStr(s string) string {
	r := []byte(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

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

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

type Ordered interface {
	Integer | Float | ~string
}

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

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

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

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

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

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

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

const (
	DEBUG = false
)

func debug(a ...interface{}) {
	if !DEBUG {
		return
	}
	for _, e := range a {
		printf("%v ", e)
	}
	printf("\n")
	writer.Flush()
}

func debugCondn(condn bool, a ...interface{}) {
	if !DEBUG || !condn {
		return
	}
	for _, e := range a {
		printf("%v ", e)
	}
	printf("\n")
	writer.Flush()
}

func assert(condn bool) {
	if !condn {
		panic("assertion error")
	}
}

func solve(tt int) {
	var n int
	scanf("%d\n", &n)
	printf("%d\n", n)
}

func main() {
	defer writer.Flush()

	var T int
	scanf("%d\n", &T)
	for tt:=1; tt<=T; tt++ {
		solve(tt)
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1740A
Date: 7/11/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1740/A
Problem: CF1740A
**/
func (in *CF1740A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		in.NextInt()
		fmt.Println(2)
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1740A
Date: 7/11/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1740/A
Problem: CF1740A
**/
func (in *CF1740A) Run() {
	for t := in.NextInt(); t > 0; t-- {
      in.NextInt()
		fmt.Println(1)
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1740A
Date: 7/11/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1740/A
Problem: CF1740A
**/
func (in *CF1740A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		fmt.Println(n + n)
	}
}

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

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

package main

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

func main() {
	var tc int

	r_ := bufio.NewReader(os.Stdin)
	w_ := bufio.NewWriter(os.Stdout)

	defer w_.Flush()
	fmt.Fscan(r_, &tc)

	for t := 1; t <= tc; t++ {

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

		ans := -1
		for i := 1; i < 1e5; i += 2 {
			if isPrime(i) == true {
				m := i + n

				if isPrime(m) == false {
					ans = m
					break
				}

			}
		}

		fmt.Fprintln(w_, ans)
	}
}
func isPrime(a int) bool {
	if a <= 1 {
		return false
	}
	if a == 2 || a == 3 {
		return true
	}

	if a%2 == 0 || a%3 == 0 {
		return false
	}

	for i := 5; i < int(math.Sqrt(float64(a))); i += 6 {
		if a%i == 0 || a%(i+2) == 0 {
			return false
		}
	}
	return true
}