Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave ai points.Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b1, b2, ..., bn (it is guaranteed that all values bj are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.Your task is to determine the number of options for the score the participant could have before the judges rated the participant.

The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers. The second line contains k integers a1, a2, ..., ak ( - 2 000 ≤ ai ≤ 2 000) — jury's marks in chronological order. The third line contains n distinct integers b1, b2, ..., bn ( - 4 000 000 ≤ bj ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.

Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).

NoteThe answer for the first example is 3 because initially the participant could have  - 10, 10 or 15 points.In the second example there is only one correct initial score equaling to 4 002 000.

package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	var k, n int64
	for I(&k, &n) == nil {
		solve(k, n)
	}
	w.Flush()
}

func solve(k, n int64) {
	kk := make([]int64, k)
	nn := make([]int64, n)
	for i := range kk {
		I(&kk[i])
	}
	var ans int64
	mm := make(map[int64]int64)
	for i := range nn {
		I(&nn[i])
		o := nn[i]
		qq := make(map[int64]bool)
		for j := range kk {
			o -= kk[j]
			if !qq[o] {
				mm[o]++
				qq[o] = true
			}
		}
	}
	for i := range mm {
		if mm[i] == n {
			ans++
		}
	}
	O(ans, "\n")
}

package main

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

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

	k := readInt(reader)
	n := readInt(reader)

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

	for i := 0; i<k; i++ {
		a[i] = readInt(reader)
	}

	for i := 0; i<n; i++ {
		b[i] = readInt(reader)
	}

	da := make([]int, k)
	for i := 0; i<k; i++ {
		da[i] = 0
	}
	for i := 0; i<k; i++ {
		if i==0 {
			continue
		}
		da[i] = a[i] + da[i-1]
	}

	//fmt.Println(a)
	//fmt.Println(b)

	nMap := make(map[int]bool)

	for i := 0; i<k; i++ {
		m := make(map[int]bool)
		for tmp := 0; tmp<n; tmp++ {
			m[b[tmp]] = true
		}
		start := b[0]
		delete(m, start)
		eval := 0
		if len(m)!=0 {
			for i_iter := 0; i_iter<k; i_iter++ {
				if i_iter==i {
					eval++
					continue
				}
				m_size := len(m)
				remain_size := k-eval
				if m_size>remain_size {
					break
				}
				var value int
				if i<i_iter {
					value = start + da[i_iter] - da[i]
				} else {
					value = start - (da[i] - da[i_iter])
				}

				_,ok := m[value]
				if ok {
					delete(m, value)
					if len(m)==0 {
						break
					}
				}
				eval++
			}
		}

		if len(m)==0 {
			//fmt.Printf("found match: %v %v\n", i, b[j])
			init := start
			if i==0 {
				init -= a[0]
			} else {
				init -= da[i]
				init -= a[0]
			}
			//for tmp := i; tmp>-1; tmp-- {
			//	init -= a[tmp]
			//}
			//fmt.Printf("init=%v\n", init)
			_,ok := nMap[init]
			if !ok {
				nMap[init] = true
			}
		}

	}

	fmt.Println(len(nMap))

}

func readString(nr *bufio.Reader) *string {
	line, _, err := nr.ReadLine()
	if err!=nil {
		panic(err)
	}
	s := string(line)
	return &s
}

func readInt(nr *bufio.Reader) int {
	var a int
	fmt.Fscan(nr, &a)
	return a
}

func readA(n int) *[]int {
	a := make([]int, n)

	reader := bufio.NewReader(os.Stdin)

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

	return &a
}

package main

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

func main() {
	fsc := NewFastScanner()
	K, N := fsc.NextInt(), fsc.NextInt()
	B := make([]int, 0)
	values := map[int]bool{}
	sum := 0
	for i := 0; i < K; i++ {
		sum += fsc.NextInt()
		if _, ok := values[sum]; !ok {
			values[sum] = true
		}
	}
	for i := 0; i < N; i++ {
		B = append(B, fsc.NextInt())
	}
	result := 0
	for val := range values {
		src := B[0] - val
		flag := true
		for i := 0; i < N; i++ {
			if _, ok := values[B[i]-src]; !ok {
				flag = false
				break
			}
		}
		if flag {
			result++
		}
	}
	fmt.Println(result)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

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

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}

func IntAbs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

func Int64Abs(a int64) int64 {
	if a < 0 {
		a *= -1
	}
	return a
}

package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	var k, n int64
	for I(&k, &n) == nil {
		solve(k, n)
	}
	w.Flush()
}

func solve(k, n int64) {
	kk := make([]int64, k)
	nn := make([]int64, n)
	for i := range kk {
		I(&kk[i])
	}
	var ans int64
	bloom := make([]int, 1e7*2)
	for i := range nn {
		I(&nn[i])
		o := nn[i]
		bloomm := make([]bool, 1e7*2)
		for j := range kk {
			o -= kk[j]
			fh, sh := firstHash(o), secondHash(o)
			if !bloomm[fh] && !bloomm[sh] {
				bloom[fh]++
				bloom[sh]++
				bloomm[fh], bloomm[sh] = true, true
			}
		}
	}
	for i := range bloom {
		if bloom[i] == int(n) {
			ans++
		}
	}
	O(ans/2, "\n")
}

func firstHash(a int64) int {
	a = (^a) + (a << 18)
	a = a ^ ((a >> 31) | (a << 33))
	a = a * 21
	a = a ^ ((a >> 11) | (a << 53))
	a = a + (a << 6)
	a = a ^ ((a >> 22) | (a << 44))
	return abs(int(a % 1998691))
}

func secondHash(a int64) int {
	a = (^a) + (a << 18)
	a = a ^ ((a >> 31) | (a << 33))
	a = a * 21
	a = a ^ ((a >> 11) | (a << 53))
	a = a + (a << 6)
	a = a ^ ((a >> 22) | (a << 44))
	return abs(int(a % 1972133))
}

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

package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	var k, n int64
	for I(&k, &n) == nil {
		solve(k, n)
	}
	w.Flush()
}

func solve(k, n int64) {
	kk := make([]int64, k)
	nn := make([]int64, n)
	for i := range kk {
		I(&kk[i])
	}
	var ans int64
	bloom := make([]int, 1e7*2)
	for i := range nn {
		I(&nn[i])
		o := nn[i]
		bloomm := make([]bool, 1e7*2)
		for j := range kk {
			o -= kk[j]
			fh, sh := firstHash(o), secondHash(o)
			if !bloomm[fh] && !bloomm[sh] {
				bloom[fh]++
				bloom[sh]++
				bloomm[fh], bloomm[sh] = true, true
			}
		}
	}
	for i := range bloom {
		if bloom[i] == int(n) {
			ans++
		}
	}
	O(ans/2, "\n")
}

func firstHash(a int64) int {
	a = (a + 0x7ed55d16) + (a << 12)
	a = (a ^ 0xc761c23c) ^ (a >> 19)
	a = (a + 0x165667b1) + (a << 5)
	a = (a + 0xd3a2646c) ^ (a << 9)
	a = (a + 0xfd7046c5) + (a << 3)
	a = (a ^ 0xb55a4f09) ^ (a >> 16)
	return abs(int(a) % 1820281)
}

func secondHash(a int64) int {
	a = (a ^ 0xc761c23c) ^ (a >> 19)
	a = (a + 0x165667b1) + (a << 5)
	a = (a + 0xd3a2646c) ^ (a << 9)
	a = (a + 0xfd7046c5) + (a << 3)
	a = (a ^ 0xb55a4f09) ^ (a >> 16)
	a = (a + 0x7ed55d16) + (a << 12)
	return abs(int(a) % 1998691)
}

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

package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	var k, n int64
	for I(&k, &n) == nil {
		solve(k, n)
	}
	w.Flush()
}

func solve(k, n int64) {
	kk := make([]int64, k)
	nn := make([]int64, n)
	for i := range kk {
		I(&kk[i])
	}
	ppp := make(map[int64]bool)
	for i := range nn {
		I(&nn[i])
		ppp[nn[i]] = true
	}
	var ans uint64
	o := int64(-1e6 * 4)
	oo := int64(1e6 * 4)
	for i := o; i <= oo; i++ {
		var p int64
		nnn := make(map[int64]bool)
		q := int64(i)
		if !nnn[q] && ppp[q] {
			nnn[q] = true
			p++
		}
		for _, j := range kk {
			q += j
			if !nnn[q] && ppp[q] {
				nnn[q] = true
				p++
			}
		}
		if p == n {
			ans++
		}
	}
	O(ans, "\n")
}


Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.

The single line contains two integers, n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000).

Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them.

NoteIn the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements.

package main
import (
	"fmt"
)

func main() {
	var n,k int
	fmt.Scan(&n,&k)
	for i:=1;i<=n;i++ {
		for j:=1;j<=n;j++ {
			if j==i {
				fmt.Print(k," ")
			}else {
				fmt.Print("0"," ")
			}
		}
		fmt.Println()
	}
}

// http://codeforces.com/problemset/problem/361/A#
package main

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

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

func main () {
	var n, k int

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n, &k)

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if j != 0 {
				fmt.Print(" ")
			}

			if i == j {
				fmt.Print(k)
			} else {
				fmt.Print("0")
			}
		}

		fmt.Println()
	}
}

package main

import "fmt"

func main() {
    var n,k int
    fmt.Scan(&n,&k)
    for i := 0; i < n; i++ {
        for j := 0; j < n; j++ {
            if i == j { fmt.Print(k) } else { fmt.Print(0) }
            if j == (n-1) { fmt.Println() } else { fmt.Print(" ") }
        }
    }
}

// 361A-mic
package main

import (
    "fmt"
)

func main() {
    var n, k int
    fmt.Scan(&n, &k)
    for i := 0; i < n; i++ {
        for j := 0; j < n; j++ {
            if i == j && j == 0 {
                fmt.Print(k)
            }
            if i == j && j != 0 {
                fmt.Print(" ")
                fmt.Print(k)
            }
            if i != j && j == 0 {
                fmt.Print("0")
            }
            if i != j && j != 0 {
                fmt.Print(" ")
                fmt.Print("0")
            }
        }
        fmt.Println()
    }
}

package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if (j == i) {
				fmt.Printf("%d ", k)
			} else {
				fmt.Printf("0 ")
			}
		}
		fmt.Printf("\n")
	}
}

// 361A-mic
package main

import (
    "fmt"
)

func main() {
    var n, k int
    fmt.Scan(&n, &k)
    for i := 0; i < n; i++ {
        for j := 0; j < n; j++ {
            if i == j && j == 0 {
                fmt.Print(k)
            }
            if i == j && j != 0 {
                fmt.Print(" ")
                fmt.Print(k)
            }
            if i != j && j == 0 {
                fmt.Print("0")
            }
            if i != j && j != 0 {
                fmt.Print("0")
            }
        }
        fmt.Println()
    }
}


You are given a positive integer $$$n$$$. In one move, you can increase $$$n$$$ by one (i.e. make $$$n := n + 1$$$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $$$n$$$ be less than or equal to $$$s$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 10^{18}$$$; $$$1 \le s \le 162$$$).

For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $$$n$$$ be less than or equal to $$$s$$$.

package main

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

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

	T:= 0
	for Fscan(in, &T); T > 0; T-- {
		var n,s int64
		Fscan(in, &n, &s);
		sod:=func(n int64) int64{
			v:=int64(0)
			for n>0{
				v+=n%10
				n/=10
			}
			return v
		}

		getNext:=func(n int64) int64 {
			if n==0{
				return 1
			}
			k:=int64(1)
			for n%10==0{
				k*=10
				n/=10
			}
			k*=10
			n/=10
			n++
			return n*k
		}
		m:=n
		for sod(m)>s{
			m=getNext(m)
		}
		Fprintln(out,m-n)
	}
}

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

package main

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

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

	for t := io.NextInt(); t > 0; t-- {
		n, s := io.NextInt64(), io.NextInt()

		nstr := "0" + strconv.FormatInt(n, 10)
		m := len(nstr)
		digits := make([]int, m)
		sum := 0
		for i, d := range nstr {
			digits[i] = int(d - '0')
			sum += digits[i]
		}

		var ans int64
		pow10 := int64(1)
		for i := m - 1; i >= 0; i-- {
			if sum > s {
				if digits[i] > 0 {
					ans += int64(10-digits[i]) * pow10
					sum -= digits[i] - 1
					digits[i-1] += 1
				}
			}
			pow10 *= 10
		}

		io.Println(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) NextInt64() int64 {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	var n int64
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int64(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

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

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() uint64 {
		sc.Scan()
		i, _ := strconv.ParseUint(sc.Text(), 10, 64)
		return i
	}

	for t := in(); t > 0 ; t-- {
		n, s := in(), in()

		a := make([]uint64, 0, 18)

		for n != 0 {
			a = append(a, n%10)
			n /= 10
		}

		var i int
		m := len(a)
		b := make([]uint64,m)

		b[m-1] = a[m-1]

		for i = m-2; i >= 0; i-- {
			b[i] = a[i] + b[i+1]
		}

		for i = m-1; i >=0 ; i-- {
			if b[i] > s || (b[i] == s && b[0] != s) {
				break
			}
		}

		var val uint64 = 0

		if i == -1 {
			fmt.Println(0)
			continue
		}

		for j := i; j >= 0; j-- {
			val *= 10
			val += (9 - a[j])
		}

		val++

		fmt.Println(val)
	}
}

package main

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

func main(){
	var (
		t int
		n,s,tmp,div,ans uint64
		jobGoing bool
	)
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i:=1;i<=t;i++{
		jobGoing = true
		div = 1
		ans = 0
		fmt.Fscan(in, &n, &s)
		for n/div>=10{
			div*=10
		}
		for jobGoing {
			tmp = (n/div)%10
			if s<=tmp {
				if s==tmp{
					if n%div!=0{
						ans = (div*10)-(n%(div*10))
						jobGoing = false
					}
				}else{
					ans = (div*10)-(n%(div*10))
					jobGoing = false
				}
			}else{
				s = s-tmp
			}
			div/=10
			if div==0{
				jobGoing = false
			}
		}
		fmt.Println(ans)
	}
}

package main

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

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

func main() {
	defer writer.Flush()

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

	var n string
	var s int
	for t > 0 {
		scanf("%s %d\n", &n, &s)

		nn := 0
		for i := 0; i < len(n); i++ {
			nn += int(n[i] - '0')
		}
		if nn <= s {
			printf("0\n")
			t--
			continue
		}
		var ans int64
		sum := 0
		i := 0
		for i < len(n) {
			sum += int(n[i] - '0')
			if sum >= s {
				break
			}
			ans = ans*10 + int64(n[i]-'0')
			i++
		}
		if i == 0 {
			ans = int64(math.Pow(10, float64(len(n))))
		} else {
			ans++
			ans = ans * int64(math.Pow(10, float64(len(n)-i)))
		}
		temp, _ := strconv.ParseInt(n, 10, 64)
		// printf("%d - %d\n", ans, temp)
		printf("%d\n", ans-temp)
		t--
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func f(x int64) (s int64) {
	for ; x > 0; x /= 10 {
		s += x % 10
	}
	return
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T, up, n int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &up)
		if f(n) <= up {
			Fprintln(out, 0)
			continue
		}
		for p := int64(10); ; p *= 10 {
			if v := (n/p + 1) * p; f(v) <= up {
				Fprintln(out, v-n)
				break
			}
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func f(s string) (ds int) {
	for _, b := range s {
		ds += int(b & 15)
	}
	return
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T, up int
	var n int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &up)
		if f(strconv.FormatInt(n, 10)) <= up {
			Fprintln(out, 0)
			continue
		}
		for p := int64(10); ; p *= 10 {
			if v := (n/p + 1) * p; f(strconv.FormatInt(v, 10)) <= up {
				Fprintln(out, v-n)
				break
			}
		}
	}
}

package main

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

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

func main() {
	defer writer.Flush()

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

	var n string
	var s int
	for t > 0 {
		scanf("%s %d\n", &n, &s)

		nn, _ := strconv.Atoi(n)
		if nn == s {
			printf("0\n")
			t--
			continue
		}
		var ans int64
		sum := 0
		i := 0
		for i < len(n) {
			sum += int(n[i] - '0')
			if sum >= s {
				break
			}
			ans = ans*10 + int64(n[i]-'0')
			i++
		}
		if i == 0 {
			ans = int64(math.Pow(10, float64(len(n))))
		} else {
			ans++
			ans = ans * int64(math.Pow(10, float64(len(n)-i)))
		}
		temp, _ := strconv.Atoi(n)
		// printf("%d - %d\n", ans, temp)
		printf("%d\n", ans-int64(temp))
		t--
	}
}

package main

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

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

func main() {
	defer writer.Flush()

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

	var n string
	var s int
	for t > 0 {
		scanf("%s %d\n", &n, &s)

		nn, _ := strconv.Atoi(n)
		if nn <= s {
			printf("0\n")
			t--
			continue
		}
		var ans int64
		sum := 0
		i := 0
		for i < len(n) {
			sum += int(n[i] - '0')
			if sum >= s {
				break
			}
			ans = ans*10 + int64(n[i]-'0')
			i++
		}
		if i == 0 {
			ans = int64(math.Pow(10, float64(len(n))))
		} else {
			ans++
			ans = ans * int64(math.Pow(10, float64(len(n)-i)))
		}
		temp, _ := strconv.ParseInt(n, 10, 64)
		// printf("%d - %d\n", ans, temp)
		printf("%d\n", ans-temp)
		t--
	}
}

package main

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

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

func main() {
	defer writer.Flush()

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

	var n string
	var s int
	for t > 0 {
		scanf("%s %d\n", &n, &s)

		nn, _ := strconv.Atoi(n)
		if nn == s {
			printf("0\n")
			t--
			continue
		}
		var ans int64
		sum := 0
		i := 0
		for i < len(n) {
			sum += int(n[i] - '0')
			if sum >= s {
				break
			}
			ans = ans*10 + int64(n[i]-'0')
			i++
		}
		if i == 0 {
			ans = int64(math.Pow(10, float64(len(n))))
		} else {
			ans++
			ans = ans * int64(math.Pow(10, float64(len(n)-i)))
		}
		temp, _ := strconv.ParseInt(n, 10, 64)
		// printf("%d - %d\n", ans, temp)
		printf("%d\n", ans-temp)
		t--
	}
}

package main

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

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

func main() {
	defer writer.Flush()

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

	var n string
	var s int
	for t > 0 {
		scanf("%s %d\n", &n, &s)

		nn, _ := strconv.Atoi(n)
		if nn == s {
			printf("0\n")
			t--
			continue
		}
		var ans int
		sum := 0
		i := 0
		for i < len(n) {
			sum += int(n[i] - '0')
			if sum >= s {
				break
			}
			ans = ans*10 + int(n[i]-'0')
			i++
		}
		if i == 0 {
			ans = int(math.Pow(10, float64(len(n))))
		} else {
			ans++
			ans = ans * int(math.Pow(10, float64(len(n)-i)))
		}
		temp, _ := strconv.Atoi(n)
		// printf("%d - %d\n", ans, temp)
		printf("%d\n", ans-int(temp))
		t--
	}
}


Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can't use it in any other day to get more money. If a worker gives back w tokens then he'll get  dollars. Mashmokh likes the tokens however he likes money more. That's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has n numbers x1, x2, ..., xn. Number xi is the number of tokens given to each worker on the i-th day. Help him calculate for each of n days the number of tokens he can save.

The first line of input contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The second line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109).

Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day.

// 415B
package main

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

func main() {
	var n, a, b, i, x int64
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &n, &a, &b)
	for i = 1; i <= n; i++ {
		fmt.Fscan(in, &x)
		fmt.Fprintf(out, "%d ", (x*a%b)/a)
	}
	out.Flush()
}

// 415B
package main

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

func main() {
	var n, a, b, i, x int64
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &n, &a, &b)
	for i = 1; i <= n; i++ {
		fmt.Fscan(in, &x)
		fmt.Fprintf(out, "%d ", (x*a%b)/a)
	}
}

// 415B
package main

import (
	"fmt"
)

func main() {
	var n, a, b, i, x int64
	fmt.Scan(&n, &a, &b)
	for i = 1; i <= n; i++ {
		fmt.Scan(&x)
		fmt.Print((x * a % b) / a)
	}
}

// 415B
package main

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

func main() {
	var n, a, b, i, x int64
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &n, &a, &b)
	for i = 1; i <= n; i++ {
		fmt.Scan(&x)
		fmt.Fprintf(out, "%d ", (x*a%b)/a)
	}
}


«Next please», — the princess called and cast an estimating glance at the next groom.The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing.The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, ..., tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1.

The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces.

Output any sequence of integers t1, t2, ..., tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1.

NoteLet's have a closer look at the answer for the first sample test.   The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.  The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n, a, b uint
	Scan(&n, &a, &b)
	base := uint(1) << b
	if (n > 1 && n-1 == a) || base+a > 50000 {
		Print(-1)
		return
	}
	Print(1)
	if n == 1 {
		return
	}
	for i := uint(1); i <= b; i++ {
		Print(" ", 1<<i)
	}
	if b == 0 {
		Print(" ", 1)
		n--
	}
	for i := uint(1); i <= a; i++ {
		Print(" ", base+i)
	}
	for n -= a + b + 1; n > 0; n-- {
		Print(" ", 1)
	}
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/148/C

package main

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

type PrincessReaction struct {
	Ohs  int
	Wows int
}

func validate(t []int) PrincessReaction {
	totalSum := 1
	maxSoFar := 1
	wows := 0
	ohs := 0
	for i := 1; i < len(t); i++ {
		if t[i] > totalSum {
			wows += 1
		} else if t[i] > maxSoFar {
			ohs += 1
		}
		if t[i] > maxSoFar {
			maxSoFar = t[i]
		}
		totalSum += t[i]
	}
	return PrincessReaction{Ohs: ohs, Wows: wows}
}

func Solve(n, a, b int) []int {
	result := []int{1}
	ohs := 0
	wows := 0
	maxSoFar := 1
	totalSum := 1
	noWows := b == 0
	for i := 1; i < n; i++ {
		if wows < b {
			maxSoFar *= 2
			totalSum += maxSoFar
			wows += 1
			result = append(result, maxSoFar)
		} else if ohs < a && noWows {
			noWows = false
			totalSum += 1
			result = append(result, 1)
		} else if ohs < a {
			maxSoFar += 1
			totalSum += maxSoFar
			ohs += 1
			result = append(result, maxSoFar)
		} else {
			result = append(result, 1)
		}
	}
	reaction := validate(result)
	if reaction.Ohs != a || reaction.Wows != b {
		return []int{-1}
	}
	return result
}

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

	var n, a, b int
	fmt.Fscanf(reader, "%d %d %d\n", &n, &a, &b)

	for _, elem := range Solve(n, a, b) {
		fmt.Fprintf(writer, "%d ", elem)
	}
	fmt.Fprintf(writer, "\n")
}

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n, a, b uint
	Scan(&n, &a, &b)
	base := uint(1) << b
	if base+a > 50000 {
		Print(-1)
		return
	}
	Print(1)
	for i := uint(1); i <= b; i++ {
		Print(" ", 1<<i)
	}
	for i := uint(1); i <= a; i++ {
		Print(" ", base+i)
	}
	for n -= a + b + 1; n > 0; n-- {
		Print(" ", 1)
	}
}

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n, a, b uint
	Scan(&n, &a, &b)
	base := uint(1) << b
	if (n > 1 && n-1 == a) || base+a > 50000 {
		Print(-1)
		return
	}
	Print(1)
	for i := uint(1); i <= b; i++ {
		Print(" ", 1<<i)
	}
	for i := uint(1); i <= a; i++ {
		Print(" ", base+i)
	}
	for n -= a + b + 1; n > 0; n-- {
		Print(" ", 1)
	}
}


Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.

On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".

NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.

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

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

		if x%2 == 0 && y%2 == 0 || x%2 != 0 && y%2 != 0 {
			fmt.Fprintln(out, "Alice")
		} else {
			fmt.Fprintln(out, "Bob")
		}
	}
}

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

		var sum, t int64
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &t)
			sum += t
		}
		sum += x

		if sum % 2 == 0 && y % 2 == 0 || sum % 2 != 0 && y % 2 != 0 {
			fmt.Fprintln(out, "Alice")
		} else {
			fmt.Fprintln(out, "Bob")
		}

	}
}

package main

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

/*

 */

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

	for i := 0; i < int(n); i++ {
		var a int64
		scanf("%d", &a)

		x ^= a
	}
	scanf("\n")

	if x%2 == y%2 {
		fmt.Fprintln(writer, "Alice")
	} else {
		fmt.Fprintln(writer, "Bob")
	}
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var tests int
	fmt.Fscan(in, &tests)
	for t := 0; t < tests; t++ {
		var n, x, y int64
		fmt.Fscan(in, &n, &x, &y)
		v := make([]int64, n)
		for i := range v {
			fmt.Fscan(in, &v[i])
		}
		var sum int64
		for _, q := range v {
			sum += q
		}
		if (sum+x+y)%2 == 0 {
			fmt.Println("Alice")
		} else {
			fmt.Println("Bob")
		}
	}
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n int
		var a, y int64
		fmt.Fscan(in, &n, &a, &y)
		sum := a
		for i := 0; i < n; i++ {
			var num int64
			fmt.Fscan(in, &num)
			sum += num
		}
		if (sum+y)%2 == 0 {
			fmt.Fprintln(out, "Alice")
		} else {
			fmt.Fprintln(out, "Bob")
		}
	}
}

// 1 0 1 2

package main

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	// arr := make([]int, 1e5+10)
	var T int
	var n int
	var x, y int64
	var v int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &x, &y)
		for i := 0; i < n; i++ {
			Fscan(in, &v)
			x ^= v
		}
		if x&1 == y&1 {
			Fprintln(out, "Alice")
		} else {
			Fprintln(out, "Bob")
		}
	}

}

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

package main

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

const MOD int64 = 1000000007

var n int
var x, y int64

var a[]int64

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

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

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n, &x, &y)

		a = make([]int64, n)

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

		fmt.Println(solve())
	}
}

type pair struct {
	v int
	idx []int
}

func solve() string {
	al := x

	var sum = al

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

	r1 := sum % 2
	r2 := y % 2

	if r1 == r2 {
		return "Alice"
	}
	return "Bob"
}

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

package main

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

const (
	MOD int64 = 1e9+7
	NL byte = byte('\n')
	SP byte = byte(' ')
)

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

	n, x int
	y int64
	a [100000]int64
	resS [2]string = [2]string{"Alice", "Bob"}
	res int
)

func main() {
	initBuffer()
	var t int = 1
	t = getInt()
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {

}

func input() {
	n = getInt()
	x = getInt()
	y = getInt64()
	for i := 0; i < n; i++ {
		a[i] = getInt64()
	}
}

func count() {
	res = x % 2
	for i := 0; i < n; i++ {
		if a[i] % 2 == 1 {
			res = 1 - res
		}
	}
	if res == int(y % 2) {
		res = 0
	} else {
		res = 1
	}
}

func output() {
	out.WriteString(resS[res])
	out.WriteByte(NL)
}

func test() {
	fmt.Print()
}

func initBuffer() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	in.Split(scanWords)
	out = bufio.NewWriter(os.Stdout)
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	i := bytes.IndexByte(data, '\n')
	j := bytes.IndexByte(data, ' ')
	ind := min(i, j)
	if ind < 0 {
		ind = max(i, j)
	}
	if ind >= 0 {
		return ind + 1, dropCR(data[0:ind]), nil
	}
	if atEOF {
		return len(data), dropCR(data), nil
	}
	return 0, nil, nil
}

func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[:len(data)-1]
	}
	return data
}

func getFloat() float64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res1 int64
	for i := 0; i < len(b); i++ {
		if b[i] == '.' {
			b = b[i+1:]
			break
		}
		res1 *= 10
		res1 += int64(b[i]) - 48
		if i == len(b) - 1 {
			b = b[:0]
		}
	}
	var res2 float64
	for i := len(b); i > 0; i-- {
		res2 += float64(b[i-1]) - 48
		res2 /= 10
	}
	if isNeg {
		res1 *= -1
		res2 *= -1
	}
	return float64(res1) + res2
}

func getInt() int {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getInt64() int64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int64
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int64(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getString() string {
	in.Scan()
	return in.Text()
}

func intToBytes(n int) []byte {
	var res [33]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 33
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 33 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func int64ToBytes(n int64) []byte {
	var res [65]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 65
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 65 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	if n1 > n2 {
		return n1
	}
	return n2
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	if n1 < n2 {
		return n1
	}
	return n2
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(arr[ind])
	out.WriteByte(NL)
	return res
}

package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }
func assert(f bool) {
	if !f {
		panic("gg")
	}
}

// ----------------------------- TEMPLATE END ----------------------------------

func main() {
	defer flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		var n int
		var x, y, ai int64
		scan(&n, &x, &y)
		x %= 2
		y %= 2
		for i := 0; i < n; i++ {
			scan(&ai)
			if ai%2 == 1 {
				x ^= 1
			}
		}
		if x == y {
			printf("Alice\n")
		} else {
			printf("Bob\n")
		}
	}
}

package main

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

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

	solve := func(curCase int) {
		var n, v int
		var x, y int64
		Fscan(in, &n, &x, &y)
		s := 0
		for i := 0; i < n; i++ {
			Fscan(in, &v)
			s ^= v & 1
		}
		if s == 0 {
			if x&1 == y&1 {
				Fprintln(out, "Alice")
			} else {
				Fprintln(out, "Bob")
			}
		} else {
			if x&1 != y&1 {
				Fprintln(out, "Alice")
			} else {
				Fprintln(out, "Bob")
			}
		}
	}

	cases := 1
	Fscan(in, &cases)
	for curCase := 1; curCase <= cases; curCase++ {
		solve(curCase)
	}

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

}

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

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

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

		for i := 0; i < n; i++ {
			if x+arr[i] > y {
				x ^= arr[i]
			} else {
				x += arr[i]
			}
		}

		if x != y {
			fmt.Fprintln(out, "Bob")
		} else {
			fmt.Fprintln(out, "Alice")
		}
	}
}

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

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

		var isWinner bool
		for i := n - 1; i >= 0; i-- {
			if (sum^xor)+x == y {
				isWinner = true
				break
			}

			xor ^= arr[i]
			sum -= arr[i]
		}

		if !isWinner && x^xor == y {
			isWinner = true
		}

		if !isWinner {
			fmt.Fprintln(out, "Bob")
		} else {
			fmt.Fprintln(out, "Alice")
		}
	}
}

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

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

		winner := -1
		var xor int64
		for i := 0; i < n; i++ {
			if (x+sum)^xor == y {
				winner = 0
				break
			} else if (x+sum+3)^xor == y {
				winner = 1
				break
			}

			sum -= arr[n-1-i]
			xor ^= arr[n-1-i]
		}

		if winner == 0 || x^xor == y {
			fmt.Fprintln(out, "Alice")
		} else if winner == 1 || (x+3)^xor == y {
			fmt.Fprintln(out, "Bob")
		} else {
			fmt.Fprintln(out, "Alice")
		}
	}
}

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

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

		winner := 0
		var xor int64
		for i := 0; i <= n; i++ {
			if (x+sum)^xor == y {
				break
			} else if (x+sum+3)^xor == y {
				winner = 1
				break
			}

			if n-1-i >= 0 {
				sum -= arr[n-1-i]
				xor ^= arr[n-1-i]
			}
		}

		if winner == 0 {
			fmt.Fprintln(out, "Alice")
		} else {
			fmt.Fprintln(out, "Bob")
		}
	}
}

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

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

		winner := 0
		var xor int64
		for i := 0; i < n; i++ {
			if (x+sum)^xor == y {
				break
			} else if (x+sum+3)^xor == y {
				winner = 1
				break
			}

			sum -= arr[n-1-i]
			xor ^= arr[n-1-i]
		}

		if winner == 0 {
			fmt.Fprintln(out, "Alice")
		} else {
			fmt.Fprintln(out, "Bob")
		}
	}
}

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

		sum, t := x, int64(0)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &t)
			sum += t
		}

		if x % 2 == 0 && y % 2 == 0 || x % 2 != 0 && y % 2 != 0 {
			fmt.Fprintln(out, "Alice")
		} else {
			fmt.Fprintln(out, "Bob")
		}

	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var tests int
	fmt.Fscan(in, &tests)
	for t := 0; t < tests; t++ {
		var n, x, y int
		fmt.Fscan(in, &n, &x, &y)
		v := make([]int, n)
		for i := range v {
			fmt.Fscan(in, &v[i])
		}
		sum := 0
		for _, x := range v {
			sum += x
		}
		if (sum + x + y) % 2 == 0 {
			fmt.Print("Alice\n")
		} else {
			fmt.Print("Bob\n")
		}
	}
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n int
		var a, y int64
		fmt.Fscan(in, &n, &a, &y)
		sum := a
		for i := 0; i < n; i++ {
			var num int64
			fmt.Fscan(in, &num)
			sum += num
		}
		if (sum+a+y)%2 == 0 {
			fmt.Fprint(out, "Alice")
		} else {
			fmt.Fprint(out, "Bob")
		}
	}
}

// 1 0 1 2

package main

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	// arr := make([]int, 1e5+10)
	var T int
	var n, x, y int
	var v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &x, &y)
		for i := 0; i < n; i++ {
			Fscan(in, &v)
			x ^= v
		}
		if x&1 == y&1 {
			Fprintln(out, "Alice")
		} else {
			Fprintln(out, "Bob")
		}
	}

}

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


You are given an array $$$a$$$ of length $$$n$$$. We define the equality of the array as the number of indices $$$1 \le i \le n - 1$$$ such that $$$a_i = a_{i + 1}$$$. We are allowed to do the following operation:  Select two integers $$$i$$$ and $$$x$$$ such that $$$1 \le i \le n - 1$$$ and $$$1 \le x \le 10^9$$$. Then, set $$$a_i$$$ and $$$a_{i + 1}$$$ to be equal to $$$x$$$. Find the minimum number of operations needed such that the equality of the array is less than or equal to $$$1$$$.

Each test contains 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 the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10 ^ 5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10 ^ 5$$$

For each test case, print the minimum number of operations needed.

NoteIn the first test case, we can select $$$i=2$$$ and $$$x=2$$$ to form $$$[1, 2, 2, 1, 1]$$$. Then, we can select $$$i=3$$$ and $$$x=3$$$ to form $$$[1, 2, 3, 3, 1]$$$.In the second test case, we can select $$$i=3$$$ and $$$x=100$$$ to form $$$[2, 1, 100, 100, 2]$$$.

package main

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

var in = bufio.NewReader(os.Stdin)

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

	a := -1
	b := -1

	arr := make([]int, n)
	for i := 0; i < n; i += 1 {
		fmt.Fscan(in, &arr[i])

		if i > 0 {
			if arr[i-1] == arr[i] {
				if a == -1 {
					a = i
				} else {
					b = i - 1
				}
			}
		}
	}

	if b == -1 {
		fmt.Printf("0\n")
	} else if a == b {
		fmt.Printf("1\n")
	} else {
		fmt.Printf("%d\n", b-a)
	}
}

func main() {
	var n int
	fmt.Fscan(in, &n)

	for i := 0; i < n; i += 1 {
		solve()
	}
}

package main

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

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

func solve() int {
	var n, x int
	fmt.Fscan(in, &n)

	ar := make([]int, 0, 0)

	for i := 0; i < n; i++ {
		fmt.Fscan(in, &x)
		ar = append(ar, x)
	}

	var L, R int = -1, -1

	for i := 0; i < n-1; i++ {
		if ar[i] == ar[i+1] {
			R = i
			if L == -1 {
				L = i
			}
		}
	}

	if R == L {
		return 0
	}

	if R-L-1 > 1 {
		return R - L - 1
	}
	return 1
}

func main() {
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		fmt.Fprintln(out, solve())
	}
}

package main

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

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var t int
	Fscan(in, &t)

	for tt := 0; tt < t; tt++ {
		var n int
		Fscan(in, &n)
		a := make([]Int, n)
		b := make([]Int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		cnt := L0
		mx := L0
		first := -1
		last := -1
		b[0] = 1
		for i := 1; i < n; i++ {
			if a[i] == a[i-1] {
				b[i] = b[i-1] + 1
				if b[i] == 2 {
					cnt++
					if cnt == 1 {
						first = i
					}
				}
				if b[i] > mx {
					mx = b[i]
				}
				if b[i] >= 2 {
					last = i
				}
			} else {
				b[i] = 1
			}
		}

		ans := L0
		if cnt == 1 {
			if mx > 2 {
				ans = Max(1, mx-3)
			}
		} else if cnt > 1 {
			ans = Int(last - 1 - first)
		}

		Fprintln(out, ans)

	}

}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

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

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

		l, r := -1, -1
		for i := 1; i < n; i++ {
			if arr[i-1] == arr[i] && l < 0 {
				l = i - 1
			} else if arr[i-1] == arr[i] {
				r = i
			}
		}

		if l < 0 || r < 0 {
			fmt.Fprintln(out, 0)
		} else if (r - l + 1) <= 4 {
			fmt.Fprintln(out, 1)
		} else {
			fmt.Fprintln(out, r-l+1-3)
		}
	}
}

package main

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

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

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

	for ; t > 0; t-- {
		var n int
		fmt.Fscanf(in, "%d\n", &n)

		arr := make([]int, n)

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

		max := -1
		min := -1
		for i := 1; i < n; i++ {
			if arr[i] == arr[i - 1] {
				if min == -1 {
					min = i
				}
				max = i
			}
		}
		if min == max {
			fmt.Fprintln(out, 0)
		} else {
			fmt.Fprintln(out, math.Max(1, float64(max - min - 1)))
		}
	}
}

package main

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

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

var T int
var N int

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

	fmt.Fscan(in, &T)
	for ; T > 0; T-- {
		fmt.Fscan(in, &N)
		a := make([]int, N)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		left, right := -1, -1
		e_cnt := 0
		for i := 0; i < N-1; i++ {
			if a[i] == a[i+1] {
				e_cnt++
				if left == -1 {
					left = i
				}
				right = i + 1
			}
		}
		length := right - left + 1
		if length-2 < 0 || e_cnt <= 1 {
			fmt.Fprintln(out, 0)
		} else {
			fmt.Fprintln(out, max(1, length-2-1))
		}
	}
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var s int
		fmt.Fscan(in, &s)
		nums := make([]int, s)
		for i := 0; i < s; i++ {
			fmt.Fscan(in, &nums[i])
		}
		var n [][]int
		count := 1
		for i := 1; i < s; i++ {
			if nums[i] == nums[i-1] {
				count++
				if i == s-1 {
					n = append(n, []int{i - count + 1, count})
					count = 0
				}
			} else {
				if count > 1 {
					n = append(n, []int{i - count, count})
				}
				count = 1
			}
		}
		//fmt.Println(n)
		if len(n) == 0 {
			fmt.Fprintln(out, "0")
			continue
		}
		if len(n) == 1 {
			c := n[0][1]
			if c == 2 {
				fmt.Fprintln(out, 0)
			} else if c == 3 {
				fmt.Fprintln(out, 1)
			} else {
				fmt.Fprintln(out, c-3)
			}
			continue
		}

		fmt.Fprintln(out, n[len(n)-1][0]+n[len(n)-1][1]-2-n[0][0]-1)
	}
}

package main

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

func calculateEquality(input []int) int {
	length := len(input)
	result := 0
	for i := 0; i < length-1; i++ {
		if input[i] == input[i+1] {
			result++
		}
	}
	return result
}
func oneIfEqual(a, b int) int {
	if a == b {
		return 1
	}
	return 0
}
func solve(input []int) int {
	length := len(input)
	if length <= 2 {
		return 0
	}
	equality := calculateEquality(input)
	replacement := 0
	changes := 0
	shouldChange := func(index int) bool {
		if index <= 0 || index >= length-1 {
			return false
		}
		return input[index-1] == input[index]
	}
	makeChange := func(index int) {
		if index <= 0 || index >= length-1 {
			return
		}
		dif := 0
		if index <= length-3 {
			a := input[index-1]
			b := input[index]
			c := input[index+1]
			d := input[index+2]
			dif = (oneIfEqual(a, replacement) + oneIfEqual(replacement, replacement) + oneIfEqual(replacement, d)) - (oneIfEqual(a, b) + oneIfEqual(b, c) + oneIfEqual(c, d))
		} else {
			// index == length-2
			a := input[index-1]
			b := input[index]
			c := input[index+1]
			dif = (oneIfEqual(a, replacement) + oneIfEqual(replacement, replacement)) - (oneIfEqual(a, b) + oneIfEqual(b, c))
		}
		input[index] = replacement
		input[index+1] = replacement
		changes++
		replacement--
		equality += dif
	}
	for i := 0; i < length && equality > 1; i++ {
		if shouldChange(i) {
			makeChange(i)
		}
	}
	return changes
}

func main() {
	input := bufio.NewReader(os.Stdin)
	t := readInt(input)
	for i := 0; i < t; i++ {
		readInt(input)
		arr := readArrInt(input)
		solution := solve(arr)
		fmt.Println(solution)
	}
}

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

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

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

package main

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

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

	var T, n, pre, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &pre)
		p := []int{}
		for i := 1; i < n; i++ {
			if Fscan(in, &v); v == pre {
				p = append(p, i)
			}
			pre = v
		}
		if len(p) < 2 {
			Fprintln(out, 0)
		} else {
			ans := p[len(p)-1] - p[0] - 1
			if ans < 1 {
				ans = 1
			}
			Fprintln(out, ans)
		}
	}
}

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

package main

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

/*
3
4
3 1 5 3
6
2 1 1 2 1 4
7
0 1 1 1 5 0 0
---
0
0
3 = 0 1 2 3 4 4 0
========
6
2
1 1
3
1 1 1
4
1 1 1 1
5
1 1 1 1 1
6
1 1 1 1 1 1
7
1 1 1 1 1 1 1
---
0
1 = 1 2 2
1 = 1 2 2 1
2 = 1 2 3 3 1
3 = 1 2 4 4 3 1 or 1 2 3 4 4 1
4 = 1 2 3 4 5 5 1 or 1 2 4 5 5 3 1
==========
2
4
1 1 2 2
10
1 2 2 3 4 5 6 7 7 8
---
2
5 = 1 2 10 11 12 13 14 14 7 8
*/

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

	a := make([]int, n)

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

	equalityCnt := 0
	firstEqualityIdx := -1
	lastEqualityIdx := -1

	for i, lft := range a[:n-1] {
		rht := a[i+1]
		if lft == rht {
			equalityCnt++

			if equalityCnt == 1 {
				firstEqualityIdx = i
			}

			lastEqualityIdx = i
		}
	}

	if equalityCnt <= 1 {
		fmt.Fprintln(writer, 0)
		return
	}

	if abs(lastEqualityIdx-firstEqualityIdx) == 1 {
		fmt.Fprintln(writer, 1)
		return
	}

	fmt.Fprintln(writer, lastEqualityIdx-firstEqualityIdx-1)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnusedFunction
func factorize(num int) []int {
	factors := []int{1}

	sqrtA := int(math.Sqrt(float64(num)))

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

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

	return factors
}

package main

import "fmt"

func solve() {
	var n int
	_, _ = fmt.Scanf("%d\n", &n)

	a := -1
	b := -1

	arr := make([]int, n)
	for i := 0; i < n; i += 1 {
		_, _ = fmt.Scan(&arr[i])

		if i > 0 {
			if arr[i-1] == arr[i] {
				if a == -1 {
					a = i
				} else {
					b = i - 1
				}
			}
		}
	}

	if b == -1 {
		fmt.Printf("0\n")
	} else if a == b {
		fmt.Printf("1\n")
	} else {
		fmt.Printf("%d\n", b-a)
	}
}

func main() {
	var n int
	_, _ = fmt.Scanf("%d\n", &n)

	for i := 0; i < n; i += 1 {
		solve()
	}
}

package main

import "fmt"

func solve() {
	var n int
	_, _ = fmt.Scanf("%d\n", &n)

	a := -1
	b := -1

	arr := make([]int, n)
	for i := 0; i < n; i += 1 {
		_, _ = fmt.Scanf("%d", &arr[i])

		if i > 0 {
			if arr[i-1] == arr[i] {
				if a == -1 {
					a = i
				} else {
					b = i - 1
				}
			}
		}
	}

	if b == -1 {
		fmt.Printf("0\n")
	} else if a == b {
		fmt.Printf("1\n")
	} else {
		fmt.Printf("%d\n", b-a)
	}
}

func main() {
	var n int
	_, _ = fmt.Scanf("%d\n", &n)

	for i := 0; i < n; i += 1 {
		solve()
	}
}

package main

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

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

func solve() int {
	var n, x int
	fmt.Fscan(in, &n)

	ar := make([]int, 0, 0)

	for i := 0; i < n; i++ {
		fmt.Fscan(in, &x)
		ar = append(ar, x)
	}

	var cnt int = 0

	for i := 1; i < n; i++ {
		if ar[i] == ar[i-1] {
			cnt++
		}
	}
	if cnt <= 1 {
		return 0
	}
	cnt = 0

	for i := 1; i < n; i++ {
		if ar[i] == ar[i-1] {
			cnt++
			i += 2
		}
	}
	return cnt
}

func main() {
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		fmt.Fprintln(out, solve())
	}
}

package main

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

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

func solve() int {
	var n, x int
	fmt.Fscan(in, &n)

	ar := make([]int, 0, 0)

	for i := 0; i < n; i++ {
		fmt.Fscan(in, &x)
		ar = append(ar, x)
	}

	var cnt int = 0

	for i := 1; i < n; i++ {
		if ar[i] == ar[i-1] {
			cnt++
		}
	}
	if cnt <= 1 {
		return 0
	}
	cnt = 0

	for i := 1; i < n; i++ {
		if ar[i] == ar[i-1] {
			cnt++
			i++
		}
	}
	return cnt
}

func main() {
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		fmt.Fprintln(out, solve())
	}
}

package main

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

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

func solve() int {
	var n, x int
	fmt.Fscan(in, &n)

	ar := make([]int, 0, 0)

	for i := 0; i < n; i++ {
		fmt.Fscan(in, &x)
		ar = append(ar, x)
	}

	var cnt int = 0
	for i := 1; i < n; i++ {
		if ar[i] == ar[i-1] {
			cnt++
			i++
		}
	}
	return cnt
}

func main() {
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		fmt.Fprintln(out, solve())
	}
}

package main

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

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var t int
	Fscan(in, &t)

	for tt := 0; tt < t; tt++ {
		var n int
		Fscan(in, &n)
		last := -1
		cnt := 1
		ans := 0
		num := 0
		for i := 0; i <= n; i++ {
			var x int
			if i < n {
				Fscan(in, &x)
			}

			if x == last {
				cnt++
			} else {
				if cnt > 1 {
					num++
				}
				if cnt > 2 {
					ans += int(Max(Int(cnt-3), L1))
				}
				cnt = 1
			}
			last = x
		}
		if num > 1 {
			ans += num
		}
		Fprintln(out, ans)

	}

}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

package main

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

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var t int
	Fscan(in, &t)

	for tt := 0; tt < t; tt++ {
		var n int
		Fscan(in, &n)
		last := -1
		mx := -1
		cnt := 1
		ans := 0
		for i := 0; i < n; i++ {
			var x int
			Fscan(in, &x)

			if x == last {
				cnt++
				if cnt > mx {
					mx = cnt
				}
			} else {
				ans += cnt - 1
				cnt = 1
			}
			last = x
		}
		ans += cnt - 1
		if mx > 1 {
			ans = ans - (mx - 1)
			ans += int(Max(Int(mx-3), Int(1)))
		}
		Fprintln(out, ans)

	}

}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

package main

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

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var t int
	Fscan(in, &t)

	for tt := 0; tt < t; tt++ {
		var n int
		Fscan(in, &n)
		last := -1
		mx := -1
		cnt := 1
		ans := 0
		for i := 0; i < n; i++ {
			var x int
			Fscan(in, &x)

			if x == last {
				cnt++
				if cnt > mx {
					mx = cnt
				}
			} else {
				ans += cnt - 1
				cnt = 1
			}
			last = x
		}
		ans += cnt - 1
		if mx > 1 {
			ans = ans - (mx - 1) + mx/2
		}
		Fprintln(out, ans)

	}

}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

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

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

		l, r := -1, -1
		for i := 1; i < n; i++ {
			if arr[i-1] == arr[i] && l < 0 {
				l = i - 1
			} else if arr[i-1] == arr[i] {
				r = i
			}
		}

		if l < 0 || r < 0 {
			fmt.Fprintln(out, 0)
		} else {
			fmt.Fprintln(out, (r-l+1)/2)
		}
	}
}

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

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

		l, r := -1, -1
		for i := 1; i < n; i++ {
			if arr[i-1] == arr[i] && l < 0 {
				l = i - 1
			} else if arr[i-1] == arr[i] {
				r = i
			}
		}

		if l < 0 || r < 0 {
			fmt.Fprintln(out, 0)
		} else {
			fmt.Fprintln(out, (r-l)/2)
		}
	}
}

package main

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

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

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

	for ; t > 0; t-- {
		var n int
		fmt.Fscanf(in, "%d\n", &n)

		ans := 0
		count := 0
		prev := 0

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

			if num == prev && i != n - 1 {
				count++
				continue
			}

			ans += count / 2
			count = 1
			prev = num
		}

		fmt.Fscanf(in, "\n")

		fmt.Fprintln(out, ans)
	}
}

package main

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

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

var T int
var N int

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

	fmt.Fscan(in, &T)
	for ; T > 0; T-- {
		fmt.Fscan(in, &N)
		a := make([]int, N)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		left, right := -1, -1
		for i := 0; i < N-1; i++ {
			if a[i] == a[i+1] {
				if left == -1 {
					left = i
				}
				right = i + 1
			}
		}
		length := right - left + 1
		if length-2 < 0 {
			fmt.Fprintln(out, 0)
		} else {
			fmt.Fprintln(out, max(1, length-2-1))
		}
	}
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var s int
		fmt.Fscan(in, &s)
		nums := make([]int, s)
		for i := 0; i < s; i++ {
			fmt.Fscan(in, &nums[i])
		}
		var n [][]int
		count := 1
		for i := 1; i < s; i++ {
			if nums[i] == nums[i-1] {
				count++
				if i == s-1 {
					n = append(n, []int{i, count})
					count = 0
				}
			} else {
				if count > 1 {
					n = append(n, []int{i - count, count})
				}
				count = 1
			}
		}
		//fmt.Println(n)
		if len(n) == 0 {
			fmt.Fprintln(out, "0")
			continue
		}
		if len(n) == 1 {
			c := n[0][1]
			if c == 2 {
				fmt.Fprintln(out, 0)
			} else if c == 3 {
				fmt.Fprintln(out, 1)
			} else {
				fmt.Fprintln(out, c-3)
			}
			continue
		}

		fmt.Fprintln(out, n[len(n)-1][0]+n[len(n)-1][1]-2-n[0][0]-1)
	}
}


Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion: An 'L' indicates he should move one unit left.  An 'R' indicates he should move one unit right.  A 'U' indicates he should move one unit up.  A 'D' indicates he should move one unit down.But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in s with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string.

The first and only line contains the string s (1 ≤ |s| ≤ 100 000) — the instructions Memory is given.

If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1.

NoteIn the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change s to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin.

package main

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

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

	var s string
	fmt.Fscanf(buf, "%s\n", &s)

	n := len(s)
	u := 0
	d := 0
	l := 0
	r := 0
	for i := 0; i < n; i++ {
		c := s[i]
		if c == 'U' {
			u++
		} else if c == 'D' {
			d++
		} else if c == 'L' {
			l++
		} else if c == 'R' {
			r++
		}
	}

	if u < d {
		u, d = d, u
	}

	if l < r {
		l, r = r, l
	}

	res := 0
	for u-1 >= d+1 {
		res++
		u--
		d++
	}

	for l-1 >= r+1 {
		res++
		l--
		r++
	}

	x := u - d
	y := l - r

	if x != y {
		fmt.Printf("-1\n")
	} else {
		if x == 1 {
			res++
		}
		fmt.Printf("%d\n", res)
	}
}

// http://codeforces.com/contest/712/problem/B
package main

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

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

func main () {
	var str string

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &str)

	if len(str) % 2 != 0 {
		fmt.Println(-1)
		return
	}

	x := 0;
	y := 0;

	for i := 0; i < len(str); i++ {
		switch str[i] {
		case 'U': y++;
		case 'D': y--;
		case 'R': x++;
		case 'L': x--;
		}
	}

	fmt.Println(math.Abs(float64(x)) / 2 + math.Abs(float64(y)) / 2)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)

	if s, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		s = re.ReplaceAllString(s, "")

		directions := map[rune]int{}
		for _, r := range s {
			directions[r] += 1
		}

		xd := abs(directions['R'] - directions['L'])
		yd := abs(directions['U'] - directions['D'])

		if (xd+yd)%2 != 0 {
			fmt.Println(-1)
		} else {
			fmt.Println((xd + yd) / 2)
		}
	}
}

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

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")

	u := 0
	d := 0
	l := 0
	r := 0
	if len(text)%2 != 0 {
		fmt.Println(-1)
	} else {
		for _, v := range text {
			if v == 'U' {
				u++
			}
			if v == 'D' {
				d++
			}
			if v == 'L' {
				l++
			}
			if v == 'R' {
				r++
			}
		}

		U := u - d
		if U < 0 {
			U = 0 - U
		}
		L := l - r
		if L < 0 {
			L = 0 - L
		}
		if U > L {
			v := U - L
			v = (v / 2) + L
			fmt.Println(v)
		} else {
			v := L - U
			v = (v / 2) + U
			fmt.Println(v)
		}
	}

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")

	u := 0
	d := 0
	l := 0
	r := 0
	if len(text)%2 != 0 {
		fmt.Println(-1)
	} else {
		for _, v := range text {
			if v == 'U' {
				u++
			}
			if v == 'D' {
				d++
			}
			if v == 'L' {
				l++
			}
			if v == 'R' {
				r++
			}
		}

		U := u - d
		if U < 0 {
			U = 0 - U
		}
		L := l - r
		if L < 0 {
			L = 0 - L
		}
		if U > L {
			fmt.Println(U)
		} else {
			fmt.Println(L)
		}
	}

}


A process RAM is a sequence of bytes that are indexed from 1 to n. Polycarpus's program contains such instructions as "memset", that is, the operations of filling memory cells on a segment with some value. The details are: the code only contains m instructions that look like "set13 a_i l_i". Instruction i fills a continuous memory segment of length li, starting from cell number ai, (that it cells with numbers ai, ai + 1, ..., ai + li - 1) with values 13.In Polycarpus's code, the optimizer's task is to remove the maximum number of instructions from his code in such a way that the remaining instructions set value 13 in all the memory bytes that got this value from the code before the optimization. Also, the value 13 should be set only in the memory bytes that got this value from the code before the optimization. Your task is to implement the optimizer for such program.

The first line contains integers n and m (1 ≤ n ≤ 2·106, 1 ≤ m ≤ 2·105) — the number of bytes (memory cells) and the number of instructions in Polycarpus's code. Then m lines follow, each line contains a pair of integers ai, li (1 ≤ ai ≤ n, 1 ≤ li ≤ n - ai + 1).

Print in the first line the sought maximum number of instructions that can be removed from the code. In the second line print the numbers of the instructions. The instructions are numbered from 1 to m in the order they appeared in the input. If there are multiple solutions, print any of them.

package main

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

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
var line []int

func readInts() []int {
	line, _ := in.ReadString('\n')
	words := strings.Fields(line)
	a := make([]int, len(words))
	for i := range a {
		a[i], _ = strconv.Atoi(words[i])
	}
	return a
}

func writeInt(x int, end byte) {
	out.WriteString(strconv.Itoa(x))
	out.WriteByte(end)
}

type Item struct {
	s, e, id int
}

type ItemSlice []Item

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

func main() {
	defer out.Flush()
	line = readInts()
	n, m := line[0], line[1]
	a := make(ItemSlice, m)
	cov := make([]int, n+2)
	mem := make([]bool, m)
	for i := range a {
		line = readInts()
		x, y := line[0], line[1]
		a[i] = Item{x, x + y, i}
		cov[x]++
		cov[x+y]--
	}
	for i := 1; i <= n; i++ {
		cov[i] += cov[i-1]
	}
	sort.Sort(a)
	cnt := 0
	for i, j := 1, 0; i <= n; {
		if cov[i] > 0 {
			var farest, id int
			for ; j < m && a[j].s <= i; j++ {
				if a[j].e > farest {
					farest = a[j].e
					id = a[j].id
				}
			}
			i = farest
			mem[id] = true
			cnt++
		} else {
			i++
		}
	}
	writeInt(m-cnt, '\n')
	for i, v := range mem {
		if !v {
			writeInt(i+1, ' ')
		}
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)
var line []int

func readInts() []int {
	line, _ := in.ReadString('\n')
	words := strings.Fields(line)
	a := make([]int, len(words))
	for i := range a {
		a[i], _ = strconv.Atoi(words[i])
	}
	return a
}

type Item struct {
	s, e, id int
}

type ItemSlice []Item

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

func main() {
	line = readInts()
	n, m := line[0], line[1]
	a := make(ItemSlice, m)
	mem := make([]bool, m)
	for i := range a {
		line = readInts()
		x, y := line[0], line[1]
		a[i] = Item{x, x + y - 1, i}
	}
	sort.Sort(a)
	for last, i := 1, 0; last <= n; {
		newLast := last
		id := -1
		for ; i < m && a[i].s <= last; i++ {
			if a[i].e >= newLast {
				newLast = a[i].e
				id = a[i].id
			}
		}
		if id == -1 {
			last++
		} else {
			mem[id] = true
			last = newLast
		}
	}
	cnt := 0
	for _, v := range mem {
		if !v {
			cnt++
		}
	}
	println(cnt)
	for i, v := range mem {
		if !v {
			print(i+1, " ")
		}
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
var line []int

func readInts() []int {
	line, _ := in.ReadString('\n')
	words := strings.Fields(line)
	a := make([]int, len(words))
	for i := range a {
		a[i], _ = strconv.Atoi(words[i])
	}
	return a
}

type Item struct {
	s, e, id int
}

type ItemSlice []Item

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

func main() {
	line = readInts()
	n, m := line[0], line[1]
	a := make(ItemSlice, m)
	mem := make([]bool, m)
	for i := range a {
		line = readInts()
		x, y := line[0], line[1]
		a[i] = Item{x, x + y - 1, i}
	}
	sort.Sort(a)
	for last, i := 1, 0; last <= n; {
		newLast := last
		id := -1
		for ; i < m && a[i].s <= last; i++ {
			if a[i].e >= newLast {
				newLast = a[i].e
				id = a[i].id
			}
		}
		if id == -1 {
			last++
		} else {
			mem[id] = true
			last = newLast
		}
	}
	cnt := 0
	for _, v := range mem {
		if !v {
			cnt++
		}
	}
	out.WriteString(strconv.Itoa(cnt))
	out.WriteByte('\n')
	for i, v := range mem {
		if !v {
			out.WriteString(strconv.Itoa(i + 1))
			out.WriteByte(' ')
		}
	}
	out.Flush()
}

package main

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

var in = bufio.NewReader(os.Stdin)
var line []int

func readInts() []int {
	line, _ := in.ReadString('\n')
	words := strings.Fields(line)
	a := make([]int, len(words))
	for i := range a {
		a[i], _ = strconv.Atoi(words[i])
	}
	return a
}

type Item struct {
	s, e, id int
}

type ItemSlice []Item

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

func main() {
	line = readInts()
	n, m := line[0], line[1]
	a := make(ItemSlice, m)
	mem := make([]bool, m)
	for i := range a {
		line = readInts()
		x, y := line[0], line[1]
		a[i] = Item{x, x + y - 1, i}
	}
	sort.Sort(a)
	for last, i := 1, 0; last <= n; {
		newLast := last
		id := -1
		for ; i < m && a[i].s <= last; i++ {
			if a[i].e >= newLast {
				newLast = a[i].e
				id = a[i].id
			}
		}
		if id == -1 {
			last++
		} else {
			mem[id] = true
			last = newLast
		}
	}
	cnt := 0
	for _, v := range mem {
		if !v {
			cnt++
		}
	}
	println(cnt)
	for i, v := range mem {
		if !v {
			print(i+1, " ")
		}
	}
	println()
}


You are given a $$$1$$$ by $$$n$$$ pixel image. The $$$i$$$-th pixel of the image has color $$$a_i$$$. For each color, the number of pixels of that color is at most $$$20$$$.You can perform the following operation, which works like the bucket tool in paint programs, on this image:   pick a color — an integer from $$$1$$$ to $$$n$$$;  choose a pixel in the image;  for all pixels connected to the selected pixel, change their colors to the selected color (two pixels of the same color are considered connected if all the pixels between them have the same color as those two pixels). Compute the minimum number of operations needed to make all the pixels in the image have the same color.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3\cdot10^3$$$) — the number of pixels in the image. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$) — the colors of the pixels in the image. Note: for each color, the number of pixels of that color is at most $$$20$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3\cdot10^3$$$.

For each test case, print one integer: the minimum number of operations needed to make all the pixels in the image have the same color.

NoteIn the first example, the optimal solution is to apply the operation on the third pixel changing its color to $$$2$$$ and then to apply the operation on any pixel that has color $$$2$$$ changing its color and the color of all pixels connected to it to $$$1$$$. The sequence of operations is then: $$$[1, 2, 3, 2, 1] \to [1, 2, 2, 2, 1] \to [1, 1, 1, 1, 1]$$$.In the second example, we can either change the $$$1$$$s to $$$2$$$s in one operation or change the $$$2$$$s to $$$1$$$s also in one operation.In the third example, one possible way to make all the pixels have the same color is to apply the operation on the first, third and the fourth pixel each time changing its color to $$$2$$$.

package main

import "fmt"

func main() {
    var n int16

    fmt.Scanln(&n)
    for ; n > 0; n-- {
        var l int
        fmt.Scanln(&l)
        var t int
        a := []int{}
        prev := map[int]int{}
        next := [3000]int{}
        for ; l > 0; l-- {
            fmt.Scan(&t)
            if len(a) == 0 || t != a[len(a) - 1] {
                a = append(a, t)
                if v, ok := prev[t]; ok {
                    next[v] = len(a) - 1
                }
                prev[t] = len(a) - 1
            }
        }
        k := len(a)

        fmt.Scanln()
        // fmt.Println(a)
        // fmt.Println(next[:k])

        dp := [][]int16{}
        for i := 0; i < k; i++ {
            dp = append(dp, []int16{})
            for j := 0; j < k; j++ {
                dp[i] = append(dp[i], 0)
            }
        }

        for d := 1; d < k; d++ {
            for i := 0; i + d < k; i++ {
                j := i + d
                if dp[i][j] < dp[i + 1][j] {
                    dp[i][j] = dp[i + 1][j]
                }
                if dp[i][j] < dp[i][j - 1] {
                    dp[i][j] = dp[i][j - 1]
                }
                for x := next[i]; x > 0 && x <= j; x = next[x] {
                    tmp := 1 + dp[i + 1][x - 1] + dp[x][j]
                    if dp[i][j] < tmp {
                        dp[i][j] = tmp
                    }
                }
            }
        }
        for i := 0; i < k; i++ {
            //fmt.Println(dp[i][:k])
        }
        fmt.Println(k - 1 - int(dp[0][k - 1]))
        // fmt.Println()
    }
}

// 1 2 3 2 1 4 1

package main

import "fmt"

var dp [3000][3000]int16

func main() {
    var n int16

    fmt.Scanln(&n)
    for ; n > 0; n-- {
        var l int
        fmt.Scanln(&l)
        var t int
        a := []int{}
        for ; l > 0; l-- {
            fmt.Scan(&t)
            if len(a) == 0 || t != a[len(a) - 1] {
                a = append(a, t)
            }
        }
        k := len(a)

        fmt.Scanln()
        // fmt.Println(a)

        dp = [3000][3000]int16{}

        for d := 1; d < k; d++ {
            for i := 0; i + d < k; i++ {
                j := i + d
                for x := i + 1; x <= j; x++ {
                    if a[i] == a[x] {
                        tmp := 1 + dp[i + 1][x - 1] + dp[x + 1][j - 1]
                        if dp[i][j] < tmp {
                            dp[i][j] = tmp
                        }
                    }
                }
                if dp[i][j] < dp[i + 1][j] {
                    dp[i][j] = dp[i + 1][j]
                }
            }
        }
        for i := 0; i < k; i++ {
            // fmt.Println(dp[i][:k])
        }
        fmt.Println(k - 1 - int(dp[0][k - 1]))
        // fmt.Println()
    }
}

// 1 2 3 2 1 4 1

package main

import "fmt"

func main() {
    var n int

    fmt.Scanln(&n)
    for ; n > 0; n-- {
        var l int
        fmt.Scanln(&l)
        var t int
        a := []int{}
        for ; l > 0; l-- {
            fmt.Scan(&t)
            if len(a) == 0 || t != a[len(a) - 1] {
                a = append(a, t)
            }
        }
        k := len(a)

        fmt.Scanln()

        ans := 0
        //fmt.Println(a)

        for ; k > 1; {
            prev := map[int]int{}
            var op []int
            barrier := 0
            min_d := k

            for i := 0; i < k; i++ {
                if p, ok := prev[a[i]]; ok {
                    d := i - p
                    if min_d > d {
                        min_d = d
                        op = []int{p}
                        barrier = i
                    } else if (min_d == d && p >= barrier) {
                        op = append(op, p)
                        barrier = i
                    }
                }
                prev[a[i]] = i
            }
            //fmt.Println(op, min_d)

            if min_d == k {
                ans += k - 1
                k = 1
            } else {
                j := 0
                var na []int
                for _, v := range op {
                    for ; j < v; j++ {
                        na = append(na, a[j])
                    }
                    if na == nil || a[v] != na[len(na) - 1] {
                        na = append(na, a[v])
                    }
                    ans += min_d - 1
                    j += min_d
                }
                for ; j < k; j++ {
                    if na == nil || a[j] != na[len(na) - 1] {
                        na = append(na, a[j])
                    }
                }
                //fmt.Println(na)
                a = na
                k = len(a)
            }
        }

        fmt.Println(ans)
        //fmt.Println()
    }
}

// 1 2 3 2 1 4 1

package main

import "fmt"

var a [3000]int
var m map[int]map[int]int

func f(l int, r int) int {
    if im, ok := m[l]; !ok {
        m[l] = map[int]int{}
    } else {
        if v, ok := im[r]; ok {
            return v
        }
    }

    if (l == r) {
        m[l][r] = 0
    } else if (l + 1 == r) {
        if a[l] != a[r] {
            m[l][r] = 1
        } else {
            m[l][r] = 0
        }
    } else {
        tmp := 999999
        for c := l; c < r; c++ {
            rl := f(l, c)
            rr := f(c + 1, r)
            if tmp > rl + rr + 1 {
                tmp = rl + rr + 1
            }
        }
        if a[l] == a[r] {
            rr := f(l + 1, r - 1)
            if tmp > rr {
                tmp = rr + 1
            }
        }
        m[l][r] = tmp
    }
    return m[l][r]
}

func main() {
    var n int
    fmt.Scanln(&n)
    for ; n > 0; n-- {
        var l int
        fmt.Scanln(&l)
        // fmt.Println(l)
        for i := 0; i < l; i++ {
            fmt.Scan(&a[i])
        }
        fmt.Scanln()
        //fmt.Println(a[:l])
        m = map[int]map[int]int{}
        fmt.Println(f(0, l - 1))
        //fmt.Println(m)
    }
}

// 1 2 3 2 1 4 1


Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noticed that the flowers stopped growing. The beaver thinks it is bad manners to present little flowers. So he decided to come up with some solutions. There are m days left to the birthday. The height of the i-th flower (assume that the flowers in the row are numbered from 1 to n from left to right) is equal to ai at the moment. At each of the remaining m days the beaver can take a special watering and water w contiguous flowers (he can do that only once at a day). At that each watered flower grows by one height unit on that day. The beaver wants the height of the smallest flower be as large as possible in the end. What maximum height of the smallest flower can he get?

The first line contains space-separated integers n, m and w (1 ≤ w ≤ n ≤ 105; 1 ≤ m ≤ 105). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Print a single integer — the maximum final height of the smallest flower.

NoteIn the first sample beaver can water the last 3 flowers at the first day. On the next day he may not to water flowers at all. In the end he will get the following heights: [2, 2, 2, 3, 2, 2]. The smallest flower has height equal to 2. It's impossible to get height 3 in this test.

package main

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

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 main() {
	in.Split(bufio.ScanWords)
	n, m, w := readInt(), readInt(), readInt()
	a := make([]int, n)
	max := 0
	for i := range a {
		a[i] = readInt()
		if a[i] > max {
			max = a[i]
		}
	}

	q := make([]int, 0, m)
	fmt.Println(sort.Search(max+m+1, func(minHeight int) bool {
		used := 0
		q := q
		for i := range a {
			for len(q) > 0 && q[0] == i {
				q = q[1:]
			}
			for len(q)+a[i] < minHeight {
				used++
				if used > m {
					return true
				}
				q = append(q, i+w)
			}
		}
		return used > m
	}) - 1)
}

package main

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

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

	var n, m, w int
	fmt.Fscanf(r, "%d %d %d\n", &n, &m, &w)

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

	fmt.Println(minMax(a, m, w))
}

func minMax(a []int, m, w int) int {
	var ret int

	lo, hi := 0, int(2e9)
	for lo <= hi {
		mid := int((int64(lo) + int64(hi)) / 2)
		b := make([]int, len(a))
		copy(b, a)

		can := true
		free := m
		x := 0
		for i := 0; i < len(b); i++ {
			cur := b[i] + x
			for cur < mid && free > 0 {
				cur++
				x++
				free--
			}
			if cur < mid {
				can = false
				break
			}
			if i+w < len(b) {
				b[i+w] -= x
			}
		}

		if can {
			lo = mid + 1
			ret = mid
		} else {
			hi = mid - 1
		}
	}

	return ret
}

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

package main

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

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 main() {
	in.Split(bufio.ScanWords)
	n, m, w := readInt(), readInt(), readInt()
	a := make([]int, n)
	max := 0
	for i := range a {
		a[i] = readInt()
		if a[i] > max {
			max = a[i]
		}
	}

	q := make([]int, 0, m)
	fmt.Println(sort.Search(max+m, func(minHeight int) bool {
		used := 0
		q := q
		for i := range a {
			for len(q) > 0 && q[0] == i {
				q = q[1:]
			}
			for len(q)+a[i] < minHeight {
				used++
				if used > m {
					return true
				}
				q = append(q, i+w)
			}
		}
		return used > m
	}) - 1)
}

package main

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

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

	var n, m, w int
	fmt.Fscanf(r, "%d %d %d\n", &n, &m, &w)

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

	fmt.Println(minMax(a, m, w))
}

func minMax(a []int, m, w int) int {
	var ret int

	lo, hi := 0, int(1e6)
	for lo <= hi {
		mid := (lo + hi) / 2
		b := make([]int, len(a))
		copy(b, a)

		can := true
		free := m
		x := 0
		for i := 0; i < len(b); i++ {
			cur := b[i] + x
			for cur < mid && free > 0 {
				cur++
				x++
				free--
			}
			if cur < mid {
				can = false
				break
			}
			if i+w < len(b) {
				b[i+w] -= x
			}
		}

		if can {
			lo = mid + 1
			ret = mid
		} else {
			hi = mid - 1
		}
	}

	return ret
}