Michael is accused of violating the social distancing rules and creating a risk of spreading coronavirus. He is now sent to prison. Luckily, Michael knows exactly what the prison looks like from the inside, especially since it's very simple.The prison can be represented as a rectangle $$$a\times b$$$ which is divided into $$$ab$$$ cells, each representing a prison cell, common sides being the walls between cells, and sides on the perimeter being the walls leading to freedom. Before sentencing, Michael can ask his friends among the prison employees to make (very well hidden) holes in some of the walls (including walls between cells and the outermost walls). Michael wants to be able to get out of the prison after this, no matter which cell he is placed in. However, he also wants to break as few walls as possible.Your task is to find out the smallest number of walls to be broken so that there is a path to the outside from every cell after this.

The first line contains a single integer $$$t$$$ ($$$1\leq t\leq 100$$$) — the number of test cases. Each of the following $$$t$$$ lines contains two integers $$$a$$$ and $$$b$$$ ($$$1\leq a, b\leq 100$$$), representing a corresponding test case.

For each test case print the single integer on a separate line — the answer to the problem.

NoteSome possible escape plans for the example test cases are shown below. Broken walls are shown in gray, not broken walls are shown in black.

package main

import "fmt"

func main() {
	var T uint8
	fmt.Scan(&T)
	for T > 0 {
		var A, B uint16
		fmt.Scan(&A, &B)
		fmt.Printf("%d\n", A*B)
		T--
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 1; i <= t; i++ {
		var a, b int
		fmt.Scan(&a)
		fmt.Scan(&b)
		fmt.Println(a * b)
	}
}

package main

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {

		var n, m int

		fmt.Fscan(input, &n)
		fmt.Fscan(input, &m)

		fmt.Println(m * n)

		// STRING := make([]byte, 0)
		// fmt.Fscan(input, &STRING)

		// ARRAY := make([]int, n)
		// for i := 0; i < n; i++ {
		// 	fmt.Fscan(input, &ARRAY[i])
		// }

	}

}

package main

import(
  "fmt"
)

func main(){
	var t int
	fmt.Scan(&t)
	for tt:=1;tt<=t;tt++ {
		solve()
	}
}

func solve(){
	var a,b int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Println(a*b)
}

package main

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

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

	var t, a, b int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &a, &b)

		fmt.Println(a * b)
	}
}

package main

import "fmt"

func main() {
	var T uint8
	fmt.Scan(&T)
	for T > 0 {
		var A, B uint8
		fmt.Scan(&A, &B)
		fmt.Printf("%d\n", A*B)
		T--
	}
}


Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a large queue of n Berland residents lined up in front of the ice cream stall. We know that each of them has a certain amount of berland dollars with them. The residents of Berland are nice people, so each person agrees to swap places with the person right behind him for just 1 dollar. More formally, if person a stands just behind person b, then person a can pay person b 1 dollar, then a and b get swapped. Of course, if person a has zero dollars, he can not swap places with person b.Residents of Berland are strange people. In particular, they get upset when there is someone with a strictly smaller sum of money in the line in front of them.Can you help the residents of Berland form such order in the line so that they were all happy? A happy resident is the one who stands first in the line or the one in front of who another resident stands with not less number of dollars. Note that the people of Berland are people of honor and they agree to swap places only in the manner described above.

The first line contains integer n (1 ≤ n ≤ 200 000) — the number of residents who stand in the line. The second line contains n space-separated integers ai (0 ≤ ai ≤ 109), where ai is the number of Berland dollars of a man standing on the i-th position in the line. The positions are numbered starting from the end of the line.

If it is impossible to make all the residents happy, print ":(" without the quotes. Otherwise, print in the single line n space-separated integers, the i-th of them must be equal to the number of money of the person on position i in the new line. If there are multiple answers, print any of them.

NoteIn the first sample two residents should swap places, after that the first resident has 10 dollars and he is at the head of the line and the second resident will have 9 coins and he will be at the end of the line. In the second sample it is impossible to achieve the desired result.In the third sample the first person can swap with the second one, then they will have the following numbers of dollars: 4 11 3, then the second person (in the new line) swaps with the third one, and the resulting numbers of dollars will equal to: 4 4 10. In this line everybody will be happy.

package main

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

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

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

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

    b := make([]int, n)
    for i := 0; i < n; i++ {
        b[i] = a[i] + i
    }

    sort.Ints(b)
    for i := 0; i + 1 < n; i++ {
        if b[i] == b[i + 1] {
            fmt.Println(":(")
            return
        }
    }

    out := bufio.NewWriter(os.Stdout)
    for i := 0; i < n; i++ {
        fmt.Fprintf(out, "%d", b[i] - i)
        if i + 1 < n {
            fmt.Fprintf(out, "%c", ' ')
        } else {
            fmt.Fprintln(out)
        }
    }
    out.Flush()
}


Luke likes to eat. There are $$$n$$$ piles of food aligned in a straight line in front of him. The $$$i$$$-th pile contains $$$a_i$$$ units of food. Luke will walk from the $$$1$$$-st pile towards the $$$n$$$-th pile, and he wants to eat every pile of food without walking back. When Luke reaches the $$$i$$$-th pile, he can eat that pile if and only if $$$|v - a_i| \leq x$$$, where $$$x$$$ is a fixed integer, and $$$v$$$ is Luke's food affinity.Before Luke starts to walk, he can set $$$v$$$ to any integer. Also, for each $$$i$$$ ($$$1 \leq i \leq n$$$), Luke can change his food affinity to any integer before he eats the $$$i$$$-th pile.Find the minimum number of changes needed to eat every pile of food.Note that the initial choice for $$$v$$$ is not considered as a change.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of test cases follows. For each test case, the first line contains two integers, $$$n, x$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$, $$$1 \leq x \leq 10^9$$$) — the number of piles, and the maximum difference between the size of a pile and Luke's food affinity, such that Luke can eat the pile. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots , a_n$$$ ($$$1 \leq a_i \leq 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output an integer on a separate line, which is the minimum number of changes needed.

NoteIn the first test case, Luke can set $$$v$$$ to $$$5$$$ before he starts to walk. And he can walk straight to eat every piles of food without changing $$$v$$$.In the second test case, Luke can set $$$v$$$ to $$$3$$$ before he starts to walk. And he could change $$$v$$$ to $$$10$$$ before he eats the second pile. After that, he can walk straight to eat remaining food without changing $$$v$$$.In the fourth test case, Luke can set $$$v$$$ to $$$3$$$ before he starts to walk. And he could change $$$v$$$ to $$$8$$$ before he eats the sixth pile. After that, he can walk straight to eat remaining food without changing $$$v$$$.In the fifth test case, Luke can set $$$v$$$ to $$$4$$$ before he starts to walk. And he could change $$$v$$$ to $$$6$$$ before he eats the fourth pile. Then he could change $$$v$$$ to $$$12$$$ before he eats the seventh pile. After that, he can walk straight to eat remaining food without changing $$$v$$$.

package main

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

const cf = true

func solve() {
	var n, x int
	fmt.Fscan(in, &n, &x)
	var num, mx, mn int64
	mx, mn = -1, 10000000000
	ans := 0
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &num)
		mx = max(mx, num)
		mn = min(mn, num)
		if mx-mn > int64(x*2) {
			ans++
			mx = num
			mn = num
		}
	}
	fmt.Fprintln(out, ans)
}

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

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 := []rune(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"
	"strconv"
	"strings"
)

func main() {
	var n, x, a, l, r int
	f := bufio.NewReader(os.Stdin)
	s, _ := f.ReadString('\n')
	s = strings.ReplaceAll(s, "\n", "")
	s = strings.ReplaceAll(s, "\r", "")
	t, _ := strconv.ParseInt(s, 10, 32)
	for i := 0; i < int(t); i++ {
		res := 0
		s, _ = f.ReadString('\n')
		s = strings.ReplaceAll(s, "\n", "")
		s = strings.ReplaceAll(s, "\r", "")
		_, _ = fmt.Sscanf(s, "%d %d", &n, &x)
		s, _ = f.ReadString('\n')
		s = strings.ReplaceAll(s, "\r", "")
		s = strings.ReplaceAll(s, "\n", "")
		as := strings.SplitN(s, " ", n)
		if len(as) != n {
			fmt.Println(len(as), n)
			panic("kek")
		}
		for j := 0; j < n; j++ {
			a1, _ := strconv.ParseInt(as[j], 10, 64)
			a = int(a1)
			if j == 0 {
				l = a
				r = a
			} else {
				if a >= l && a <= r {
					continue
				} else if a < l {
					if r-a <= x*2 {
						l = a
						continue
					} else {
						res++
						l = a
						r = a
					}
				} else if a > r {
					if a-l <= x*2 {
						r = a
						continue
					} else {
						res++
						l = a
						r = a
					}
				}
			}
		}
		fmt.Println(res)
	}
}

package main

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

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

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

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 int
		var x int64
		fmt.Fscan(in, &n, &x)

		aa := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
		}

		var tot int
		l, r := aa[0]-x, aa[0]+x
		for i := 1; i < n; i++ {
			if aa[i]-x > r || aa[i]+x < l {
				l, r = aa[i]-x, aa[i]+x
				tot++
			}
			l = max(l, aa[i]-x)
			r = min(r, aa[i]+x)
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, x := readTwoNums(reader)
		A := readNNums(reader, n)
		res := solve(A, x)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' || s[i] == '\r' {
			return s[:i]
		}
	}
	return s
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

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

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

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

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

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

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

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

	return i
}

func solve(A []int, x int) int {
	n := len(A)

	var res int

	lo := 0
	hi := 1 << 30
	for i := 0; i < n; i++ {
		// hi - A[i] <= x
		// A[i] - lo <= x
		a := A[i] - x
		b := A[i] + x
		lo = max(lo, a)
		hi = min(hi, b)
		if lo <= hi {
			continue
		}
		res++
		lo = a
		hi = b
	}

	return res
}

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

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

package main

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

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

func CF1704B(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n, x int64
		fmt.Fscan(r, &n, &x)
		var val, ans int64
		maxV, minV := int64(math.MinInt64), int64(math.MaxInt64)
		for i := int64(0); i < n; i++ {
			fmt.Fscan(r, &val)
			maxV = max(maxV, val)
			minV = min(minV, val)
			if maxV-minV > 2*x {
				ans++
				maxV = val
				minV = val
			}
		}
		fmt.Fprintln(w, ans)
	}
}

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

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

package main

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

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

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

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

func do(n, x int, a []int) int {
	l := math.MinInt
	r := math.MinInt
	ans := -1
	for _, v := range a {
		c := v - x
		d := v + x
		if r < c || l > d {
			ans++
			l, r = c, d
			continue
		}
		if l < c {
			l = c
		}
		if r > d {
			r = d
		}
	}
	return ans
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	cases := readInt(input)
	for asdf := 0; asdf < cases; asdf++ {
		tmp := readArrInt(input)
		arr := readArrInt(input)
		fmt.Println(solve(tmp[0], tmp[1], arr))
	}
}

func solve(n int, jump int, arr []int) int {
	// fmt.Println(n, jump, arr)
	result := 0
	bottom := arr[0]
	top := arr[0]
	for i := 1; i < n; i++ {
		bottom = min(bottom, arr[i])
		top = max(top, arr[i])
		if top-bottom > jump*2 {
			result++
			bottom = arr[i]
			top = arr[i]
		}
	}
	return result
}

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

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

func 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.Atoi(nStr)
	return int64(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 readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

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

func solve() {
	n := get()
	x := L(get())
	a := geta(n)

	count := 0
	l := a[0]
	r := a[0]
	for _, v := range a[1:] {
		l = min(l, v)
		r = max(r, v)
		if L(r-l) > 2*x {
			l, r = v, v
			count++
		}
	}
	putln(count)
}

const (
	once       = false
	maxBufSize = 0 //10_000_000
	YES        = "YES"
	NO         = "NO"
)

var (
	splitFunc = bufio.ScanWords //bufio.SplitFunc(nil)
)

func main() {
	in = bufio.NewScanner(bufio.NewReader(os.Stdin))
	if splitFunc != nil {
		in.Split(splitFunc)
	}
	if maxBufSize > 0 {
		in.Buffer(make([]byte, maxBufSize), maxBufSize)
	}

	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	if once {
		solve()
		return
	}

	for t := get(); t > 0; t-- {
		solve()
	}
}

var (
	in  *bufio.Scanner
	out *bufio.Writer
)

func get() int {
	x, _ := strconv.Atoi(gets())
	return x
}

func geta(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get()
	}
	return a
}

func geta1(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get() - 1
	}
	return a
}

func get64() int64 {
	x, _ := strconv.ParseInt(gets(), 10, 64)
	return x
}

func get64a(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64()
	}
	return a
}

func get64a1(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64() - 1
	}
	return a
}

func getf() float64 {
	x, _ := strconv.ParseFloat(gets(), 64)
	return x
}

func getfa(n int) []float64 {
	a := make([]float64, n)
	for i := range a {
		a[i] = getf()
	}
	return a
}

func gets() string {
	scan()
	return in.Text()
}

func scanN(n int) {
	for n > 0 {
		scan()
		n--
	}
}

func scan() {
	in.Scan()
}

func putc(c rune) {
	out.WriteRune(c)
}

func line() {
	putc('\n')
}

func space() {
	putc(' ')
}

func put(x int) {
	out.WriteString(strconv.Itoa(x))
}

func putln(i int) {
	put(i)
	line()
}

func puta(a []int) {
	for _, v := range a {
		put(v)
		space()
	}
	line()
}

func put64(x int64) {
	out.WriteString(strconv.FormatInt(x, 10))
}

func put64ln(x int64) {
	put64(x)
	line()
}

func put64a(a []int64) {
	for _, v := range a {
		put64(v)
		space()
	}
	line()
}

func puts(s string) {
	out.WriteString(s)
}

func putsln(s string) {
	puts(s)
	line()
}

func yn(y bool) {
	if y {
		yes()
		return
	}
	no()
}

func yes() {
	puts(YES)
	line()
}

func no() {
	puts(NO)
	line()
}

func putf(x float64) {
	out.WriteString(strconv.FormatFloat(x, 'f', -1, 64))
}

func putfln(x float64) {
	putf(x)
	line()
}

func putfa(a []float64) {
	for _, v := range a {
		putf(v)
		space()
	}
	line()
}

type IntTp interface {
	int | int64
}

type Tp interface {
	IntTp | float64
}

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

func fabs(x float64) float64 {
	return math.Abs(x)
}

func max1[T Tp](x T, y T) T {
	if x > y {
		return x
	}
	return y
}

func max[T Tp](xs ...T) T {
	r := xs[0]
	for _, x := range xs[1:] {
		r = max1(r, x)
	}
	return r
}

func maxa[T Tp](a []T) (i int, val T) {
	i, val = 0, a[0]
	for j := 1; j < len(a); j++ {
		if a[j] <= val {
			continue
		}
		i = j
		val = a[j]
	}
	return
}

func min1[T Tp](x T, y T) T {
	if x < y {
		return x
	}
	return y
}

func min[T Tp](xs ...T) T {
	r := xs[0]
	for _, x := range xs[1:] {
		r = min1(r, x)
	}
	return r
}

func mina[T Tp](a []T) (i int, val T) {
	i, val = 0, a[0]
	for j := 1; j < len(a); j++ {
		if a[j] >= val {
			continue
		}
		i = j
		val = a[j]
	}
	return
}

func L(i int) int64 {
	return int64(i)
}

func F(i int) float64 {
	return float64(i)
}

func ints(n int, val int) (a []int) {
	a = make([]int, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

func int64s(n int, val int64) (a []int64) {
	a = make([]int64, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

func floats(n int, val float64) (a []float64) {
	a = make([]float64, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

const heapBase = 4

func children(i int) (int, int) {
	start := heapBase * i
	return start + 1, start + (1 + heapBase)
}

func parent(i int) int {
	return (i - 1) / heapBase
}

package main

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

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

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var niter int
	fmt.Fscan(scanner, &niter)
	for iiter := 0; iiter < niter; iiter++ {
		var n int
		var x int
		fmt.Fscan(scanner, &n, &x)
		res := 0
		vmin := 0
		vmax := 1000000001
		for i := 0; i < n; i++ {
			var elem int
			fmt.Fscan(scanner, &elem)
			nvmin := elem - x
			nvmax := elem + x
			potmin := max(vmin, nvmin)
			potmax := min(vmax, nvmax)
			if potmin <= potmax {
				vmin = potmin
				vmax = potmax
			} else {
				res++
				vmin = elem - x
				vmax = elem + x
			}
		}
		fmt.Fprintln(writer, res)
	}
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var n, x int
	fmt.Fscan(rr, &n, &x)
	nums := make([]int, n)
	for i:=0;i<len(nums);i++ {
		fmt.Fscan(rr, &nums[i])
	}
	ans := 0
	l, r := nums[0], nums[0]
	for i:=1;i<n;i++ {
		l = min(l, nums[i])
		r = max(r, nums[i])
		if r - l > 2 * x {
			ans++
			l, r = nums[i], nums[i]
		}
	}
	fmt.Fprintln(ww, ans)
}

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

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

package main

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

const cf = true

func solve() {
	var n, x int
	fmt.Fscan(in, &n, &x)
	var num int
	mx, mn := -1, int(1e8)
	ans := 0
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &num)
		mx = max(mx, num)
		mn = min(mn, num)
		if mx-mn > x*2 {
			ans++
			mx = num
			mn = num
		}
	}
	fmt.Fprintln(out, ans)
}

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

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 := []rune(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 (
	"fmt"
)

func main() {
	var t, n, x, a, l, r int
	_, _ = fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		res := 0
		_, _ = fmt.Scanf("%d %d", &n, &x)
		for j := 0; j < n; j++ {
			_, _ = fmt.Scanf("%d", &a)
			if j == 0 {
				l = a
				r = a
			} else {
				if a >= l && a <= r {
					continue
				} else if a < l {
					if r-a <= x*2 {
						l = a
						continue
					} else {
						res++
						l = a
						r = a
					}
				} else if a > r {
					if a-l <= x*2 {
						r = a
						continue
					} else {
						res++
						l = a
						r = a
					}
				}
			}
		}
		fmt.Println(res)
	}
}

package main

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

func abs(n int64) int64 {
	if n < 0 {
		return n * -1
	}
	return n
}
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 int
		var x int64
		fmt.Fscan(in, &n, &x)

		aa := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
		}

		l, r := aa[0]-x, aa[0]+x
		var tot int
		for i := 1; i < n; i++ {
			if abs(aa[i]-l) > x && abs(aa[i]-r) > x {
				l, r = aa[i]-x, aa[i]+x
				tot++
			}
			// fmt.Println(l, r)
		}
		fmt.Fprintln(out, tot)
	}
}


Alexandra has an even-length array $$$a$$$, consisting of $$$0$$$s and $$$1$$$s. The elements of the array are enumerated from $$$1$$$ to $$$n$$$. She wants to remove at most $$$\frac{n}{2}$$$ elements (where $$$n$$$ — length of array) in the way that alternating sum of the array will be equal $$$0$$$ (i.e. $$$a_1 - a_2 + a_3 - a_4 + \dotsc = 0$$$). In other words, Alexandra wants sum of all elements at the odd positions and sum of all elements at the even positions to become equal. The elements that you remove don't have to be consecutive.For example, if she has $$$a = [1, 0, 1, 0, 0, 0]$$$ and she removes $$$2$$$nd and $$$4$$$th elements, $$$a$$$ will become equal $$$[1, 1, 0, 0]$$$ and its alternating sum is $$$1 - 1 + 0 - 0 = 0$$$.Help her!

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^3$$$, $$$n$$$ is even)  — length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 1$$$)  — elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^3$$$.

For each test case, firstly, print $$$k$$$ ($$$\frac{n}{2} \leq k \leq n$$$) — number of elements that will remain after removing in the order they appear in $$$a$$$. Then, print this $$$k$$$ numbers. Note that you should print the numbers themselves, not their indices. We can show that an answer always exists. If there are several answers, you can output any of them.

NoteIn the first and second cases, alternating sum of the array, obviously, equals $$$0$$$.In the third case, alternating sum of the array equals $$$1 - 1 = 0$$$.In the fourth case, alternating sum already equals $$$1 - 1 + 0 - 0 = 0$$$, so we don't have to remove anything.

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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

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

func Abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func Gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return Gcd(b, a%b)
}

const mod = 1000000007

func Add(a, b int64) int64 {
	return (a + b) % mod
}

func Mult(a, b int64) int64 {
	return (a * b) % mod
}

func Sub(a, b int64) int64 {
	return (a - b + mod) % mod
}

func solve() {
	n := nextInt()

	a, b := 0, 0
	arr := make([]int, n)
	for i := range arr {
		arr[i] = nextInt()
		if arr[i] == 0 {
			a++
		} else {
			b++
		}
	}

	if a >= b {
		printf("%d\n", a)
		for i := 0; i < a; i++ {
			printf("0 ")
		}
	} else {
		if b%2 == 1 {
			b--
		}
		printf("%d\n", b)
		for i := 0; i < b; i++ {
			printf("1 ")
		}
	}
	printf("\n")
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		name := "foreign"
		file1, err := os.Open(name + ".in")
		if err != nil {
			log.Fatal(err)
		}
		file2, err := os.Create(name + ".out")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file1, 8192)
		out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()
	// start := time.Now()

	for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
		// 	printf("Case #%d:\n", i)
		solve()
	}

	// printf("%v\n", time.Now().Sub(start))
}

package main

import (
	"fmt"
)

func main()  {
	//fileInput, _ := os.Open("input.txt")
	//os.Stdin = fileInput

	//fileOutput, _ := os.Create("output.txt")
	//os.Stdout = fileOutput

	var n, t, k int
	a := make([]int, 1003)
	res := make([]int, 1003)
	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		for j := 0; j < n ; j++ {
			fmt.Scan(&a[j])
		}
		k = 0
		if n == 2 {
			if a[0] == a[1] {
				k = 2
				res = a
			} else {
				k = 1
				res[0] = 0
			}
		}
		for j := 0; j < n - 2; {
			if a[j] != a[j+1] {
				if a[j] == a[j+2] {
					res[k] = a[j]
					res[k+1] = a[j+2]
					k += 2
					j += 3
				} else {
					res[k] = a[j+1]
					res[k+1] = a[j+2]
					k += 2
					j += 3
				}
			} else {
				res[k] = a[j]
				res[k+1] = a[j+1]
				k += 2
				j += 2
			}
		}
		fmt.Println(k)
		for j := 0; j < k; j++ {
			fmt.Printf("%d ", res[j])
		}
		fmt.Println("")
	}
}

package main

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

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	for t := io.NextInt(); t > 0; t-- {
		n := io.NextInt()
		a := io.NextInts(n)
		var o, z []int
		for _, x := range a {
			if x == 0 {
				z = append(z, x)
			} else {
				o = append(o, x)
			}
		}
		ans := z
		if len(o) > len(z) {
			ans = o
			if len(ans)%2 == 1 {
				ans = ans[:len(ans)-1]
			}
		}
		io.Println(len(ans))
		io.PrintlnInts(ans...)
	}
}

type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		zeroCount := 0
		oneCount := 0
		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
			if a[j] == 1 {
				oneCount++
			} else {
				zeroCount++
			}
		}
		if oneCount <= zeroCount {
			fmt.Println(zeroCount)
			for j := 0; j < n; j++ {
				if a[j] == 0 {
					fmt.Print(a[j], " ")
				}
			}
		} else {
			ignoreFirst := false
			if oneCount%2 != 0 {
				oneCount--
				ignoreFirst = true
			}
			fmt.Println(oneCount)
			for j := 0; j < n; j++ {
				if a[j] == 1 {
					if ignoreFirst {
						ignoreFirst = false
						continue
					}
					fmt.Print(a[j], " ")
				}
			}
		}
		fmt.Println()
	}
}

// Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools

package main

import (
  "fmt"
)

func main() {
  var tests int
  _, _ = fmt.Scanf("%d\n", &tests)
  for ; tests > 0; tests-- {
    var n int
    _, _ = fmt.Scanf("%d\n", &n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
      if i < n-1 {
        _, _ = fmt.Scanf("%d", &a[i])
      } else {
        _, _ = fmt.Scanf("%d\n", &a[i])
      }
    }

    res := make([]int, 0)
    for i := 0; i < n; i += 2 {
      if a[i]+a[i+1] == 0 {
        res = append(res, 0, 0)
      } else if a[i]+a[i+1] == 1 {
        res = append(res, 0)
      } else {
        res = append(res, 1, 1)
      }
    }
    fmt.Println(len(res))
    for i, d := range res {
      fmt.Printf("%d", d)
      if i < len(res)-1 {
        fmt.Print(" ")
      }
    }
    fmt.Println()
  }
}

package main

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

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

	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		c := [2]int{}
		for ; n > 0; n-- {
			Fscan(in, &v)
			c[v]++
		}
		if c[0] >= c[1] {
			Fprintln(out, c[0])
			Fprintln(out, strings.Repeat("0 ", c[0]))
		} else {
			c[1] &^= 1
			Fprintln(out, c[1])
			Fprintln(out, strings.Repeat("1 ", c[1]))
		}
	}
}

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

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t, n, i int
	fmt.Scan(&t)
	for t != 0 {
		fmt.Scan(&n)
		var x int
		var count int

		for i = 0; i < n; i++ {
			fmt.Scan(&x)
			if x == 1 {
				count++
			}
		}

		if count <= n/2 {
			fmt.Println(n - count)
			fmt.Println(strings.Repeat("0 ", n-count))
		} else {
			fmt.Println(count - count%2)
			fmt.Println(strings.Repeat("1 ", count-count%2))
		}
		t--
	}
}

package main

import (
	"fmt"
)

func main()  {
	//fileInput, _ := os.Open("input.txt")
	//os.Stdin = fileInput

	//fileOutput, _ := os.Create("output.txt")
	//os.Stdout = fileOutput

	var n, t, k int
	a := make([]int, 1003)
	res := make([]int, 1003)
	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		for j := 0; j < n ; j++ {
			fmt.Scan(&a[j])
		}
		k = 0
		if n == 2 {
			if a[0] == a[1] {
				k = 2
				res = a
			} else {
				k = 1
				res[0] = 0
			}
		}
		for j := 0; j < n - 2; {
			if a[j] != a[j+1] {
				if a[j] == a[j+2] {
					res[k] = a[j]
					res[k+1] = a[j+1]
					k += 2
					j += 3
				} else {
					res[k] = a[j+1]
					res[k+1] = a[j+2]
					k += 2
					j += 3
				}
			} else {
				res[k] = a[j]
				res[k+1] = a[j+1]
				k += 2
				j += 2
			}
		}
		fmt.Println(k)
		for j := 0; j < k; j++ {
			fmt.Printf("%d ", res[j])
		}
		fmt.Println("")
	}
}

package main

import (
	"fmt"
)

func main()  {
	//fileInput, _ := os.Open("input.txt")
	//os.Stdin = fileInput

	//fileOutput, _ := os.Create("output.txt")
	//os.Stdout = fileOutput

	var n, t, k int
	a := make([]int, 1003)
	res := make([]int, 1003)
	fmt.Scanf("%d", &t)

	for i := 0; i < t; i++ {
		fmt.Scanf("%d", &n)
		for j := 0; j < n ; j++ {
			fmt.Scanf("%d", &a[j])
		}
		k = 0
		if n == 2 {
			if a[0] == a[1] {
				k = 2
				res = a
			} else {
				k = 1
				res[0] = 0
			}
		}
		for j := 0; j < n - 2; {
			if a[j] != a[j+1] {
				if a[j] == a[j+2] {
					res[k] = a[j]
					res[k+1] = a[j+1]
					k += 2
					j += 3
				} else {
					res[k] = a[j+1]
					res[k+1] = a[j+2]
					k += 2
					j += 3
				}
			} else {
				res[k] = a[j]
				res[k+1] = a[j+1]
				k += 2
				j += 2
			}
		}
		fmt.Println(k)
		for j := 0; j < k; j++ {
			fmt.Printf("%d ", res[j])
		}
		fmt.Println("")
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		zeroCount := 0
		oneCount := 0
		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
			if a[j] == 1 {
				oneCount++
			} else {
				zeroCount++
			}
		}
		if oneCount <= zeroCount {
			fmt.Println(zeroCount)
			for j := 0; j < n; j++ {
				if a[j] == 0 {
					fmt.Print(a[j], " ")
				}
			}
		} else {
			fmt.Println(oneCount)
			for j := 0; j < n; j++ {
				if a[j] == 1 {
					fmt.Print(a[j], " ")
				}
			}
		}
		fmt.Println()
	}
}

// Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools

package main

import (
  "fmt"
)

func main() {
  var tests int
  _, _ = fmt.Scanf("%d\n", &tests)
  for ; tests > 0; tests-- {
    var n int
    _, _ = fmt.Scanf("%d\n", &n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
      _, _ = fmt.Scanf("%d", &a[i])
    }

    res := make([]int, 0)
    for i := 0; i < n; i += 2 {
      if a[i]+a[i+1] == 0 {
        res = append(res, 0, 0)
      } else if a[i]+a[i+1] == 1 {
        res = append(res, 0)
      } else {
        res = append(res, 1, 1)
      }
    }
    fmt.Println(len(res))
    for i, d := range res {
      fmt.Printf("%d", d)
      if i < len(res)-1 {
        fmt.Print(" ")
      }
    }
    fmt.Println()
  }
}

// Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools

package main

import (
  "fmt"
)

func main() {
  var tests int
  _, _ = fmt.Scanf("%d\n", &tests)
  for ; tests > 0; tests-- {
    var n int
    _, _ = fmt.Scanf("%d\n", &n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
      _, _ = fmt.Scan(&a[i])
    }

    res := make([]int, 0)
    for i := 0; i < n; i += 2 {
      if a[i]+a[i+1] == 0 {
        res = append(res, 0, 0)
      } else if a[i]+a[i+1] == 1 {
        res = append(res, 0)
      } else {
        res = append(res, 1, 1)
      }
    }
    fmt.Println(len(res))
    for i, d := range res {
      fmt.Printf("%d", d)
      if i < len(res)-1 {
        fmt.Print(" ")
      }
    }
    fmt.Println()
  }
}

// Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools

package main

import (
  "fmt"
)

func main() {
  var tests int
  _, _ = fmt.Scanf("%d\n", &tests)
  for ; tests > 0; tests-- {
    var n int
    _, _ = fmt.Scanf("%d", &n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
      _, _ = fmt.Scanf("%d", &a[i])
    }

    res := make([]int, 0)
    for i := 0; i < n; i += 2 {
      if a[i]+a[i+1] == 0 {
        res = append(res, 0, 0)
      } else if a[i]+a[i+1] == 1 {
        res = append(res, 0)
      } else {
        res = append(res, 1, 1)
      }
    }
    fmt.Println(len(res))
    for i, d := range res {
      fmt.Printf("%d", d)
      if i < len(res)-1 {
        fmt.Print(" ")
      }
    }
    fmt.Println()
  }
}

// Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools

package main

import (
  "fmt"
)

func main() {
  var tests int
  _, _ = fmt.Scanf("%d", &tests)
  for ; tests > 0; tests-- {
    var n int
    _, _ = fmt.Scanf("%d", &n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
      _, _ = fmt.Scanf("%d", &a[i])
    }

    res := make([]int, 0)
    for i := 0; i < n; i += 2 {
      if a[i]+a[i+1] == 0 {
        res = append(res, 0, 0)
      } else if a[i]+a[i+1] == 1 {
        res = append(res, 0)
      } else {
        res = append(res, 1, 1)
      }
    }
    fmt.Println(len(res))
    for i, d := range res {
      fmt.Printf("%d", d)
      if i < len(res)-1 {
        fmt.Print(" ")
      }
    }
    fmt.Println()
  }
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1407A(_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)
		for i := range a {
			Fscan(in, &a[i])
		}
		for {
			s := 0
			for i, v := range a {
				if i&1 == 0 {
					s += v
				} else {
					s -= v
				}
			}
			if s == 0 {
				break
			}
			if s > 0 {
				for i := 0; i < n; i += 2 {
					if a[i] > 0 {
						a = append(a[:i], a[i+1:]...)
						break
					}
				}
			} else {
				for i := 1; i < n; i += 2 {
					if a[i] > 0 {
						a = append(a[:i], a[i+1:]...)
						break
					}
				}
			}
		}
		Fprintln(out, len(a))
		for _, v := range a {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

import (
	"fmt"
	"strings"
)

func main() {
	var t, n, i int
	fmt.Scan(&t)
	for t != 0 {
		fmt.Scan(&n)
		var x int
		var count int

		for i = 0; i < n; i++ {
			fmt.Scan(&x)
			if x == 1 {
				count++
			}
		}
		fmt.Println(n / 2)
		if count > n/2 {
			fmt.Println(strings.Repeat("1 ", n/2))
		} else {
			fmt.Println(strings.Repeat("0 ", n/2))
		}
		t--
	}
}


You have an array $$$a$$$ of length $$$n$$$. For every positive integer $$$x$$$ you are going to perform the following operation during the $$$x$$$-th second:  Select some distinct indices $$$i_{1}, i_{2}, \ldots, i_{k}$$$ which are between $$$1$$$ and $$$n$$$ inclusive, and add $$$2^{x-1}$$$ to each corresponding position of $$$a$$$. Formally, $$$a_{i_{j}} := a_{i_{j}} + 2^{x-1}$$$ for $$$j = 1, 2, \ldots, k$$$. Note that you are allowed to not select any indices at all. You have to make $$$a$$$ nondecreasing as fast as possible. Find the smallest number $$$T$$$ such that you can make the array nondecreasing after at most $$$T$$$ seconds.Array $$$a$$$ is nondecreasing if and only if $$$a_{1} \le a_{2} \le \ldots \le a_{n}$$$.You have to answer $$$t$$$ independent test cases.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^{4}$$$) — the number of test cases. The first line of each test case contains single integer $$$n$$$ ($$$1 \le n \le 10^{5}$$$) — the length of array $$$a$$$. It is guaranteed that the sum of values of $$$n$$$ over all test cases in the input does not exceed $$$10^{5}$$$. The second line of each test case contains $$$n$$$ integers $$$a_{1}, a_{2}, \ldots, a_{n}$$$ ($$$-10^{9} \le a_{i} \le 10^{9}$$$).

For each test case, print the minimum number of seconds in which you can make $$$a$$$ nondecreasing.

NoteIn the first test case, if you select indices $$$3, 4$$$ at the $$$1$$$-st second and $$$4$$$ at the $$$2$$$-nd second, then $$$a$$$ will become $$$[1, 7, 7, 8]$$$. There are some other possible ways to make $$$a$$$ nondecreasing in $$$2$$$ seconds, but you can't do it faster.In the second test case, $$$a$$$ is already nondecreasing, so answer is $$$0$$$.In the third test case, if you do nothing at first $$$2$$$ seconds and select index $$$2$$$ at the $$$3$$$-rd second, $$$a$$$ will become $$$[0, 0]$$$.

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

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

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

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

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n := reader.NextInt64()
		curr := reader.NextInt64()
		secsNeeded := int64(0)
		for ; n > 1; n-- {
			next := reader.NextInt64()
			if next >= curr {
				curr = next
				continue
			}
			delta := curr - next
			tmpSecsNeeded := int64(1)
			tmpSecsValue := int64(1)
			for tmpSecsValue < delta {
				tmpSecsNeeded++
				tmpSecsValue = ((tmpSecsValue + 1) << 1) - 1
			}
			secsNeeded = max(secsNeeded, tmpSecsNeeded)
			// curr does not change
		}
		writer.Printf("%d\n", secsNeeded)
	}
}

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

//Codeforces Round #633 (Div. 2)
//https://codeforces.com/contest/1339/problem/C

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

// var db bool = true
var db bool = false

const maxn int = 1e5

var t, n int
var a [maxn]int64
var pre, ans, p2, p2sum int64

func main() {
	defer writer.Flush()

	scanf("%d\n", &t)
	for tc := 1; tc <= t; tc++ {
		scanf("%d\n", &n)
		for i := 0; i < n; i++ {
		    scanf("%d", &a[i])
		    if i != n-1 {
		        scanf(" ")
		    } else {
		        scanf("\n")
		    }
		    //printf("%d ", a[i])
	    }
	    //printf("\n")
	    pre = a[0]
	    ans = 0
	    p2 = 0
	    p2sum = 0
	    for i := 1; i < n; i++ {
	        if db {
	            printf("a[%d] = %d,%d, pre = %v, p2sum = %v\n", i, a[i], a[i]+p2sum, pre, p2sum)
	        }
	        if a[i] >= pre {
	            pre = a[i]
	            continue
	        }
	        if a[i] + p2sum >= pre {
	            a[i] = pre
	            continue
	        }
	        a[i] += p2sum
		    if a[i] < pre {
		        for a[i] < pre {
		            if db {
	                    printf("    a[%d] = %d\n", i, a[i])
	                }
		            ans++
		            if p2 == 0 {
		                p2 = 1
		            } else {
		                p2 *= 2
		            }
		            a[i] += p2
		            if a[i] > pre {
		                a[i] = pre
		            }
		            p2sum += p2
		            if db {
	                    printf("    p2 = %v, p2sum = %v,                  ans = %v\n", p2, p2sum, ans)
	                }
		        }
		    }
		    if db {
	            printf("        fa[%d] = %d\n", i, a[i])
	        }
		    pre = a[i]
	    }
	    printf("%v\n", ans)
	}
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() int64 {
		sc.Scan()
		i, _ := strconv.ParseInt(sc.Text(), 0, 64)
		return i
	}

	for t := in(); t > 0; t-- {
		n := in()
		a := make([]int64, n)

		for i := range a {
			a[i] = in()
		}

		max := a[0]

		for i := range a {
			if max < a[i] {
				max = a[i]
			}

			a[i] = max - a[i]
		}

		max = a[0]

		for i := range a {
			if max < a[i] {
				max = a[i]
			}
		}

		cnt := 0

		for max != 0 {
			cnt++
			max /= 2
		}

		fmt.Println(cnt)
	}
}

/*
URL:
https://codeforces.com/problemset/problem/1338/A
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int

	n int
	A []int64
)

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

		solve()
	}
}

func solve() {
	md := int64(0)

	cur := A[0]
	for i := 1; i < n; i++ {
		if !ChMax(&cur, A[i]) {
			ChMax(&md, AbsInt(cur-A[i]))
		}
	}

	ans := -1
	for i := 0; i < 60; i++ {
		if NthBit(md, i) == 1 {
			ans = i
		}
	}
	fmt.Println(ans + 1)
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num int64, nth int) int64 {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num int64, nth int) int64 {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num int64, nth int) int64 {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int64) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

// AbsInt is integer version of math.Abs
func AbsInt(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

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

type writerImpl struct {
    *bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
    *bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
    s := bufio.NewScanner(reader)
    s.Split(bufio.ScanWords)
    // adjust the following size as needed
    // 2 << 17 is good enough to scan strings of len 2*10^5
    // it could go as high as 2 << 26 before cf judge breaks
    size := 2 << 20
    buf := make([]byte, size)
    s.Buffer(buf, size)
    return &wordScannerImpl{Scanner: s}
}

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

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

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

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

func main() {
    defer writer.Flush()
    t := reader.NextInt64()
    for ; t > 0; t-- {
        n := reader.NextInt64()
        curr := reader.NextInt64()
        secsNeeded := int64(0)
        for ; n > 1; n-- {
            next := reader.NextInt64()
            if next >= curr {
                curr = next
                continue
            }
            delta := curr - next
            tmpSecsNeeded := int64(1)
            tmpSecsValue := int64(1)
            for tmpSecsValue < delta {
                tmpSecsNeeded++
                tmpSecsValue <<= 1
            }
            secsNeeded = max(secsNeeded, tmpSecsNeeded)
            // curr does not change
        }
        writer.Printf("%d\n", secsNeeded)
    }
}

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

package main

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

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

type writerImpl struct {
    *bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
    *bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
    s := bufio.NewScanner(reader)
    s.Split(bufio.ScanWords)
    // adjust the following size as needed
    // 2 << 17 is good enough to scan strings of len 2*10^5
    // it could go as high as 2 << 26 before cf judge breaks
    size := 2 << 20
    buf := make([]byte, size)
    s.Buffer(buf, size)
    return &wordScannerImpl{Scanner: s}
}

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

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

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

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

func main() {
    defer writer.Flush()
    t := reader.NextInt64()
    for ; t > 0; t-- {
        n := reader.NextInt64()
        curr := reader.NextInt64()
        secsNeeded := int64(0)
        for ; n > 1; n-- {
            next := reader.NextInt64()
            if next >= curr {
                curr = next
                continue
            }
            delta := curr - next
            tmpSecsNeeded := int64(1)
            tmpSecsValue := int64(1)
            for tmpSecsValue < delta {
                tmpSecsNeeded++
                tmpSecsValue <<= 1
            }
            secsNeeded = max(secsNeeded, tmpSecsNeeded)
            curr = next + tmpSecsValue
        }
        writer.Printf("%d\n", secsNeeded)
    }
}

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

//Codeforces Round #633 (Div. 2)
//https://codeforces.com/contest/1339/problem/C

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

//var db bool = true
var db bool = false

const maxn int = 1e5

var t, n int
var a [maxn]int64
var pre, ans, p2, p2sum int64

func main() {
	defer writer.Flush()

	scanf("%d\n", &t)
	for tc := 1; tc <= t; tc++ {
		scanf("%d\n", &n)
		for i := 0; i < n; i++ {
		    scanf("%d", &a[i])
		    if i != n-1 {
		        scanf(" ")
		    } else {
		        scanf("\n")
		    }
		    //printf("%d ", a[i])
	    }
	    //printf("\n")
	    pre = a[0]
	    ans = 0
	    p2 = 0
	    p2sum = 0
	    for i := 1; i < n; i++ {
		    a[i] += p2sum
		    if a[i] < pre {
		        for a[i] < pre {
		            ans++
		            if p2 == 0 {
		                p2 = 1
		            } else {
		                p2 *= 2
		            }
		            a[i] += p2
		            p2sum += p2

		        }
		    }
		    pre = a[i]
	    }
	    printf("%v\n", ans)
	}
}

//Codeforces Round #633 (Div. 2)
//https://codeforces.com/contest/1339/problem/C

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

// var db bool = true
var db bool = false

const maxn int = 1e5

var t, n int
var a [maxn]int64
var pre, ans, p2, p2sum int64

func main() {
	defer writer.Flush()

	scanf("%d\n", &t)
	for tc := 1; tc <= t; tc++ {
		scanf("%d\n", &n)
		for i := 0; i < n; i++ {
		    scanf("%d", &a[i])
		    if i != n-1 {
		        scanf(" ")
		    } else {
		        scanf("\n")
		    }
		    //printf("%d ", a[i])
	    }
	    //printf("\n")
	    pre = a[0]
	    ans = 0
	    p2 = 0
	    p2sum = 0
	    for i := 1; i < n; i++ {
	        if db {
	            printf("a[%d] = %d,%d, pre = %v, p2sum = %v\n", i, a[i], a[i]+p2sum, pre, p2sum)
	        }
	        if a[i] >= pre {
	            pre = a[i]
	            continue
	        }
	        if a[i] + p2sum >= pre {
	            a[i] = pre
	            continue
	        }
	        a[i] += p2sum
		    if a[i] < pre {
		        for a[i] < pre {
		            if db {
	                    printf("    a[%d] = %d\n", i, a[i])
	                }
		            ans++
		            if p2 == 0 {
		                p2 = 1
		            } else {
		                p2 *= 2
		            }
		            a[i] += p2
		            p2sum += p2
		            if db {
	                    printf("    p2 = %v, p2sum = %v,                  ans = %v\n", p2, p2sum, ans)
	                }
		        }
		    }
		    if db {
	            printf("        fa[%d] = %d\n", i, a[i])
	        }
		    pre = a[i]
	    }
	    printf("%v\n", ans)
	}
}


You are given two integers $$$n$$$ and $$$d$$$. You need to construct a rooted binary tree consisting of $$$n$$$ vertices with a root at the vertex $$$1$$$ and the sum of depths of all vertices equals to $$$d$$$.A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. A parent of a vertex $$$v$$$ is the last different from $$$v$$$ vertex on the path from the root to the vertex $$$v$$$. The depth of the vertex $$$v$$$ is the length of the path from the root to the vertex $$$v$$$. Children of vertex $$$v$$$ are all vertices for which $$$v$$$ is the parent. The binary tree is such a tree that no vertex has more than $$$2$$$ children.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The only line of each test case contains two integers $$$n$$$ and $$$d$$$ ($$$2 \le n, d \le 5000$$$) — the number of vertices in the tree and the required sum of depths of all vertices. It is guaranteed that the sum of $$$n$$$ and the sum of $$$d$$$ both does not exceed $$$5000$$$ ($$$\sum n \le 5000, \sum d \le 5000$$$).

For each test case, print the answer. If it is impossible to construct such a tree, print "NO" (without quotes) in the first line. Otherwise, print "{YES}" in the first line. Then print $$$n-1$$$ integers $$$p_2, p_3, \dots, p_n$$$ in the second line, where $$$p_i$$$ is the parent of the vertex $$$i$$$. Note that the sequence of parents you print should describe some binary tree.

NotePictures corresponding to the first and the second test cases of the example:

package main

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

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

	var T, n, d, lastR int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &d)
		p := make([]int, n+1)
		r := make([][]int, n)
		var f func(v, d int)
		f = func(v, d int) {
			if v <= n {
				p[v] = v / 2
				r[d] = append(r[d], v)
				f(2*v, d+1)
				f(2*v+1, d+1)
			}
		}
		f(1, 0)
		for i, vs := range r {
			if len(vs) == 0 {
				break
			}
			lastR = i
			d -= len(vs) * i
		}
		i := n - 1
		for i >= 0 && d > 0 {
			vs := r[i]
			if len(vs) <= 1 {
				i--
				continue
			}
			v := vs[len(vs)-1]
			r[i] = vs[:len(vs)-1]
			if lastR-i+1 < d {
				d -= lastR - i + 1
				p[v] = r[lastR][0]
				lastR++
				r[lastR] = []int{v}
			} else {
				p[v] = r[i+d-1][0]
				d = 0
			}
		}
		if i < 0 || d < 0 {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
			for _, v := range p[2:] {
				Fprint(out, v, " ")
			}
			Fprintln(out)
		}
	}
}

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

package main

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

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

	var T, n, d, lastR int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &d)
		p := make([]int, n+1)
		r := make([][]int, n)
		var f func(v, d int)
		f = func(v, d int) {
			if v <= n {
				p[v] = v / 2
				r[d] = append(r[d], v)
				f(2*v, d+1)
				f(2*v+1, d+1)
			}
		}
		f(1, 0)
		for i, vs := range r {
			if len(vs) == 0 {
				break
			}
			lastR = i
			d -= len(vs) * i
		}
		i := n - 1
		for ; i >= 0 && d > 0; i-- {
			vs := r[i]
			if len(vs) <= 1 {
				continue
			}
			v := vs[len(vs)-1]
			r[i] = vs[:len(vs)-1]
			if lastR-i+1 < d {
				d -= lastR - i + 1
				p[v] = r[lastR][0]
				lastR++
				r[lastR] = []int{v}
			} else {
				p[v] = r[i+d-1][0]
				d = 0
			}
		}
		if i < 0 || d < 0 {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
			for _, v := range p[2:] {
				Fprint(out, v, " ")
			}
			Fprintln(out)
		}
	}
}

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


This is the hard version of the problem. The difference between versions is the constraints on $$$n$$$ and $$$a_i$$$. You can make hacks only if all versions of the problem are solved.First, Aoi came up with the following idea for the competitive programming problem:Yuzu is a girl who collecting candies. Originally, she has $$$x$$$ candies. There are also $$$n$$$ enemies numbered with integers from $$$1$$$ to $$$n$$$. Enemy $$$i$$$ has $$$a_i$$$ candies.Yuzu is going to determine a permutation $$$P$$$. A permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$\{2,3,1,5,4\}$$$ is a permutation, but $$$\{1,2,2\}$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$\{1,3,4\}$$$ is also not a permutation (because $$$n=3$$$ but there is the number $$$4$$$ in the array).After that, she will do $$$n$$$ duels with the enemies with the following rules:  If Yuzu has equal or more number of candies than enemy $$$P_i$$$, she wins the duel and gets $$$1$$$ candy. Otherwise, she loses the duel and gets nothing.  The candy which Yuzu gets will be used in the next duels. Yuzu wants to win all duels. How many valid permutations $$$P$$$ exist?This problem was easy and wasn't interesting for Akari, who is a friend of Aoi. And Akari made the following problem from the above idea:Let's define $$$f(x)$$$ as the number of valid permutations for the integer $$$x$$$.You are given $$$n$$$, $$$a$$$ and a prime number $$$p \le n$$$. Let's call a positive integer $$$x$$$ good, if the value $$$f(x)$$$ is not divisible by $$$p$$$. Find all good integers $$$x$$$.Your task is to solve this problem made by Akari.

The first line contains two integers $$$n$$$, $$$p$$$ $$$(2 \le p \le n \le 10^5)$$$. It is guaranteed, that the number $$$p$$$ is prime (it has exactly two divisors $$$1$$$ and $$$p$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$.

In the first line, print the number of good integers $$$x$$$. In the second line, output all good integers $$$x$$$ in the ascending order. It is guaranteed that the number of good integers $$$x$$$ does not exceed $$$10^5$$$.

NoteIn the first test, $$$p=2$$$.  If $$$x \le 2$$$, there are no valid permutations for Yuzu. So $$$f(x)=0$$$ for all $$$x \le 2$$$. The number $$$0$$$ is divisible by $$$2$$$, so all integers $$$x \leq 2$$$ are not good.  If $$$x = 3$$$, $$$\{1,2,3\}$$$ is the only valid permutation for Yuzu. So $$$f(3)=1$$$, so the number $$$3$$$ is good.  If $$$x = 4$$$, $$$\{1,2,3\} , \{1,3,2\} , \{2,1,3\} , \{2,3,1\}$$$ are all valid permutations for Yuzu. So $$$f(4)=4$$$, so the number $$$4$$$ is not good.  If $$$x \ge 5$$$, all $$$6$$$ permutations are valid for Yuzu. So $$$f(x)=6$$$ for all $$$x \ge 5$$$, so all integers $$$x \ge 5$$$ are not good. So, the only good number is $$$3$$$.In the third test, for all positive integers $$$x$$$ the value $$$f(x)$$$ is divisible by $$$p = 3$$$.

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

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

type node struct {
	l, r, mid, tot int
	left, right    *node
}

func (v *node) off(le, ri int) {
	if (le <= v.l && ri >= v.r) || v.tot == 0 {
		v.tot = 0
		return
	}

	if v.left == nil {
		v.left = &node{v.l, v.mid, (v.l + v.mid) >> 1, v.mid - v.l, nil, nil}
	}
	if v.right == nil {
		v.right = &node{v.mid, v.r, (v.mid + v.r) >> 1, v.r - v.mid, nil, nil}
	}

	if le < v.mid {
		v.left.off(le, ri)
	}
	if ri > v.mid {
		v.right.off(le, ri)
	}

	v.tot = v.left.tot + v.right.tot
}

const maxLog = 30

var res = []int{}

func (v *node) find() {
	if v == nil {
		return
	}
	if v.tot == 0 {
		return
	}
	if v.l == v.r-1 {
		res = append(res, v.l)
		return
	}

	if v.left == nil {
		v.left = &node{v.l, v.mid, (v.l + v.mid) >> 1, v.mid - v.l, nil, nil}
	}
	if v.right == nil {
		v.right = &node{v.mid, v.r, (v.mid + v.r) >> 1, v.r - v.mid, nil, nil}
	}

	v.left.find()
	v.right.find()
}

func main() {
	out = bufio.NewWriterSize(os.Stdout, 8192)
	defer out.Flush()
	if false {
		file, err := os.Open("in.txt")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file, 8192)
	} else {
		in = bufio.NewReaderSize(os.Stdin, 8192)
	}

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

	arr := make([]int, n)
	for i := range arr {
		scanf("%d", &arr[i])
	}

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

	tree := &node{0, 1 << maxLog, 1 << (maxLog - 1), 1 << maxLog, nil, nil}
	tree.off(arr[n-1]-(n-p), 1<<30)

	for i, v := range arr {
		tree.off(0, v-i)
	}

	for i := p; i < n; i++ {
		tree.off(arr[i-1]-(i-p), arr[i]-(i-p))
	}

	tree.find()
	printf("%d\n", len(res))
	for _, v := range res {
		printf("%d ", v)
	}
	printf("\n")
}

package main

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

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

	n, p := readTwoNums(reader)
	A := readNNums(reader, n)
	res := solve(n, p, A)
	fmt.Println(len(res))
	for i := 0; i < len(res); i++ {
		fmt.Printf("%d ", res[i])
	}
}

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

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

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

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

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

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

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

	return i
}

const MAX_N = 262144

var BK [MAX_N]int

func solve(n int, p int, A []int) []int {
	var bas = A[0]

	for i := 1; i < n; i++ {
		bas = max(bas, A[i])
	}

	for i := 0; i < MAX_N; i++ {
		BK[i] = 0
	}

	for i := 0; i < n; i++ {
		BK[max(0, A[i]-bas+n)]++
	}

	for i := 1; i < MAX_N; i++ {
		BK[i] += BK[i-1]
	}

	var st = 1
	for i := 1; i <= n; i++ {
		for BK[st+i-1] < i {
			st++
		}
	}

	st += bas - n

	fi := n

	for i := 1; i <= n; i++ {
		for fi > 0 {
			if BK[fi+(i-1)]-(i-1) < p {
				break
			}
			fi--
		}
	}

	fi += bas - n

	if fi < st {
		return nil
	}

	res := make([]int, 0, fi-st+1)

	for i := st; i <= fi; i++ {
		res = append(res, i)
	}

	return res
}

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

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

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

type node struct {
	l, r, mid, tot int
	left, right    *node
}

func (v *node) off(le, ri int) {
	if (le <= v.l && ri >= v.r) || v.tot == 0 {
		v.tot = 0
		return
	}

	if v.left == nil {
		v.left = &node{v.l, v.mid, (v.l + v.mid) >> 1, v.mid - v.l, nil, nil}
	}
	if v.right == nil {
		v.right = &node{v.mid, v.r, (v.mid + v.r) >> 1, v.r - v.mid, nil, nil}
	}

	if le < v.mid {
		v.left.off(le, ri)
	}
	if ri > v.mid {
		v.right.off(le, ri)
	}

	v.tot = v.left.tot + v.right.tot
}

var res = []int{}

func (v *node) find() {
	if v == nil {
		return
	}
	if v.tot == 0 {
		return
	}
	if v.l == v.r-1 {
		res = append(res, v.l)
		return
	}

	v.left.find()
	v.right.find()
}

func main() {
	out = bufio.NewWriterSize(os.Stdout, 8192)
	defer out.Flush()
	if false {
		file, err := os.Open("in.txt")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file, 8192)
	} else {
		in = bufio.NewReaderSize(os.Stdin, 8192)
	}

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

	arr := make([]int, n)
	for i := range arr {
		scanf("%d", &arr[i])
	}

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

	tree := &node{0, 1 << 30, 1 << 29, 1 << 30, nil, nil}
	tree.off(arr[n-1]-(n-p), 1<<30)

	for i, v := range arr {
		tree.off(0, v-i)
	}

	for i := p; i < n; i++ {
		tree.off(arr[i-1]-(i-p), arr[i]-(i-p))
	}

	tree.find()
	printf("%d\n", len(res))
	for _, v := range res {
		printf("%d ", v)
	}
	printf("\n")
}


Consider a tunnel on a one-way road. During a particular day, $$$n$$$ cars numbered from $$$1$$$ to $$$n$$$ entered and exited the tunnel exactly once. All the cars passed through the tunnel at constant speeds.A traffic enforcement camera is mounted at the tunnel entrance. Another traffic enforcement camera is mounted at the tunnel exit. Perfectly balanced.Thanks to the cameras, the order in which the cars entered and exited the tunnel is known. No two cars entered or exited at the same time.Traffic regulations prohibit overtaking inside the tunnel. If car $$$i$$$ overtakes any other car $$$j$$$ inside the tunnel, car $$$i$$$ must be fined. However, each car can be fined at most once.Formally, let's say that car $$$i$$$ definitely overtook car $$$j$$$ if car $$$i$$$ entered the tunnel later than car $$$j$$$ and exited the tunnel earlier than car $$$j$$$. Then, car $$$i$$$ must be fined if and only if it definitely overtook at least one other car.Find the number of cars that must be fined.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$), denoting the number of cars. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$), denoting the ids of cars in order of entering the tunnel. All $$$a_i$$$ are pairwise distinct. The third line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le n$$$), denoting the ids of cars in order of exiting the tunnel. All $$$b_i$$$ are pairwise distinct.

NoteThe first example is depicted below:Car $$$2$$$ definitely overtook car $$$5$$$, while car $$$4$$$ definitely overtook cars $$$1$$$, $$$2$$$, $$$3$$$ and $$$5$$$. Cars $$$2$$$ and $$$4$$$ must be fined.In the second example car $$$5$$$ was definitely overtaken by all other cars.In the third example no car must be fined.

package main

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

/* solution */

func solve() {
	n := readInt()
	a, b := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
	}
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	out := make([]bool, n+1)
	position := 0
	ans := 0
	for i := 0; i < n; i++ {
		for out[a[position]] {
			position++
		}
		if a[position] != b[i] {
			ans++
		}
		out[b[i]] = true
	}
	printInt(ans)
}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

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

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

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

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

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

func solve(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	b := make([]int, n)
	for i := range b {
		Fscan(in, &b[i])
	}

	ans := 0
	check := make([]bool, n+1)
	//now := b[n-1]
	j := n - 1
	for i := n - 1; i >= 0; i-- {
		if check[b[i]] {
			 continue
		}
		for ; j >= 0; j-- {
			if a[j] != b[i] {
				ans++
				check[a[j]] = true
				continue
			}
			j--
			break
		}
	}
	Fprintln(out, ans)
}

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

package main

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

func main() {
	defer Flush()

	n, a := readInts(0)
	_, b := readInts(n)

	c := make([]bool, n+1)
	var ans int
	var i int
	for _, v := range a {
		if c[v] {
			continue
		}
		for i < n && b[i] != v {
			c[b[i]] = true
			ans++
			i++
		}
		c[v] = true
		i++
	}
	println(ans)

}

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

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

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

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

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

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

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

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

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

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}