During their New Year holidays, Alice and Bob play the following game using an array $$$a$$$ of $$$n$$$ integers:   Players take turns, Alice moves first.  Each turn a player chooses any element and removes it from the array.  If Alice chooses even value, then she adds it to her score. If the chosen value is odd, Alice's score does not change.  Similarly, if Bob chooses odd value, then he adds it to his score. If the chosen value is even, then Bob's score does not change. If there are no numbers left in the array, then the game ends. The player with the highest score wins. If the scores of the players are equal, then a draw is declared.For example, if $$$n = 4$$$ and $$$a = [5, 2, 7, 3]$$$, then the game could go as follows (there are other options):   On the first move, Alice chooses $$$2$$$ and get two points. Her score is now $$$2$$$. The array $$$a$$$ is now $$$[5, 7, 3]$$$.  On the second move, Bob chooses $$$5$$$ and get five points. His score is now $$$5$$$. The array $$$a$$$ is now $$$[7, 3]$$$.  On the third move, Alice chooses $$$7$$$ and get no points. Her score is now $$$2$$$. The array $$$a$$$ is now $$$[3]$$$.  On the last move, Bob chooses $$$3$$$ and get three points. His score is now $$$8$$$. The array $$$a$$$ is empty now.  Since Bob has more points at the end of the game, he is the winner. You want to find out who will win if both players play optimally. Note that there may be duplicate numbers in the array.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in the array $$$a$$$. The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the array $$$a$$$ used to play the game. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output on a separate line:    "Alice" if Alice wins with the optimal play;  "Bob" if Bob wins with the optimal play;  "Tie", if a tie is declared during the optimal play.

package main

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

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

func main() {

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

		fmt.Fprintln(out, solve2(a, n))

	}

}

func solve2(a []int, n int) string {

	var (
		alice = int64(0)
		bob   = int64(0)
	)

	//quickSort(a, 0, n-1)
	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	for i := range a {

		if i%2 == 0 && a[i]%2 == 0 {
			alice += int64(a[i])
		}

		if i%2 == 1 && a[i]%2 == 1 {
			bob += int64(a[i])
		}

	}

	if alice > bob {
		return "Alice"
	} else if bob > alice {
		return "Bob"
	} else {
		return "Tie"
	}

	//fmt.Println(alice, bob)

}

//逆向氣泡排序
func reverseBobbleSort(array []int) {

	for i := 0; i < len(array)-1; i++ {
		for j := i + 1; j < len(array); j++ {
			if array[j] > array[i] {
				temp := array[i]
				array[i] = array[j]
				array[j] = temp
			}
		}
	}

}

//數字陣列反轉
func reverseInt(array []int) {

	for i := 0; i < len(array)/2; i++ {
		temp := array[i]
		array[i] = array[len(array)-1-i]
		array[len(array)-1-i] = temp
	}

}

func solve(a []int, n int) string {

	var (
		odd  []int
		even []int
		oSum = 0
		eSum = 0
	)

	for i := range a {

		if a[i]%2 == 1 {
			odd = append(odd, a[i])
		} else {
			even = append(even, a[i])
		}

	}

	//printIntArr(odd)
	//printIntArr(even)

	for i := range odd {

		if i >= n/2 {
			break
		}

		oSum += odd[i]

	}

	for i := range even {

		if i > n/2 {
			break
		}

		eSum += even[i]

	}

	//fmt.Println(oSum, eSum)

	if eSum > oSum {
		return "Alice"
	} else if eSum < oSum {
		return "Bob"
	} else {
		return "Tie"
	}

}

//印出數字陣列
func printIntArr(array []int) {

	for i := range array {
		fmt.Printf("%d ", array[i])
	}

	fmt.Println()

}

//快速排序
func quickSort(array []int64, low int, high int) {
	if low < high {
		p := partition(array, low, high)
		quickSort(array, low, p-1)
		quickSort(array, p+1, high)
	}
}
func partition(Array []int64, low int, high int) int {

	pivot := Array[high]
	i := low

	for j := low; j < high; j++ {
		if Array[j] > pivot {
			temp := Array[i]
			Array[i] = Array[j]
			Array[j] = temp
			i++
		}
	}

	temp := Array[i]
	Array[i] = Array[high]
	Array[high] = temp

	return i

}

package main

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

func main () {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t,n int
	Fscan(in, &t)
	for tt := 0; tt < t ; tt++ {
		Fscan(in, &n)
		p := make([]int, n)
		for i := 0; i<n; i++ {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sort.Sort(sort.Reverse(sort.IntSlice(p)))
		var s, prev int64
		s = 0
		prev = 0
		for i, v := range p{
			prev = s
			if v%2 == i%2{
				if i%2 == 0 {
					s += int64(v)
					if s < prev {
						out.WriteString("error")
					}
				} else {
					s -= int64(v)
					if s > prev {
						out.WriteString("error2")
					}
				}
			}
		}
		ans := "Tie"
		if s > 0 {
			ans = "Alice"
		} else if s < 0 {
			ans = "Bob"
		}
		out.WriteString(ans)
		out.WriteString("\n")
	}
}

package main

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

func solveA() {}

func solveB() {}

func solveC() {}

func solveD() {}

// ---

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		var n int
		scan(&n)

		even, odd := make([]int64, 0), make([]int64, 0)
		for i := 0; i < n; i++ {
			var num int64
			scan(&num)
			if num%2 == 0 {
				even = append(even, num)
			} else {
				odd = append(odd, num)
			}
		}

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

		turn := 0
		i, j := len(even)-1, len(odd)-1
		var suma, sumb int64 = 0, 0
		for k := 0; k < n; k++ {
			if turn == 0 {
				if i < 0 || j < 0 {
					if i < 0 {
						j--
					} else {
						suma += even[i]
						i--
					}
					turn ^= 1
					continue
				}
				if even[i] > odd[j] {
					suma += even[i]
					i--
				} else {
					j--
				}
			} else {
				if i < 0 || j < 0 {
					if j < 0 {
						i--
					} else {
						sumb += odd[j]
						j--
					}
					turn ^= 1
					continue
				}
				if even[i] < odd[j] {
					sumb += odd[j]
					j--
				} else {
					i--
				}
			}
			turn ^= 1
		}

		if suma > sumb {
			printf("Alice\n")
		} else if suma < sumb {
			printf("Bob\n")
		} else {
			printf("Tie\n")
		}
	}
}

func scan(a ...interface{})             { fmt.Fscan(reader, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

// ---

package main

import (
	"bufio"
	"fmt"
	"os"
    "sort"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewWriter(os.Stdout)
)

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

func solve() {
    var n, alice, bob int64
    fmt.Fscan(input, &n)
    a := make([]int64, n)
    for i := 0; i < len(a); i++ {
        fmt.Fscan(input, &a[i])
    }
    sort.Slice(a, func(i, j int) bool { return a[j] < a[i]})

    for i := 0; i < len(a); i++ {
        if i & 1 == 0 {
            if a[i] & 1 == 0 { alice += a[i]}
        } else {
            if a[i] & 1 == 1 { bob += a[i]}
        }
    }
    if alice == bob {
        fmt.Fprintln(output, "Tie")
    } else {
        if alice > bob {
            fmt.Fprintln(output, "Alice")
        } else {
            fmt.Fprintln(output, "Bob")
        }
    }
}

package main

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

func Solve() {
	n := ri()
	var st0, st1 Stack
	var a []int
	for i := 0; i < n; i++ {
		a = append(a, ri())
	}
	sort.Ints(a)
	for i := 0; i < n; i++ {
		x := a[i]
		if x%2 == 0 {
			st0.push(x)
		} else {
			st1.push(x)
		}
	}
	//println(st0.s, st1.s)
	x, y := int64(0), int64(0)
	for i := 0; i < n; i++ {
		if st0.size() == 0 {
			if i%2 == 1 {
				y += int64(st1.top())
			}
			st1.pop()
			continue
		}
		if st1.size() == 0 {
			if i%2 == 0 {
				x += int64(st0.top())
			}
			st0.pop()
			continue
		}
		if i%2 == 0 {
			if st0.top() >= st1.top() {
				x += int64(st0.top())
				st0.pop()
			} else {
				st1.pop()
			}
		} else {
			if st0.top() <= st1.top() {
				y += int64(st1.top())
				st1.pop()
			} else {
				st0.pop()
			}
		}
	}
	//println(x, y)
	switch {
	case x > y:
		println("Alice")
	case x < y:
		println("Bob")
	case x == y:
		println("Tie")
	}
}

func main() {
	T := 0 // 如果是多组样例，请讲 T := 1 改为 T := 0
	in, out = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	if T == 0 {
		scan(&T)
	}
	for t := 0; t < T; t++ {
		Solve()
	}
	out.Flush()
}

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

// ri 将直接读入并返回一个 int
func ri() (x int) {
	scan(&x)
	return x
}

// ri64 将直接读入并返回一个 int64
func ri64() (x int64) {
	scan(&x)
	return x
}

//rs 将直接读入并返回一个 string
func rs() (s string) {
	scan(&s)
	return s
}

//scan 用法与 fmt.scan() 相似，可以传入多个变量的地址进行读入操作
func scan(a ...interface{}) { Fscan(in, a...) }

//print 用法与 fmt.print() 相似，可以传入多个变量进行输出。
//注意，这个函数不会换行，多个变量之间有空格
func print(a ...interface{}) { Fprint(out, a...) }

//println 用法与 fmt.println() 相似，可以传入多个变量进行输出。
//这个函数会换行，多个变量之间有空格
func println(a ...interface{}) { Fprintln(out, a...) }

//min 可以传入多个 int 变量，求出这些变量的最小值
func min(a ...int) int {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] < ans {
			ans = a[i]
		}
	}
	return ans
}

//min64 可以传入多个 int64 变量，求出这些变量的最小值
func min64(a ...int64) int64 {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] < ans {
			ans = a[i]
		}
	}
	return ans
}

//max 可以传入多个 int 变量，求出这些变量的最大值
func max(a ...int) int {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] > ans {
			ans = a[i]
		}
	}
	return ans
}

//max64 可以传入多个 int64 变量，求出这些变量的最大值
func max64(a ...int64) int64 {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] > ans {
			ans = a[i]
		}
	}
	return ans
}

//sum 可以传入多个 int 变量，求出这些变量的总和，并返回总和。
//你可以使用 ... 运算符打散数组，使得 sum 函数可以求出数组的和。
func sum(a ...int) int {
	ans := 0
	for _, x := range a {
		ans += x
	}
	return ans
}

//sum64 可以传入多个 int64 变量，求出这些变量的总和，并返回总和。
//你可以使用 ... 运算符打散数组，使得 sum 函数可以求出数组的和。
func sum64(a ...int64) int64 {
	ans := int64(0)
	for _, x := range a {
		ans += x
	}
	return ans
}

//reverse 用于翻转 int 切片，所有元素将会变成原切片的倒序
func reverse(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

//reverse64 用于翻转 int64 切片，所有元素将会变成原切片的倒序
func reverse64(a []int64) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

//lowerBound 类似于 C++ 中的 lower_bound。
//用于二分查找 int 切片中，第一个大于等于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，lowerBound 作用的 int 切片必须升序。
func lowerBound(a []int, k int) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] < k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

//lowerBound64 类似于 C++ 中的 lower_bound。
//用于二分查找 int64 切片中，第一个大于等于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，lowerBound 作用的 int64 切片必须升序。
func lowerBound64(a []int64, k int64) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] < k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

//upperBound 类似于 C++ 中的 upper_bound。
//用于二分查找 int 切片中，第一个大于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，upperBound 作用的 int 切片必须升序。
func upperBound(a []int, k int) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] <= k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

//upperBound64 类似于 C++ 中的 upper_bound。
//用于二分查找 int64 切片中，第一个大于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，upperBound 作用的 int64 切片必须升序。
func upperBound64(a []int64, k int64) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] <= k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

type Stack struct {
	s []int
}

func (st *Stack) top() int   { return st.s[len(st.s)-1] }
func (st *Stack) size() int  { return len(st.s) }
func (st *Stack) pop()       { st.s = st.s[:len(st.s)-1] }
func (st *Stack) push(x int) { st.s = append(st.s, x) }

type Queue struct {
	que chan int
}

func MakeQueue(size int) Queue {
	var q Queue
	q.que = make(chan int, size)
	return q
}

package main

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

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

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

//https://codeforces.com/problemset/problem/1472/D

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, 1024), int(1e+9))
	for t := nextNum(); t > 0; t-- {
		n := nextNum()
		a := make([]int64, n)
		for i := int64(0); i < n; i++ {
			a[i] = nextNum()
		}
		sort.Sort(sort.Reverse(Ints64(a)))
		score := int64(0)
		for i := int64(0); i < n; i++ {
			if i&1 == 0 {
				if a[i]&1 == 0 {
					score += a[i]
				}
			} else {
				if a[i]&1 == 1 {
					score -= a[i]
				}
			}
		}
		switch {
		case score > 0:
			println("Alice")
		case score < 0:
			println("Bob")
		default:
			println("Tie")
		}
	}
}

func nextNum() int64 {
	in.Scan()
	var r, f int64
	f = 1
	for _, c := range in.Bytes() {
		if c == '-' {
			f = -1
			continue
		}
		r *= 10
		r += int64(c - '0')
	}
	return r * f
}

type Ints64 []int64

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

package main

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

var tt int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &tt)

	for o := 0; o < tt; o++ {
		var n int
		fmt.Fscan(input, &n)

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

		var alice int64
		var bob int64

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

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

			if i%2 == 0 {

				if arr[i]%2 == 0 {
					alice += int64(arr[i])
				}

			} else {
				if arr[i]%2 == 1 {
					bob += int64(arr[i])
				}
			}
		}

		if alice == bob {
			fmt.Println("Tie")
		}

		if alice > bob {
			fmt.Println("Alice")
		}

		if bob > alice {
			fmt.Println("Bob")
		}
	}
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		size := ReadInt()
		weights := ReadIntSliceln(size)
		fmt.Println(process(weights))
	}
}

func process(w []int) (ans string) {
	sort.Sort(sort.Reverse(sort.IntSlice(w)))
	var alice, bob int64
	isAlice := true
	for _, v := range w {
		if isAlice {
			if v&1 == 0 {
				alice = alice + int64(v)
			}
		} else {
			if v&1 != 0 {
				bob = bob + int64(v)
			}
		}
		//fmt.Println("Alice:", isAlice, alice, bob)
		isAlice = !isAlice
	}
	if alice == bob {
		return "Tie"
	} else if alice > bob {
		return "Alice"
	}
	return "Bob"
}

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

// ReadInt Read a single integer followed by a space
func ReadInt() (v int) {
	fmt.Fscan(reader, &v)
	return v
}

// ReadIntSliceln reads a line of integers into a slice.
func ReadIntSliceln(size int) []int {
	a := make([]int, size)
	for i := range a {
		fmt.Fscan(reader, &a[i])
	}
	//fmt.Scanf("\n")
	return a
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		println(solve(ReadInts(n)))
	}
}

func solve(a []int) string {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	score := int64(0)
	for i, v := range a {
		if i%2 == 0 && v%2 == 0 {
			score += int64(v)
		}
		if i%2 == 1 && v%2 == 1 {
			score -= int64(v)
		}
	}

	if score == 0 {
		return "Tie"
	}
	if score > 0 {
		return "Alice"
	}
	return "Bob"
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func printInts(a ...int)                { s := fmt.Sprint(a); println(s[1 : len(s)-1]) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

func main() {
	sc := NewScanner()
	t := sc.NextInt()
	for i := 0; i < t; i++ {
		sc.NextInt()
		a := sc.NextIntArray()
		fmt.Println(solve(a))
	}

}

func solve(a []int) string {
	sort.Ints(a)
	reverse(a, 0, len(a))
	score := int64(0)
	for i := 0; i < len(a); i++ {
		if a[i]%2 == 0 && i%2 == 0 {
			score += int64(a[i])
		} else if a[i]%2 == 1 && i%2 == 1 {
			score -= int64(a[i])
		}
	}
	if score > 0 {
		return "Alice"
	} else if score < 0 {
		return "Bob"
	} else {
		return "Tie"
	}

}

func reverse(a []int, start int, length int) {
	var end = start + length - 1
	for start < end {
		a[start], a[end] = a[end], a[start]
		start++
		end--
	}
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) 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 *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]int {
	s.pre()
	start := s.p
	mp := map[int]int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v]++
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v]++

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) 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
		}
	}
}

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func ScanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func ScanInt() int {
	return int(ScanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		a := make([]int, n)

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

		sort.Ints(a)
		var points [2]int64

		for i, turn := n-1, 0; i >= 0; i, turn = i-1, 1-turn {
			if a[i]%2 == turn {
				points[turn] += int64(a[i])
			}
		}

		if points[0] > points[1] {
			fmt.Println("Alice")
		} else if points[1] > points[0] {
			fmt.Println("Bob")
		} else {
			fmt.Println("Tie")
		}
	}
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1e6), 1e6)
}

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

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

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

func sbytes() []byte {
	scanner.Scan()
	return scanner.Bytes()
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		a := make([]int64, n)
		for i := range a {
			a[i] = sint64()
		}
		printf("%s\n", sol(a))
	}
}

func sol(a []int64) string {
	sort.Slice(a, func(il, ir int) bool {
		return a[il] < a[ir]
	})
	as := int64(0)
	bs := int64(0)
	isAlice := true
	for i := len(a) - 1; i > -1; i-- {
		if isAlice {
			if a[i]&1 == 0 {
				as += a[i]
			}
		} else {
			if a[i]&1 == 1 {
				bs += a[i]
			}
		}
		isAlice = !isAlice
	}
	if as > bs {
		return "Alice"
	}
	if bs > as {
		return "Bob"
	}
	return "Tie"
}

package main

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

func main(){
	var t, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)

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

		sort.Ints(a)

		x := int64(0)
		y := int64(0)
		for i:=n-1; i>=0; i-=2{
			if (a[i] % 2 == 0){
				x += int64(a[i]);
			}
			if (i-1 >= 0 && a[i-1]%2 == 1){
				y += int64(a[i-1]);
			}
		}
		if (x > y){
			fmt.Println("Alice")
		}else if (y > x){
			fmt.Println("Bob")
		}else {
			fmt.Println("Tie")
		}

		t--
	}
}

package main

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

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)

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

		var alice int64
		var bob int64

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

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

			if i%2 == 0 {

				if arr[i]%2 == 0 {
					alice += int64(arr[i])
				}

			} else {
				if arr[i]%2 == 1 {
					bob += int64(arr[i])
				}
			}
		}

		if alice == bob {
			fmt.Println("Tie")
		}

		if alice > bob {
			fmt.Println("Alice")
		}

		if bob > alice {
			fmt.Println("Bob")
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"sort"
	"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(Case int) {
		var n int
		Fscan(in, &n)
		var a, b []int64
		for i := 0; i < n; i++ {
			var v int64
			Fscan(in, &v)
			if v&1 == 0 {
				a = append(a, v)
			} else {
				b = append(b, v)
			}
		}
		sort.Slice(a, func(i, j int) bool { return a[i] > a[j] })
		sort.Slice(b, func(i, j int) bool { return b[i] > b[j] })

		s := int64(0)
		for i := 0; i < n; i++ {
			if len(a) == 0 {
				if i&1 == 1 {
					s -= b[0]
				}
				b = b[1:]
			} else if len(b) == 0 {
				if i&1 == 0 {
					s += a[0]
				}
				a = a[1:]
			} else {
				if i&1 == 0 {
					if a[0] > b[0] {
						s += a[0]
						a = a[1:]
					} else {
						b = b[1:]
					}
				} else {
					if b[0] > a[0] {
						s -= b[0]
						b = b[1:]
					} else {
						a = a[1:]
					}
				}
			}
		}
		if s > 0 {
			Fprintln(out, "Alice")
		} else if s == 0 {
			Fprintln(out, "Tie")
		} else {
			Fprintln(out, "Bob")
		}
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}

	_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"
)

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

func main() {

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

		fmt.Fprintln(out, solve2(a, n))
		//solve2(a, n)

	}

}

func solve2(a []int, n int) string {

	var (
		alice = 0
		bob   = 0
	)

	quickSort(a, 0, n-1)
	reverseInt(a)

	//printIntArr(a)

	for i := range a {

		if i%2 == 0 && a[i]%2 == 0 {
			alice += a[i]
		}

		if i%2 == 1 && a[i]%2 == 1 {
			bob += a[i]
		}

	}

	if alice > bob {
		return "Alice"
	} else if bob > alice {
		return "Bob"
	} else {
		return "Tie"
	}

	//fmt.Println(alice, bob)

}

//數字陣列反轉
func reverseInt(array []int) {

	for i := 0; i < len(array)/2; i++ {
		temp := array[i]
		array[i] = array[len(array)-1-i]
		array[len(array)-1-i] = temp
	}

}

func solve(a []int, n int) string {

	var (
		odd  []int
		even []int
		oSum = 0
		eSum = 0
	)

	for i := range a {

		if a[i]%2 == 1 {
			odd = append(odd, a[i])
		} else {
			even = append(even, a[i])
		}

	}

	//printIntArr(odd)
	//printIntArr(even)

	for i := range odd {

		if i >= n/2 {
			break
		}

		oSum += odd[i]

	}

	for i := range even {

		if i > n/2 {
			break
		}

		eSum += even[i]

	}

	//fmt.Println(oSum, eSum)

	if eSum > oSum {
		return "Alice"
	} else if eSum < oSum {
		return "Bob"
	} else {
		return "Tie"
	}

}

//印出數字陣列
func printIntArr(array []int) {

	for i := range array {
		fmt.Printf("%d ", array[i])
	}

	fmt.Println()

}

//快速排序
func quickSort(array []int, low int, high int) {
	if low < high {
		p := partition(array, low, high)
		quickSort(array, low, p-1)
		quickSort(array, p+1, high)
	}
}
func partition(Array []int, low int, high int) int {

	pivot := Array[high]
	i := low

	for j := low; j < high; j++ {
		if Array[j] < pivot {
			temp := Array[i]
			Array[i] = Array[j]
			Array[j] = temp
			i++
		}
	}

	temp := Array[i]
	Array[i] = Array[high]
	Array[high] = temp

	return i

}

package main

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

func main () {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t,n int
	Fscan(in, &t)
	for tt := 0; tt < t ; tt++ {
		Fscan(in, &n)
		p := make([]int, n)
		for i := 0; i<n; i++ {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sort.Sort(sort.Reverse(sort.IntSlice(p)))
		s, prev := 0, 0
		for i, v := range p{
			prev = s
			if v%2 == i%2{
				if i%2 == 0 {
					s += v
					if s < prev {
						out.WriteString("error")
					}
				} else {
					s -= v
					if s > prev {
						out.WriteString("error2")
					}
				}
			}
		}
		ans := "Tie"
		if s > 0 {
			ans = "Alice"
		} else if s < 0 {
			ans = "Bob"
		}
		out.WriteString(ans)
		out.WriteString("\n")
	}
}

package main

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

func main () {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	errWriter := bufio.NewWriter(os.Stderr)
	defer out.Flush()
	defer errWriter.Flush()
	var t,n int
	Fscan(in, &t)
	for tt := 0; tt < t ; tt++ {
		Fscan(in, &n)
		p := make([]int, n)
		for i := 0; i<n; i++ {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sort.Sort(sort.Reverse(sort.IntSlice(p)))
		s, prev := 0, 0
		for i, v := range p{
			prev = s
			if v%2 == i%2{
				if i%2 == 0 {
					s += v
					if s < prev {
						errWriter.WriteString("error")
					}
				} else {
					s -= v
					if s > prev {
						errWriter.WriteString("error2")
					}
				}
			}
		}
		ans := "Tie"
		if s > 0 {
			ans = "Alice"
		} else if s < 0 {
			ans = "Bob"
		}
		out.WriteString(ans)
		out.WriteString("\n")
	}
}

package main

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

func main () {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t,n int
	Fscan(in, &t)
	for tt := 0; tt < t ; tt++ {
		Fscan(in, &n)
		p := make([]int, n)
		for i := 0; i<n; i++ {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sort.Sort(sort.Reverse(sort.IntSlice(p)))
		s := 0
		for i, v := range p{
			if v%2 == i%2{
				if i%2 == 0 {
					s += v
				} else {
					s -= v
				}
			}
		}
		ans := "Tie"
		if s > 0 {
			ans = "Alice"
		} else if s < 0 {
			ans = "Bob"
		}
		out.WriteString(ans)
		out.WriteString("\n")
	}
}

package main

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

func main () {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t,n int
	Fscan(in, &t)
	for tt := 0; tt < t ; tt++ {
		Fscan(in, &n)
		p := make([]int, n)
		for i := 0; i<n; i++ {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sort.Sort(sort.Reverse(sort.IntSlice(p)))
		s := make ([]int, 2)
		for i, v := range p{
			if v%2 == i%2{
				s[i%2]+=v
			}
		}
		ans := "Tie"
		if s[0] > s[1] {
			ans = "Alice"
		} else if s[0] < s[1] {
			ans = "Bob"
		}
		out.WriteString(ans)
		out.WriteString("\n")
	}
}

package main

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

func solveA() {}

func solveB() {}

func solveC() {}

func solveD() {}

// ---

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		var n int
		scan(&n)

		even, odd := make([]int64, 0), make([]int64, 0)
		for i := 0; i < n; i++ {
			var num int64
			scan(&num)
			if num%2 == 0 {
				even = append(even, num)
			} else {
				odd = append(odd, num)
			}
		}

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

		turn := 0
		i, j := len(even)-1, len(odd)-1
		var suma, sumb int64 = 0, 0
		for k := 0; k < n; k++ {
			if turn == 0 {
				if i < 0 || j < 0 {
					if i < 0 {
						j--
					} else {
						suma += even[i]
						i--
					}
					continue
				}
				if even[i] > odd[j] {
					suma += even[i]
					i--
				} else {
					j--
				}
			} else {
				if i < 0 || j < 0 {
					if j < 0 {
						i--
					} else {
						sumb += odd[j]
						j--
					}
					continue
				}
				if even[i] < odd[j] {
					sumb += odd[j]
					j--
				} else {
					i--
				}
			}
			turn ^= 1
		}

		if suma > sumb {
			printf("Alice\n")
		} else if suma < sumb {
			printf("Bob\n")
		} else {
			printf("Tie\n")
		}
	}
}

func scan(a ...interface{})             { fmt.Fscan(reader, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

// ---

package main

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

func solveA() {}

func solveB() {}

func solveC() {}

func solveD() {}

// ---

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		var n int
		scan(&n)

		even, odd := make([]int64, 0), make([]int64, 0)
		for i := 0; i < n; i++ {
			var num int64
			scan(&num)
			if num%2 == 0 {
				even = append(even, num)
			} else {
				odd = append(odd, num)
			}
		}

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

		turn := 0
		i, j := len(even)-1, len(odd)-1
		var suma, sumb int64 = 0, 0
		for k := 0; k < n; k++ {
			if turn == 0 {
				if i < 0 || j < 0 {
					if i < 0 {
						j--
					} else {
						suma += even[i]
						i--
					}
					break
				}
				if even[i] > odd[j] {
					suma += even[i]
					i--
				} else {
					j--
				}
			} else {
				if i < 0 || j < 0 {
					if j < 0 {
						i--
					} else {
						sumb += odd[j]
						j--
					}
					break
				}
				if even[i] < odd[j] {
					sumb += odd[j]
					j--
				} else {
					i--
				}
			}
			turn ^= 1
		}

		if suma > sumb {
			printf("Alice\n")
		} else if suma < sumb {
			printf("Bob\n")
		} else {
			printf("Tie\n")
		}
	}
}

func scan(a ...interface{})             { fmt.Fscan(reader, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

// ---

package main

import (
	"bufio"
	"fmt"
	"os"
    "sort"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewWriter(os.Stdout)
)

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

func solve() {
    var n, alice, bob int
    fmt.Fscan(input, &n)
    a := make([]int, n)
    for i := 0; i < len(a); i++ {
        fmt.Fscan(input, &a[i])
    }
    sort.Slice(a, func(i, j int) bool { return a[j] < a[i]})
    for i := 0; i < len(a); i++ {
        if i & 1 == 0 {
            if a[i] & 1 == 0 { alice += a[i]}
        } else {
            if a[i] & 1 == 1 { bob += a[i]}
        }
    }
    if alice == bob {
        fmt.Fprintln(output, "Tie")
    } else {
        if alice > bob {
            fmt.Fprintln(output, "Alice")
        } else {
            fmt.Fprintln(output, "Bob")
        }
    }
}

package main

import (
	"bufio"
	"fmt"
	"os"
    "sort"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewWriter(os.Stdout)
)

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

func solve() {
    var n, alice, bob, turn int
    fmt.Fscan(input, &n)
    a := make([]int, n)
    for i := 0; i < len(a); i++ {
        fmt.Fscan(input, &a[i])
    }
    sort.Slice(a, func(i, j int) bool { return a[j] < a[i]})
    for len(a) > 0  {
        if turn == 0 {
            if a[0] & 1 == 0 {
                alice += a[0]
            }
        } else {
            if a[0] & 1 == 1 {
                bob += a[0]
            }
        }
        a = a[1:]
        turn ^= 1
    }
    if alice == bob {
        fmt.Fprintln(output, "Tie")
    } else {
        if alice > bob {
            fmt.Fprintln(output, "Alice")
        } else {
            fmt.Fprintln(output, "Bob")
        }
    }
}

package main

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

func Solve() {
	n := ri()
	var st0, st1 Stack
	var a []int
	for i := 0; i < n; i++ {
		a = append(a, ri())
	}
	sort.Ints(a)
	for i := 0; i < n; i++ {
		x := a[i]
		if x%2 == 0 {
			st0.push(x)
		} else {
			st1.push(x)
		}
	}
	//println(st0.s, st1.s)
	x, y := 0, 0
	for i := 0; i < n; i++ {
		if st0.size() == 0 {
			if i%2 == 1 {
				y += st1.top()
			}
			st1.pop()
			continue
		}
		if st1.size() == 0 {
			if i%2 == 0 {
				x += st0.top()
			}
			st0.pop()
			continue
		}
		if i%2 == 0 {
			if st0.top() >= st1.top() {
				x += st0.top()
				st0.pop()
			} else {
				st1.pop()
			}
		} else {
			if st0.top() <= st1.top() {
				y += st1.top()
				st1.pop()
			} else {
				st0.pop()
			}
		}
	}
	//println(x, y)
	switch {
	case x > y:
		println("Alice")
	case x < y:
		println("Bob")
	case x == y:
		println("Tie")
	}
}

func main() {
	T := 0 // 如果是多组样例，请讲 T := 1 改为 T := 0
	in, out = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	if T == 0 {
		scan(&T)
	}
	for t := 0; t < T; t++ {
		Solve()
	}
	out.Flush()
}

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

// ri 将直接读入并返回一个 int
func ri() (x int) {
	scan(&x)
	return x
}

// ri64 将直接读入并返回一个 int64
func ri64() (x int64) {
	scan(&x)
	return x
}

//rs 将直接读入并返回一个 string
func rs() (s string) {
	scan(&s)
	return s
}

//scan 用法与 fmt.scan() 相似，可以传入多个变量的地址进行读入操作
func scan(a ...interface{}) { Fscan(in, a...) }

//print 用法与 fmt.print() 相似，可以传入多个变量进行输出。
//注意，这个函数不会换行，多个变量之间有空格
func print(a ...interface{}) { Fprint(out, a...) }

//println 用法与 fmt.println() 相似，可以传入多个变量进行输出。
//这个函数会换行，多个变量之间有空格
func println(a ...interface{}) { Fprintln(out, a...) }

//min 可以传入多个 int 变量，求出这些变量的最小值
func min(a ...int) int {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] < ans {
			ans = a[i]
		}
	}
	return ans
}

//min64 可以传入多个 int64 变量，求出这些变量的最小值
func min64(a ...int64) int64 {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] < ans {
			ans = a[i]
		}
	}
	return ans
}

//max 可以传入多个 int 变量，求出这些变量的最大值
func max(a ...int) int {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] > ans {
			ans = a[i]
		}
	}
	return ans
}

//max64 可以传入多个 int64 变量，求出这些变量的最大值
func max64(a ...int64) int64 {
	ans := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] > ans {
			ans = a[i]
		}
	}
	return ans
}

//sum 可以传入多个 int 变量，求出这些变量的总和，并返回总和。
//你可以使用 ... 运算符打散数组，使得 sum 函数可以求出数组的和。
func sum(a ...int) int {
	ans := 0
	for _, x := range a {
		ans += x
	}
	return ans
}

//sum64 可以传入多个 int64 变量，求出这些变量的总和，并返回总和。
//你可以使用 ... 运算符打散数组，使得 sum 函数可以求出数组的和。
func sum64(a ...int64) int64 {
	ans := int64(0)
	for _, x := range a {
		ans += x
	}
	return ans
}

//reverse 用于翻转 int 切片，所有元素将会变成原切片的倒序
func reverse(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

//reverse64 用于翻转 int64 切片，所有元素将会变成原切片的倒序
func reverse64(a []int64) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

//lowerBound 类似于 C++ 中的 lower_bound。
//用于二分查找 int 切片中，第一个大于等于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，lowerBound 作用的 int 切片必须升序。
func lowerBound(a []int, k int) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] < k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

//lowerBound64 类似于 C++ 中的 lower_bound。
//用于二分查找 int64 切片中，第一个大于等于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，lowerBound 作用的 int64 切片必须升序。
func lowerBound64(a []int64, k int64) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] < k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

//upperBound 类似于 C++ 中的 upper_bound。
//用于二分查找 int 切片中，第一个大于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，upperBound 作用的 int 切片必须升序。
func upperBound(a []int, k int) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] <= k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

//upperBound64 类似于 C++ 中的 upper_bound。
//用于二分查找 int64 切片中，第一个大于 k 的元素在切片中的位置。
//如果元素不存在，则返回切片的长度。
//注意，upperBound 作用的 int64 切片必须升序。
func upperBound64(a []int64, k int64) int {
	l, r, pos := 0, len(a)-1, len(a)
	for l <= r {
		mid := (l + r) >> 1
		if a[mid] <= k {
			l = mid + 1
		} else {
			pos, r = mid, mid-1
		}
	}
	return pos
}

type Stack struct {
	s []int
}

func (st *Stack) top() int   { return st.s[len(st.s)-1] }
func (st *Stack) size() int  { return len(st.s) }
func (st *Stack) pop()       { st.s = st.s[:len(st.s)-1] }
func (st *Stack) push(x int) { st.s = append(st.s, x) }

type Queue struct {
	que chan int
}

func MakeQueue(size int) Queue {
	var q Queue
	q.que = make(chan int, size)
	return q
}

package main

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

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

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

//https://codeforces.com/problemset/problem/1472/D

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, 1024), int(1e+9))
	for t := nextNum(); t > 0; t-- {
		n := nextNum()
		a := make([]int, n)
		for i := 0; i < n; i++ {
			a[i] = nextNum()
		}
		sort.Sort(sort.Reverse(sort.IntSlice(a)))
		score := 0
		for i := 0; i < n; i++ {
			if i&1 == 0 {
				if a[i]&1 == 0 {
					score += a[i]
				}
			} else {
				if a[i]&1 == 1 {
					score -= a[i]
				}
			}
		}
		switch {
		case score > 0:
			println("Alice")
		case score < 0:
			println("Bob")
		default:
			println("Tie")
		}
	}
}

func nextNum() int {
	in.Scan()
	var r, f int
	f = 1
	for _, c := range in.Bytes() {
		if c == '-' {
			f = -1
			continue
		}
		r *= 10
		r += int(c - '0')
	}
	return r * f
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		size := ReadInt()
		weights := ReadIntSliceln(size)
		fmt.Println(process(weights))
	}
}

func process(w []int) (ans string) {
	sort.Sort(sort.Reverse(sort.IntSlice(w)))
	alice, bob := 0, 0
	isAlice := true
	for _, v := range w {
		if isAlice {
			if v&1 == 0 {
				alice = alice + v
			}
		} else {
			if v&1 != 0 {
				bob = bob + v
			}
		}
		//fmt.Println("Alice:", isAlice, alice, bob)
		isAlice = !isAlice
	}
	if alice == bob {
		return "Tie"
	} else if alice > bob {
		return "Alice"
	}
	return "Bob"
}

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

// ReadInt Read a single integer followed by a space
func ReadInt() (v int) {
	fmt.Fscan(reader, &v)
	return v
}

// ReadIntSliceln reads a line of integers into a slice.
func ReadIntSliceln(size int) []int {
	a := make([]int, size)
	for i := range a {
		fmt.Fscan(reader, &a[i])
	}
	//fmt.Scanf("\n")
	return a
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		println(solve(ReadInts(n)))
	}
}

func solve(a []int) string {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	score := 0
	for i, v := range a {
		if i%2 == 0 && v%2 == 0 {
			score += v
		}
		if i%2 == 1 && v%2 == 1 {
			score -= v
		}
	}

	if score == 0 {
		return "Tie"
	}
	if score > 0 {
		return "Alice"
	}
	return "Bob"
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func printInts(a ...int)                { s := fmt.Sprint(a); println(s[1 : len(s)-1]) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

func main() {
	sc := NewScanner()
	t := sc.NextInt()
	for i := 0; i < t; i++ {
		sc.NextInt()
		a := sc.NextIntArray()
		fmt.Println(solve(a))
	}

}

func solve(a []int) string {
	sort.Ints(a)
	reverse(a, 0, len(a))
	score := 0
	for i := 0; i < len(a); i++ {
		if a[i]%2 == 0 && i%2 == 0 {
			score += a[i]
		} else if a[i]%2 == 1 && i%2 == 1 {
			score -= a[i]
		}
	}
	if score > 0 {
		return "Alice"
	} else if score < 0 {
		return "Bob"
	} else {
		return "Tie"
	}

}

func reverse(a []int, start int, length int) {
	var end = start + length - 1
	for start < end {
		a[start], a[end] = a[end], a[start]
		start++
		end--
	}
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) 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 *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]int {
	s.pre()
	start := s.p
	mp := map[int]int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v]++
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v]++

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) 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
		}
	}
}


You are given a rooted tree. Each vertex contains $$$a_i$$$ tons of gold, which costs $$$c_i$$$ per one ton. Initially, the tree consists only a root numbered $$$0$$$ with $$$a_0$$$ tons of gold and price $$$c_0$$$ per ton.There are $$$q$$$ queries. Each query has one of two types:   Add vertex $$$i$$$ (where $$$i$$$ is an index of query) as a son to some vertex $$$p_i$$$; vertex $$$i$$$ will have $$$a_i$$$ tons of gold with $$$c_i$$$ per ton. It's guaranteed that $$$c_i > c_{p_i}$$$.  For a given vertex $$$v_i$$$ consider the simple path from $$$v_i$$$ to the root. We need to purchase $$$w_i$$$ tons of gold from vertices on this path, spending the minimum amount of money. If there isn't enough gold on the path, we buy all we can. If we buy $$$x$$$ tons of gold in some vertex $$$v$$$ the remaining amount of gold in it decreases by $$$x$$$ (of course, we can't buy more gold that vertex has at the moment). For each query of the second type, calculate the resulting amount of gold we bought and the amount of money we should spend.Note that you should solve the problem in online mode. It means that you can't read the whole input at once. You can read each query only after writing the answer for the last query, so don't forget to flush output after printing answers. You can use functions like fflush(stdout) in C++ and BufferedWriter.flush in Java or similar after each writing in your program. In standard (if you don't tweak I/O), endl flushes cout in C++ and System.out.println in Java (or println in Kotlin) makes automatic flush as well.

The first line contains three integers $$$q$$$, $$$a_0$$$ and $$$c_0$$$ ($$$1 \le q \le 3 \cdot 10^5$$$; $$$1 \le a_0, c_0 < 10^6$$$) — the number of queries, the amount of gold in the root and its price. Next $$$q$$$ lines contain descriptions of queries; The $$$i$$$-th query has one of two types:    "$$$1$$$ $$$p_i$$$ $$$a_i$$$ $$$c_i$$$" ($$$0 \le p_i < i$$$; $$$1 \le a_i, c_i < 10^6$$$): add vertex $$$i$$$ as a son to vertex $$$p_i$$$. The vertex $$$i$$$ will have $$$a_i$$$ tons of gold with price $$$c_i$$$ per one ton. It's guaranteed that $$$p_i$$$ exists and $$$c_i > c_{p_i}$$$. "$$$2$$$ $$$v_i$$$ $$$w_i$$$" ($$$0 \le v_i < i$$$; $$$1 \le w_i < 10^6$$$): buy $$$w_i$$$ tons of gold from vertices on path from $$$v_i$$$ to $$$0$$$ spending the minimum amount of money. If there isn't enough gold, we buy as much as we can. It's guaranteed that vertex $$$v_i$$$ exist.  It's guaranteed that there is at least one query of the second type.

For each query of the second type, print the resulting amount of gold we bought and the minimum amount of money we should spend.

NoteExplanation of the sample:At the first query, the tree consist of root, so we purchase $$$2$$$ tons of gold and pay $$$2 \cdot 2 = 4$$$. $$$3$$$ tons remain in the root.At the second query, we add vertex $$$2$$$ as a son of vertex $$$0$$$. Vertex $$$2$$$ now has $$$3$$$ tons of gold with price $$$4$$$ per one ton.At the third query, a path from $$$2$$$ to $$$0$$$ consists of only vertices $$$0$$$ and $$$2$$$ and since $$$c_0 < c_2$$$ we buy $$$3$$$ remaining tons of gold in vertex $$$0$$$ and $$$1$$$ ton in vertex $$$2$$$. So we bought $$$3 + 1 = 4$$$ tons and paid $$$3 \cdot 2 + 1 \cdot 4 = 10$$$. Now, in vertex $$$0$$$ no gold left and $$$2$$$ tons of gold remain in vertex $$$2$$$.At the fourth query, we add vertex $$$4$$$ as a son of vertex $$$0$$$. Vertex $$$4$$$ now has $$$1$$$ ton of gold with price $$$3$$$.At the fifth query, a path from $$$4$$$ to $$$0$$$ consists of only vertices $$$0$$$ and $$$4$$$. But since no gold left in vertex $$$0$$$ and only $$$1$$$ ton is in vertex $$$4$$$, we buy $$$1$$$ ton of gold in vertex $$$4$$$ and spend $$$1 \cdot 3 = 3$$$. Now, in vertex $$$4$$$ no gold left.

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var q, op, fa, v, wt int
	Fscan(in, &q)
	const mx = 19
	pa := make([][mx]int, q+1)
	dep := make([]int, q+1)
	left := make([]int, q+1)
	price := make([]int, q+1)
	Fscan(in, &left[0], &price[0])
	for i := 0; i < mx; i++ {
		pa[0][i] = -1
	}
	uptoDep := func(v, d int) int {
		for i := 0; i < mx; i++ {
			if (dep[v]-d)>>i&1 > 0 {
				v = pa[v][i]
				//if v == -1 { panic(-9) }
			}
		}
		return v
	}

	for w := 1; w <= q; w++ {
		Fscan(in, &op)
		if op == 1 {
			Fscan(in, &fa, &left[w], &price[w])
			pa[w][0] = fa
			v := w
			for i := 0; i+1 < mx; i++ {
				if p := pa[v][i]; p != -1 {
					pa[v][i+1] = pa[p][i]
				} else {
					pa[v][i+1] = -1
				}
			}
			dep[w] = dep[fa] + 1
		} else {
			Fscan(in, &v, &wt)
			actualWt := 0
			ans := int64(0)
			tar := v
			for i := mx - 1; i >= 0; i-- {
				if p := pa[tar][i]; p != -1 && left[p] > 0 {
					tar = p
				}
			}
			for d := dep[tar]; d <= dep[v]; d++ {
				w := uptoDep(v, d)
				if left[w] > wt {
					ans += int64(wt) * int64(price[w])
					actualWt += wt
					left[w] -= wt
					break
				}
				ans += int64(left[w]) * int64(price[w])
				actualWt += left[w]
				wt -= left[w]
				left[w] = 0
			}
			Fprintln(out, actualWt, ans)
		}
	}
}

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

package main
import ("bufio";."fmt";."os")

// github.com/EndlessCheng/codeforces-go
func main(){
	in:=bufio.NewReader(Stdin)
	var q,op,v,wt int
	Fscan(in,&q)
	F:=make([][19]int,q+1)
	for i:=0;i<19;i++{F[0][i]=-1}
	D:=make([]int,q+1)
	a:=make([]int,q+1)
	c:=make([]int,q+1)
	Fscan(in,&a[0],&c[0])
	for w:=1;w<=q;w++{
		if Fscan(in,&op);op==1{
			Fscan(in,&F[w][0],&a[w],&c[w])
			for i:=0;i+1<19;i++{if f:=F[w][i];f>=0{F[w][i+1]=F[f][i]}else{F[w][i+1]=-1}}
			D[w]=D[F[w][0]]+1
			continue
		}
		Fscan(in,&v,&wt)
		s,f,t:=int64(0),v,wt
		for i:=18;i>=0;i--{if p:=F[f][i];p>=0&&a[p]>0{f=p}}
		for d:=D[f];d<=D[v];d++{
			w:=v
			for i:=0;i<19;i++{if(D[w]-d)>>i&1>0{w=F[w][i]}}
			if t<a[w]{
				s+=int64(t)*int64(c[w])
				t=0
				a[w]-=wt
				break
			}
			s+=int64(a[w])*int64(c[w])
			t-=a[w]
			a[w]=0
		}
		Println(wt-t,s)
	}
}


Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more. Dima felt so grateful to Inna about the present that he decided to buy her n hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to n from left to right and started feeding them with carrots. Inna was determined to feed each hare exactly once. But in what order should she feed them?Inna noticed that each hare radiates joy when she feeds it. And the joy of the specific hare depends on whether Inna fed its adjacent hares before feeding it. Inna knows how much joy a hare radiates if it eats when either both of his adjacent hares are hungry, or one of the adjacent hares is full (that is, has been fed), or both of the adjacent hares are full. Please note that hares number 1 and n don't have a left and a right-adjacent hare correspondingly, so they can never have two full adjacent hares.Help Inna maximize the total joy the hares radiate. :)

The first line of the input contains integer n (1 ≤ n ≤ 3000) — the number of hares. Then three lines follow, each line has n integers. The first line contains integers a1 a2 ... an. The second line contains b1, b2, ..., bn. The third line contains c1, c2, ..., cn. The following limits are fulfilled: 0 ≤ ai, bi, ci ≤ 105. Number ai in the first line shows the joy that hare number i gets if his adjacent hares are both hungry. Number bi in the second line shows the joy that hare number i radiates if he has exactly one full adjacent hare. Number сi in the third line shows the joy that hare number i radiates if both his adjacent hares are full.

In a single line, print the maximum possible total joy of the hares Inna can get by feeding them.

package main

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

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

var dp [][]int
var a, b, c []int
var n int

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

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

	dp = make([][]int, n)
	for i := 0; i < n; i++ {
		dp[i] = make([]int, 2)
		for j := 0; j < 2; j++ {
			dp[i][j] = -1
		}
	}

	r := Dp(0, 0)

	fmt.Fprintln(out, r)
}

func Dp(pos, prev int) int {
	if pos == n - 1 {
		if prev == 0 {
			return a[pos]
		}
		return b[pos]
	}
	if dp[pos][prev] != -1 {
		return dp[pos][prev]
	}

	var ret int = 0

	if prev == 0 {
		ret = Max(ret, Dp(pos + 1, 0) + b[pos])
		ret = Max(ret, Dp(pos + 1, 1) + a[pos])
	}else {
		ret = Max(ret, Dp(pos + 1, 0) + c[pos])
		ret = Max(ret, Dp(pos + 1, 1) + b[pos])
	}

	dp[pos][prev] = ret
	return ret
}

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

func Next() string{
	if !in.Scan() {
		panic("Scan error")
	}
	return in.Text()
}

func NextInt() int{
	ret, _ := strconv.Atoi(Next())
	return ret
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF358D(_r io.Reader, out io.Writer) {
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	a := make([][3]int, n)
	for j := 0; j < 3; j++ {
		for i := range a {
			Fscan(in, &a[i][j])
		}
	}
	dp := make([][2]int, n+1)
	dp[0][0] = -1e9
	for i, v := range a {
		dp[i+1][0] = max(dp[i][0]+v[1], dp[i][1]+v[0])
		dp[i+1][1] = max(dp[i][0]+v[2], dp[i][1]+v[1])
	}
	Fprint(out, dp[n][0])
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF358D(_r io.Reader, out io.Writer) {
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	a := make([][3]int, n)
	for j := 0; j < 3; j++ {
		for i := range a {
			Fscan(in, &a[i][j])
		}
	}
	dp := make([][2]int, n+1)
	for i, v := range a {
		dp[i+1][0] = max(dp[i][1]+v[0], dp[i][0]+v[1])
		dp[i+1][1] = max(dp[i][1]+v[1], dp[i][0]+v[2])
	}
	Fprint(out, dp[n][0])
}

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


There is an infinite 2-dimensional grid. The robot stands in cell $$$(0, 0)$$$ and wants to reach cell $$$(x, y)$$$. Here is a list of possible commands the robot can execute:  move north from cell $$$(i, j)$$$ to $$$(i, j + 1)$$$;  move east from cell $$$(i, j)$$$ to $$$(i + 1, j)$$$;  move south from cell $$$(i, j)$$$ to $$$(i, j - 1)$$$;  move west from cell $$$(i, j)$$$ to $$$(i - 1, j)$$$;  stay in cell $$$(i, j)$$$. The robot wants to reach cell $$$(x, y)$$$ in as few commands as possible. However, he can't execute the same command two or more times in a row.What is the minimum number of commands required to reach $$$(x, y)$$$ from $$$(0, 0)$$$?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of testcases. Each of the next $$$t$$$ lines contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 10^4$$$) — the destination coordinates of the robot.

For each testcase print a single integer — the minimum number of commands required for the robot to reach $$$(x, y)$$$ from $$$(0, 0)$$$ if no command is allowed to be executed two or more times in a row.

NoteThe explanations for the example test:We use characters N, E, S, W and 0 to denote going north, going east, going south, going west and staying in the current cell, respectively.In the first test case, the robot can use the following sequence: NENENENENE.In the second test case, the robot can use the following sequence: NENENEN.In the third test case, the robot can use the following sequence: ESENENE0ENESE.In the fourth test case, the robot doesn't need to go anywhere at all.In the fifth test case, the robot can use the following sequence: E0E.

package main

import (
	"fmt"
)

func main() {

	t := 0
	fmt.Scanln(&t)

	for t > 0 {

		//var x, y = 0, 0
		step := 0
		//dir := 0
		var tx, ty int
		//pStep := 5

		fmt.Scanln(&tx, &ty)

		if tx == ty {
			step = 2 * tx
		} else {
			if tx > ty {
				step = 2*tx - 1
			} else {
				step = 2*ty - 1
			}
		}

		/*
			pri := priority(tx, ty)

			//dir := nStep(x, y, tx, ty, pStep)
			//fmt.Println(dir)

			for !(x == tx && y == ty) {

				switch pri {
				case 1:
					dir = nStep1(x, y, tx, ty, pStep)
				case 2:
					dir = nStep2(x, y, tx, ty, pStep)
				case 3:
					dir = nStep3(x, y, tx, ty, pStep)
				case 4:
					dir = nStep4(x, y, tx, ty, pStep)
				}

				//fmt.Printf("%d %d %d\n", x, y, dir)

				switch dir {
				case 4:
					x, y = up(x, y)
					pStep = 4
				case 1:
					x, y = right(x, y)
					pStep = 1
				case 2:
					x, y = down(x, y)
					pStep = 2
				case 3:
					x, y = left(x, y)
					pStep = 3
				case 0:
					pStep = 0
				}

				step++
			}
		*/

		fmt.Printf("%d\n", step)
		t--
	}

}

func priority(x int, y int) int {
	if abs(x) >= abs(y) {
		if x >= 0 {
			return 1
		} else {
			return 3
		}
	} else {
		if y >= 0 {
			return 4
		} else {
			return 2
		}
	}
}

func nStep1(x int, y int, tx int, ty int, pStep int) int {
	low := 2000
	dir := 5

	if abs(x+1-tx)+abs(y-ty) < low {
		if pStep != 1 {
			dir = 1
			low = abs(x+1-tx) + abs(y-ty)
		}
	}

	if abs(x-tx)+abs(y+1-ty) < low {
		if pStep != 4 {
			dir = 4
			low = abs(x-tx) + abs(y+1-ty)
		}
	}

	if abs(x-tx)+abs(y-ty) < low {
		if pStep != 0 {
			dir = 0
			low = abs(x-tx) + abs(y-ty)
		}
	}

	if abs(x-tx)+abs(y-1-ty) < low {
		if pStep != 2 {
			dir = 2
			low = abs(x-tx) + abs(y-1-ty)
		}
	}

	if abs(x-1-tx)+abs(y-ty) < low {
		if pStep != 3 {
			dir = 3
			low = abs(x-1-tx) + abs(y-ty)
		}
	}

	return dir
}

func nStep2(x int, y int, tx int, ty int, pStep int) int {
	low := 2000
	dir := 5

	if abs(x-tx)+abs(y-1-ty) < low {
		if pStep != 2 {
			dir = 2
			low = abs(x-tx) + abs(y-1-ty)
		}
	}

	if abs(x+1-tx)+abs(y-ty) < low {
		if pStep != 1 {
			dir = 1
			low = abs(x+1-tx) + abs(y-ty)
		}
	}

	if abs(x-tx)+abs(y+1-ty) < low {
		if pStep != 4 {
			dir = 4
			low = abs(x-tx) + abs(y+1-ty)
		}
	}

	if abs(x-tx)+abs(y-ty) < low {
		if pStep != 0 {
			dir = 0
			low = abs(x-tx) + abs(y-ty)
		}
	}

	if abs(x-1-tx)+abs(y-ty) < low {
		if pStep != 3 {
			dir = 3
			low = abs(x-1-tx) + abs(y-ty)
		}
	}

	return dir
}

func nStep3(x int, y int, tx int, ty int, pStep int) int {
	low := 2000
	dir := 5

	if abs(x-1-tx)+abs(y-ty) < low {
		if pStep != 3 {
			dir = 3
			low = abs(x-1-tx) + abs(y-ty)
		}
	}

	if abs(x-tx)+abs(y-1-ty) < low {
		if pStep != 2 {
			dir = 2
			low = abs(x-tx) + abs(y-1-ty)
		}
	}

	if abs(x+1-tx)+abs(y-ty) < low {
		if pStep != 1 {
			dir = 1
			low = abs(x+1-tx) + abs(y-ty)
		}
	}

	if abs(x-tx)+abs(y+1-ty) < low {
		if pStep != 4 {
			dir = 4
			low = abs(x-tx) + abs(y+1-ty)
		}
	}

	if abs(x-tx)+abs(y-ty) < low {
		if pStep != 0 {
			dir = 0
			low = abs(x-tx) + abs(y-ty)
		}
	}

	return dir
}

func nStep4(x int, y int, tx int, ty int, pStep int) int {
	low := 2000
	dir := 5

	if abs(x-tx)+abs(y+1-ty) < low {
		if pStep != 4 {
			dir = 4
			low = abs(x-tx) + abs(y+1-ty)
		}
	}

	if abs(x-1-tx)+abs(y-ty) < low {
		if pStep != 3 {
			dir = 3
			low = abs(x-1-tx) + abs(y-ty)
		}
	}

	if abs(x-tx)+abs(y-1-ty) < low {
		if pStep != 2 {
			dir = 2
			low = abs(x-tx) + abs(y-1-ty)
		}
	}

	if abs(x+1-tx)+abs(y-ty) < low {
		if pStep != 1 {
			dir = 1
			low = abs(x+1-tx) + abs(y-ty)
		}
	}

	if abs(x-tx)+abs(y-ty) < low {
		if pStep != 0 {
			dir = 0
			low = abs(x-tx) + abs(y-ty)
		}
	}

	return dir
}

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

func up(x int, y int) (int, int) {
	y = y + 1
	return x, y
}

func down(x int, y int) (int, int) {
	y = y - 1
	return x, y
}

func left(x int, y int) (int, int) {
	x = x - 1
	return x, y
}

func right(x int, y int) (int, int) {
	x = x + 1
	return x, y
}

/*
URL:
https://codeforces.com/contest/1452/problem/A
*/

package main

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

var (
	t    int
	x, y int
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		x, y = readi2()

		solve()
	}
}

func solve() {
	maxi := max(x, y)
	mini := min(x, y)

	a := maxi - mini

	// ans := 2*mini + (2*a - 1)
	ans := 2 * mini
	if a > 0 {
		ans += 2*a - 1
	}

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

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

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

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

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

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

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

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

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

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

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

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := pow(a, halfE)
		return half * half
	}

	return a * pow(a, e-1)
}

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

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

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

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

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

/*********** Input ***********/

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

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

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

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

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

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

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

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

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

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

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

	return res
}

package main

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

// 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(Case int) {
		var x,y int
		Fscan(in, &x, &y)
		if y > x {
			y, x = x, y
		}
		if x-y<=1 {
			Fprintln(out, x+y)
		} else {
			Fprintln(out, x+y+(x-y-1))
		}

	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}
}

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

package main

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

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var x, y int
		fmt.Fscan(input, &x, &y)

		if x > y {
			a := x
			x = y
			y = a
		}

		ans := x * 2
		if (y - x) > 1 {
			ans += ((y - x) * 2) - 1
		}

		if (y - x) == 1 {
			ans++
		}

		fmt.Println(ans)
	}
}

package main
import "fmt"
func max(a, b int) int {
	if a >= b {
		return a
	} else {
		return b
	}
}
func main() {
	q := 0
	fmt.Scan(&q)
	for t := 0; t < q; t++ {
		var x, y int
		fmt.Scan(&x, &y)
		res := 2 * max(x, y)
		if x != y {
			res--
		}
		fmt.Println(res)
	}
}

package main

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

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

	var t, x, y int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &x, &y)
		if x > y {
			x, y = y, x
		}
		if y-x <= 1 {
			fmt.Println(x + y)
		} else {
			fmt.Println(x + y + (y - x - 1))
		}
	}
}

package main
import "fmt"
func max(a, b int) int {
	if a >= b {
		return a
	} else {
		return b
	}
}
func main() {
	q := 0
	fmt.Scan(&q)
	for t := 0; t < q; t++ {
		var x, y int
		fmt.Scan(&x, &y)
		res := max(x, y)
		if x != y {
			res--
		}
		fmt.Println(res)
	}
}


You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c.You have to find minimum k such that there exists at least one k-dominant character.

The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000).

Print one number — the minimum value of k such that there exists at least one k-dominant character.

package main

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

var local = false
var scanner *bufio.Scanner

func main() {
	setup()

	mink := make(map[rune]int)
	link := make(map[rune]int)

	for i := 0; ; i++ {
		ch := readChar()
		if len(ch) < 1 || ch[0] < 97 || ch[0] > 122 {
			break
		}
		c := rune(ch[0])

		for k, v := range link {
			next := i - v
			if k != c {
				next++
			}
			mink[k] = int(math.Max(float64(next), float64(mink[k])))
		}

		if _, ok := link[c]; !ok {
			mink[c] = i + 1
		}
		link[c] = i
	}

	res := math.MaxInt32
	for _, v := range mink {
		res = int(math.Min(float64(res), float64(v)))
	}
	fmt.Println(res)
}

func setup() {
	source := os.Stdin
	if local == true {
		file, _ := os.Open("input.txt")
		source = file
	}
	scanner = bufio.NewScanner(source)
	scanner.Split(bufio.ScanRunes)
}

func readChar() string {
	scanner.Scan()
	ans := scanner.Text()
	return ans
}

package main

import (
	"fmt"
)

func main(){
	var alph = "qwertyuiopasdfghjklzxcvbnm"
	var s string
	fmt.Scan(&s)
	min := len(s)
	for i := range alph {
		max := 1
		counter := 1
		for j := range s {
			if alph[i] != s[j] {
				counter ++
				if counter > max {
					max = counter
				}
			} else {
				counter = 1
			}
		}
		if max < min {
			min = max
		}
	}
	fmt.Print(min)
}

package main

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

var local = false
var scanner *bufio.Scanner

func main() {
	setup()
	inp := readString()

	mink := make(map[rune]int)
	link := make(map[rune]int)

	for i, c := range inp {
		for k, v := range link {
			next := i - v
			if k != c {
				next++
			}
			mink[k] = int(math.Max(float64(next), float64(mink[k])))
		}

		if _, ok := link[c]; !ok {
			mink[c] = i + 1
		}
		link[c] = i
	}

	res := 100001
	for _, v := range mink {
		res = int(math.Min(float64(res), float64(v)))
	}
	fmt.Println(res)
}

func setup() {
	source := os.Stdin
	if local == true {
		file, _ := os.Open("input.txt")
		source = file
	}
	scanner = bufio.NewScanner(source)
	scanner.Split(bufio.ScanWords)
}

func readString() string {
	scanner.Scan()
	ans := scanner.Text()
	return ans
}

package main

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

var local = false
var scanner *bufio.Scanner

func main() {
	setup()
	inp := readString()

	mink := make(map[rune]int)
	link := make(map[rune]int)

	for i, c := range inp {
		for k, v := range link {
			next := i - v
			if k != c {
				next++
			}
			mink[k] = int(math.Max(float64(next), float64(mink[k])))
		}

		if _, ok := link[c]; !ok {
			mink[c] = i + 1
		}
		link[c] = i
	}

	res := math.MaxInt32
	for _, v := range mink {
		res = int(math.Min(float64(res), float64(v)))
	}
	fmt.Println(res)
}

func setup() {
	source := os.Stdin
	if local == true {
		file, _ := os.Open("input.txt")
		source = file
	}
	scanner = bufio.NewScanner(source)
	scanner.Split(bufio.ScanWords)
}

func readString() string {
	scanner.Scan()
	ans := scanner.Text()
	return ans
}


For a given sequence of distinct non-negative integers $$$(b_1, b_2, \dots, b_k)$$$ we determine if it is good in the following way:  Consider a graph on $$$k$$$ nodes, with numbers from $$$b_1$$$ to $$$b_k$$$ written on them. For every $$$i$$$ from $$$1$$$ to $$$k$$$: find such $$$j$$$ ($$$1 \le j \le k$$$, $$$j\neq i$$$), for which $$$(b_i \oplus b_j)$$$ is the smallest among all such $$$j$$$, where $$$\oplus$$$ denotes the operation of bitwise XOR (https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Next, draw an undirected edge between vertices with numbers $$$b_i$$$ and $$$b_j$$$ in this graph. We say that the sequence is good if and only if the resulting graph forms a tree (is connected and doesn't have any simple cycles). It is possible that for some numbers $$$b_i$$$ and $$$b_j$$$, you will try to add the edge between them twice. Nevertheless, you will add this edge only once.You can find an example below (the picture corresponding to the first test case). Sequence $$$(0, 1, 5, 2, 6)$$$ is not good as we cannot reach $$$1$$$ from $$$5$$$.However, sequence $$$(0, 1, 5, 2)$$$ is good.   You are given a sequence $$$(a_1, a_2, \dots, a_n)$$$ of distinct non-negative integers. You would like to remove some of the elements (possibly none) to make the remaining sequence good. What is the minimum possible number of removals required to achieve this goal?It can be shown that for any sequence, we can remove some number of elements, leaving at least $$$2$$$, so that the remaining sequence is good.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 200,000$$$) — length of the sequence. The second line contains $$$n$$$ distinct non-negative integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the elements of the sequence.

You should output exactly one integer — the minimum possible number of elements to remove in order to make the remaining sequence good.

NoteNote that numbers which you remove don't impact the procedure of telling whether the resulting sequence is good.It is possible that for some numbers $$$b_i$$$ and $$$b_j$$$, you will try to add the edge between them twice. Nevertheless, you will add this edge only once.

package main

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

// github.com/EndlessCheng/codeforces-go
type trieNode struct {
	son [2]*trieNode
	val int
}

type trie struct{ root *trieNode }

func newTrie() *trie {
	return &trie{&trieNode{}}
}

func (t *trie) put(s []byte, val int) *trieNode {
	o := t.root
	for _, b := range s {
		if o.son[b] == nil {
			o.son[b] = &trieNode{}
		}
		o = o.son[b]
	}
	o.val = val
	return o
}
func (o *trieNode) empty() bool {
	for _, son := range o.son {
		if son != nil {
			return false
		}
	}
	return true
}
func (t *trie) del(s []byte) {
	fa := make([]*trieNode, len(s)+1)
	o := t.root
	for i, b := range s {
		fa[i] = o
		o = o.son[b]
	}
	for i := len(s) - 1; i >= 0; i-- {
		f := fa[i]
		f.son[s[i]] = nil
		if !f.empty() {
			break
		}
	}
}
func (t *trie) minXor(s []byte) (ans int) {
	o := t.root
	for _, b := range s {
		if o.son[b] == nil {
			b ^= 1
		}
		o = o.son[b]
	}
	return o.val
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	bits31 := func(n int) []byte {
		bits := make([]byte, 31)
		for i := range bits {
			bits[i] = byte(n >> (30 - i) & 1)
		}
		return bits
	}

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	t := newTrie()
	for i := range a {
		Fscan(in, &a[i])
		v := a[i]
		s := bits31(v)
		t.put(s, i)
	}

	//cnt := [40]int{}
	var f func(o *trieNode) (save, size int)
	f = func(o *trieNode) (save, size int) {
		if o.son[0] == nil && o.son[1] == nil {
			return 1, 1
		}
		if o.son[0] ==nil {
			return f(o.son[1])
		}
		if o.son[1] ==nil {
			return f(o.son[0])
		}
		save0, size0 := f(o.son[0])
		save1, size1 := f(o.son[1])

		save = max(save0,save1)+1

		size =  size0 + size1
		return
	}
	save, _ := f(t.root)
//Println(size,n)
//println(save)
	ans := n-save

	//left := 0
	//for _, c := range cnt[1:] {
	//	if c > 1 {
	//		left++
	//	}
	//}

	//ans := 0
	//another := make([]int, n)
	//for _i := range another {
	//	another[_i] = -1
	//}
	//for i, v := range a {
	//	s := bits31(v)
	//	t.del(s)
	//	id := t.minXor(s)
	//	if another[id] == i {
	//		ans++
	//	}
	//	another[i] = id
	//	t.put(s, i)
	//}
	//for i, id := range another {
	//	Fprintln(out, a[i],a[id])
	//}

	Fprintln(out, ans)
}

func main() { run(os.Stdin, os.Stdout) }
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

package main

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

// github.com/EndlessCheng/codeforces-go
type trieNode struct {
	son [2]*trieNode
	val int
}

type trie struct{ root *trieNode }

func newTrie() *trie {
	return &trie{&trieNode{}}
}

func (t *trie) put(s []byte, val int) *trieNode {
	o := t.root
	for _, b := range s {
		if o.son[b] == nil {
			o.son[b] = &trieNode{}
		}
		o = o.son[b]
	}
	o.val = val
	return o
}
func (o *trieNode) empty() bool {
	for _, son := range o.son {
		if son != nil {
			return false
		}
	}
	return true
}
func (t *trie) del(s []byte) {
	fa := make([]*trieNode, len(s)+1)
	o := t.root
	for i, b := range s {
		fa[i] = o
		o = o.son[b]
	}
	for i := len(s) - 1; i >= 0; i-- {
		f := fa[i]
		f.son[s[i]] = nil
		if !f.empty() {
			break
		}
	}
}
func (t *trie) minXor(s []byte) (ans int) {
	o := t.root
	for _, b := range s {
		if o.son[b] == nil {
			b ^= 1
		}
		o = o.son[b]
	}
	return o.val
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	bits31 := func(n int) []byte {
		bits := make([]byte, 31)
		for i := range bits {
			bits[i] = byte(n >> (30 - i) & 1)
		}
		return bits
	}

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	t := newTrie()
	for i := range a {
		Fscan(in, &a[i])
		v := a[i]
		s := bits31(v)
		t.put(s, i)
	}
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
		_ = min
	var f func(o *trieNode) (needDel int)
	f = func(o *trieNode) (needDel int) {
		if o.son[0] == nil && o.son[1] == nil {
			return 0
		}
		if o.son[0] == nil {
			return f(o.son[1])
		}
		if o.son[1] == nil {
			return f(o.son[0])
		}
		l, r := f(o.son[0]), f(o.son[1])
		if l ==0 && r ==0 {
			return 1
		}
		res := l + r

		return res
	}
	ans := f(t.root)

	//ans := 0
	//another := make([]int, n)
	//for _i := range another {
	//	another[_i] = -1
	//}
	//for i, v := range a {
	//	s := bits31(v)
	//	t.del(s)
	//	id := t.minXor(s)
	//	if another[id] == i {
	//		ans++
	//	}
	//	another[i] = id
	//	t.put(s, i)
	//}
	//for i, id := range another {
	//	Fprintln(out, a[i],a[id])
	//}

	Fprintln(out, ans-1)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
type trieNode struct {
	son [2]*trieNode
	val int
}

type trie struct{ root *trieNode }

func newTrie() *trie {
	return &trie{&trieNode{}}
}

func (t *trie) put(s []byte, val int) *trieNode {
	o := t.root
	for _, b := range s {
		if o.son[b] == nil {
			o.son[b] = &trieNode{}
		}
		o = o.son[b]
	}
	o.val = val
	return o
}
func (o *trieNode) empty() bool {
	for _, son := range o.son {
		if son != nil {
			return false
		}
	}
	return true
}
func (t *trie) del(s []byte) {
	fa := make([]*trieNode, len(s)+1)
	o := t.root
	for i, b := range s {
		fa[i] = o
		o = o.son[b]
	}
	for i := len(s) - 1; i >= 0; i-- {
		f := fa[i]
		f.son[s[i]] = nil
		if !f.empty() {
			break
		}
	}
}
func (t *trie) minXor(s []byte) (ans int) {
	o := t.root
	for _, b := range s {
		if o.son[b] == nil {
			b ^= 1
		}
		o = o.son[b]
	}
	return o.val
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	bits31 := func(n int) []byte {
		bits := make([]byte, 31)
		for i := range bits {
			bits[i] = byte(n >> (30 - i) & 1)
		}
		return bits
	}

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	t := newTrie()
	for i := range a {
		Fscan(in, &a[i])
		v := a[i]
		s := bits31(v)
		t.put(s, i)
	}

	ans := 0
	another := make([]int, n)
	for _i := range another {
		another[_i] = -1
	}
	for i, v := range a {
		s := bits31(v)
		t.del(s)
		id := t.minXor(s)
		if another[id] == i {
			ans++
		}
		another[i] = id
		t.put(s, i)
	}
	Fprintln(out, ans-1)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
type trieNode struct {
	son [2]*trieNode
	val int
}

type trie struct{ root *trieNode }

func newTrie() *trie {
	return &trie{&trieNode{}}
}

func (t *trie) put(s []byte, val int) *trieNode {
	o := t.root
	for _, b := range s {
		if o.son[b] == nil {
			o.son[b] = &trieNode{}
		}
		o = o.son[b]
	}
	o.val = val
	return o
}
func (o *trieNode) empty() bool {
	for _, son := range o.son {
		if son != nil {
			return false
		}
	}
	return true
}
func (t *trie) del(s []byte) {
	fa := make([]*trieNode, len(s)+1)
	o := t.root
	for i, b := range s {
		fa[i] = o
		o = o.son[b]
	}
	for i := len(s) - 1; i >= 0; i-- {
		f := fa[i]
		f.son[s[i]] = nil
		if !f.empty() {
			break
		}
	}
}
func (t *trie) minXor(s []byte) (ans int) {
	o := t.root
	for _, b := range s {
		if o.son[b] == nil {
			b ^= 1
		}
		o = o.son[b]
	}
	return o.val
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	bits31 := func(n int) []byte {
		bits := make([]byte, 31)
		for i := range bits {
			bits[i] = byte(n >> (30 - i) & 1)
		}
		return bits
	}

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	t := newTrie()
	for i := range a {
		Fscan(in, &a[i])
		v := a[i]
		s := bits31(v)
		t.put(s, i)
	}
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	_ = min
	cnt := [40]int{}
	var f func(o *trieNode, d int)
	f = func(o *trieNode, d int) {
		if o == nil {
			return
		}

		if o.son[0] != nil && o.son[1] != nil {
			cnt[d]++
		}

		f(o.son[0], d+1)

		f(o.son[1], d+1)

	}
	f(t.root, 0)

	ans := 0
	for _, c := range cnt[1:] {
		if c > 1 {
			ans += c - 1
		}
	}

	//ans := 0
	//another := make([]int, n)
	//for _i := range another {
	//	another[_i] = -1
	//}
	//for i, v := range a {
	//	s := bits31(v)
	//	t.del(s)
	//	id := t.minXor(s)
	//	if another[id] == i {
	//		ans++
	//	}
	//	another[i] = id
	//	t.put(s, i)
	//}
	//for i, id := range another {
	//	Fprintln(out, a[i],a[id])
	//}

	Fprintln(out, ans)
}

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


You are given an integer $$$n$$$. You have to apply $$$m$$$ operations to it.In a single operation, you must replace every digit $$$d$$$ of the number with the decimal representation of integer $$$d + 1$$$. For example, $$$1912$$$ becomes $$$21023$$$ after applying the operation once.You have to find the length of $$$n$$$ after applying $$$m$$$ operations. Since the answer can be very large, print it modulo $$$10^9+7$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^5$$$) — the number of test cases. The only line of each test case contains two integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$m$$$ ($$$1 \le m \le 2 \cdot 10^5$$$) — the initial number and the number of operations.

For each test case output the length of the resulting number modulo $$$10^9+7$$$.

NoteFor the first test, $$$1912$$$ becomes $$$21023$$$ after $$$1$$$ operation which is of length $$$5$$$.For the second test, $$$5$$$ becomes $$$21$$$ after $$$6$$$ operations which is of length $$$2$$$.For the third test, $$$999$$$ becomes $$$101010$$$ after $$$1$$$ operation which is of length $$$6$$$.For the fourth test, $$$88$$$ becomes $$$1010$$$ after $$$2$$$ operations which is of length $$$4$$$.

package main

import (
	"bufio"
	"fmt"
	"os"
)
var mod = 1000000007
type M struct{
	m [15][15]int
	r int
	c int
}
func mul(x M, y M) M{
	var ret M
	for i:=1;i<=x.r;i++{
		for j:=1;j<=y.c;j++{
			for k:=1;k<=x.c;k++ {
				ret.m[i][j] += x.m[i][k]*y.m[k][j]%mod
				ret.m[i][j]%=mod
			}
		}
	}
	ret.c = y.c
	ret.r = x.r
	return ret
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	f := [200050]int{}
	for i:=0;i<9;i++{
		f[i]=2
	}
	f[9]=3
	for i:=10;i<=200005;i++{
		f[i]=(f[i-9]+f[i-10])%mod
	}
	for u:=1;u<=t;u++{
		var n, m int
		fmt.Fscan(in,&n,&m)
		ans := 0
		for n>0{
			now := n%10
			if m+now<10{
				ans++
				ans %=mod
			}else{
				ans += f[m+now-10]
				ans %= mod
			}
			n/=10
		}
		fmt.Fprintln(out,ans)
	}
}

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	p:= int64(1E9+7)
	table := [200010][10]int64 {}
	table[0][0]=1

	for i := 0; i < len(table)-1; i++ {
		new0 := table[i][9] % p
		new1 := table[i][9] % p
		for j := 9; j >= 1; j-- {
			table[i+1][j] = table[i][j-1]
		}
		table[i+1][0] = new0 % p
		table[i+1][1] = (new1 + table[i+1][1]) % p
	}

	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)
	for oi:=0; oi < k ; oi ++ {
		pln, _ := Readln(reader)
		ln := strings.Split(pln, " ")
		og := []byte (ln[0])
		times,_ :=  strconv.Atoi(ln[1])

		res:=int64(0)
		for i:= range og {
			n:= times+int(og[i]-48)
			temp:= table[n]
			for _,v := range temp{
				res+=v
			}
		}
		fmt.Println(res % p)

	}

}

package main

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

const modulo = 1000000007

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	max := 200100
	type cell struct {
		digits [10]int64
		d      int64
	}
	dp := make([]cell, max)
	dp[0] = cell{digits: [10]int64{1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, d: 1}
	for i := 1; i < max; i++ {
		digits := dp[i-1].digits
		nextDigits := [10]int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
		for j := 0; j < 9; j++ {
			nextDigits[j+1] = digits[j]
		}
		nextDigits[0] = (nextDigits[0] + digits[9]) % modulo
		nextDigits[1] = (nextDigits[1] + digits[9]) % modulo
		var nd int64 = 0
		for j := 0; j < 10; j++ {
			nd = (nd + nextDigits[j]) % modulo
		}
		dp[i] = cell{digits: nextDigits, d: nd}
	}
	var T, n, k int
	Fscan(in, &T)
	for t := T; t > 0; t-- {
		Fscan(in, &n, &k)

		digits := [10]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

		for n > 0 {
			x := modi(n, 10)
			digits[x]++
			n /= 10
		}

		var result int64 = 0
		for d := 0; d < 10; d++ {
			digitCount := digits[d]
			idx := d + k
			dpv := dp[idx].d
			// result += mod(int64(digitCount)*dpv, modulo)
			for i := 0; i < digitCount; i++ {
				result = (dpv + result) % modulo
			}
		}
		Fprintln(out, result)
	}
}

func modi(a, b int) int {
	return (a%b + b) % b
}

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()
	const mod int = 1e9 + 7

	dp := make([][]int, 10)
	for i := range dp {
		dp[i] = make([]int, 2e5+1)
		for j := range dp[i] {
			dp[i][j] = -1
		}
	}
	var f func(int, int) int
	f = func(d, k int) (res int) {
		if k == 0 {
			return 1
		}
		dv := &dp[d][k]
		if *dv != -1 {
			return *dv
		}
		defer func() { *dv = res }()
		if d == 9 {
			return (f(1, k-1) + f(0, k-1)) % mod
		}
		return f(d+1, k-1)
	}

	solve := func(Case int) {
		var n, k, ans int
		Fscan(in, &n, &k)

		for x := n; x > 0; x /= 10 {
			d := x % 10
			res := f(d, k)
			ans = (ans + res) % mod
		}
		Fprintln(out, ans)
	}

	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}
	_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"
)

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 min_int(a int, b int) int { if a < b { return a } else { return b } }
func min_int64(a int64, b int64) int64 { if a < b { return a } else { return b } }

func max_int(a int, b int) int { if a > b { return a } else { return b } }
func max_int64(a int64, b int64) int64 { if a > b { return a } else { return b } }

func main() {
	defer writer.Flush()

	var T int = 0
	scanf("%d\n", &T)

	const MAX_M int = 200007
	var dp [MAX_M]int

	for i := 0; i <= 8; i++ {
		dp[i] = 2
	}

	dp[9] = 3

	var MOD_FACTOR = 1000000000 + 7

	for i := 10; i < MAX_M; i++ {
		dp[i] = (dp[i-9] + dp[i-10]) % MOD_FACTOR
	}

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

		var n string
		var m int
		scanf("%s %d\n", &n, &m);

		var res int = 0
		for _, r := range n {
			var d int = int(r - '0')
			if (m + d < 10) {
				res = (res % MOD_FACTOR + 1) % MOD_FACTOR
			} else {
				res = ((res % MOD_FACTOR) + (dp[m + d - 10] % MOD_FACTOR)) % MOD_FACTOR
			}
		}

		printf("%d\n", res)

	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var mod = 1000000007
type M struct{
	m [15][15]int
	r int
	c int
}
func mul(x M, y M) M{
	var ret M
	for i:=1;i<=x.r;i++{
		for j:=1;j<=y.c;j++{
			for k:=1;k<=x.c;k++ {
				ret.m[i][j] += x.m[i][k]*y.m[k][j]%mod
				ret.m[i][j]%=mod
			}
		}
	}
	return ret
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for u:=1;u<=t;u++{
		var n, m int
		fmt.Fscan(in,&n,&m)
		f:=[10]int{}
		temp := n
		for temp>0{
			f[temp%10]++
			temp = temp/10
		}
		var a M
		for i:=1;i<=10;i++{
			a.m[i][1]=f[i-1]
		}
		a.c=1
		a.r=10
		var b M
		for i:=1;i<=10;i++{
			if i==1{
				b.m[i][10]=1
				continue
			}
			if i==2{
				b.m[i][1]=1
				b.m[i][10]=1
				continue
			}
			b.m[i][i-1]=1
		}
		b.r=10
		b.c=10
		cnt := m
		for cnt>0{
			if cnt%2==1{
				a = mul(b,a)
			}
			b = mul(b,b)
			cnt = cnt>>1
		}
		ans := 0
		for i:=1;i<=10;i++{
			ans = (ans +a.m[i][1])%mod
		}
		fmt.Fprintln(out,ans)
	}
}

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	p:= int(1E9+7)
	table := [200010][10]int {}
	table[0][0]=1

	for i := 0; i < len(table)-1; i++ {
		new0 := table[i][9] % p
		new1 := table[i][9] % p
		for j := 9; j >= 1; j-- {
			table[i+1][j] = table[i][j-1]
		}
		table[i+1][0] = new0 % p
		table[i+1][1] = (new1 + table[i+1][1]) % p
	}

	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)
	for oi:=0; oi < k ; oi ++ {
		pln, _ := Readln(reader)
		ln := strings.Split(pln, " ")
		og := []byte (ln[0])
		times,_ :=  strconv.Atoi(ln[1])

		res:=0
		for i:= range og {
			n:= times+int(og[i]-48)
			temp:= table[n]
			for _,v := range temp{
				res+=v
			}
		}
		fmt.Println(res % p)

	}

}

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	p:= int(1E9+7)
	table := [100010][10]int {}
	table[0][0]=1

	for i := 0; i < len(table)-1; i++ {
		new0 := table[i][9] % p
		new1 := table[i][9] % p
		for j := 9; j >= 1; j-- {
			table[i+1][j] = table[i][j-1]
		}
		table[i+1][0] = new0 % p
		table[i+1][1] = (new1 + table[i+1][1]) % p
	}

	fmt.Println(table[100:200])

	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)
	for oi:=0; oi < k ; oi ++ {
		pln, _ := Readln(reader)
		ln := strings.Split(pln, " ")
		og := []byte (ln[0])
		times,_ :=  strconv.Atoi(ln[1])

		res:=0
		for i:= range og {
			n:= times+int(og[i]-48)
			temp:= table[n]
			for _,v := range temp{
				res+=v
			}
		}
		fmt.Println(res % p)

	}

}

package main

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

const modulo = 1000000007

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	max := 200100
	type cell struct {
		digits [10]int64
		d      int64
	}
	dp := make([]cell, max)
	dp[0] = cell{digits: [10]int64{1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, d: 1}
	for i := 1; i < max; i++ {
		digits := dp[i-1].digits
		nextDigits := [10]int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
		for j := 0; j < 9; j++ {
			nextDigits[j+1] = digits[j]
		}
		nextDigits[0] += digits[9]
		nextDigits[1] += digits[9]
		var nd int64 = 0
		for j := 0; j < 10; j++ {
			nd = mod(nd+nextDigits[j], modulo)
		}
		dp[i] = cell{digits: nextDigits, d: nd}
	}
	var T, n, k int
	Fscan(in, &T)
	for t := T; t > 0; t-- {
		Fscan(in, &n, &k)
		s := strconv.Itoa(n)
		l := len(s)
		digits := [10]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
		for i := 0; i < l; i++ {
			digits[s[i]-48] += 1
		}

		var result int64 = 0
		for d := 0; d < 10; d++ {
			digitCount := digits[d]
			idx := d + k
			dpv := dp[idx].d
			for i := 0; i < digitCount; i++ {
				result = mod(dpv+result, modulo)
			}
		}
		Fprintln(out, result)
	}
}

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

package main

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

const modulo = 1000000007

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	max := 200001
	type cell struct {
		digits [10]int64
		d      int64
	}
	dp := make([]cell, max)
	dp[0] = cell{digits: [10]int64{1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, d: 1}
	for i := 1; i < max; i++ {
		digits := dp[i-1].digits
		nextDigits := [10]int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
		for j := 0; j < 9; j++ {
			nextDigits[j+1] = digits[j]
		}
		nextDigits[0] += digits[9]
		nextDigits[1] += digits[9]
		var nd int64 = 0
		for j := 0; j < 10; j++ {
			nd = mod(nd+nextDigits[j], modulo)
		}
		dp[i] = cell{digits: nextDigits, d: nd}
	}
	var T, n, k int
	Fscan(in, &T)
	for t := T; t > 0; t-- {
		Fscan(in, &n, &k)
		s := strconv.Itoa(n)
		l := len(s)
		digits := [10]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
		for i := 0; i < l; i++ {
			digits[s[i]-48] += 1
		}
		Printf("%+v\n", digits)

		var result int64 = 0
		for d := 0; d < 10; d++ {
			digitCount := digits[d]
			idx := d + k
			dpv := dp[idx].d
			for i := 0; i < digitCount; i++ {
				result = mod(dpv+result, modulo)
				Println(result)
			}
		}
		Fprintln(out, result)
	}
}

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

package main

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

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

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

func min_int(a int, b int) int { if a < b { return a } else { return b } }
func min_int64(a int64, b int64) int64 { if a < b { return a } else { return b } }

func max_int(a int, b int) int { if a > b { return a } else { return b } }
func max_int64(a int64, b int64) int64 { if a > b { return a } else { return b } }

func main() {
	defer writer.Flush()

	var T int = 0
	scanf("%d\n", &T)

	const MAX_M int = 200007
	var dp [MAX_M]int

	for i := 0; i <= 8; i++ {
		dp[i] = 2
	}

	dp[9] = 3

	for i := 10; i < MAX_M; i++ {
		dp[i] = dp[i-9] + dp[i-10]
	}

	var MOD_FACTOR = 1000000000 + 7

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

		var n string
		var m int
		scanf("%s %d\n", &n, &m);

		var res int = 0
		for _, r := range n {
			var d int = int(r - '0')
			if (m + d < 10) {
				res = (res % MOD_FACTOR + 1) % MOD_FACTOR
			} else {
				res = ((res % MOD_FACTOR) + (dp[m + d - 10] % MOD_FACTOR)) % MOD_FACTOR
			}
		}

		printf("%d\n", res)

	}

}