You are given a multiset $$$S$$$ initially consisting of $$$n$$$ distinct non-negative integers. A multiset is a set, that can contain some elements multiple times.You will perform the following operation $$$k$$$ times:   Add the element $$$\lceil\frac{a+b}{2}\rceil$$$ (rounded up) into $$$S$$$, where $$$a = \operatorname{mex}(S)$$$ and $$$b = \max(S)$$$. If this number is already in the set, it is added again. Here $$$\operatorname{max}$$$ of a multiset denotes the maximum integer in the multiset, and $$$\operatorname{mex}$$$ of a multiset denotes the smallest non-negative integer that is not present in the multiset. For example:    $$$\operatorname{mex}(\{1,4,0,2\})=3$$$;   $$$\operatorname{mex}(\{2,5,1\})=0$$$. Your task is to calculate the number of distinct elements in $$$S$$$ after $$$k$$$ operations will be done.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$1\le n\le 10^5$$$, $$$0\le k\le 10^9$$$) — the initial size of the multiset $$$S$$$ and how many operations you need to perform. The second line of each test case contains $$$n$$$ distinct integers $$$a_1,a_2,\dots,a_n$$$ ($$$0\le a_i\le 10^9$$$) — the numbers in the initial multiset. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print the number of distinct elements in $$$S$$$ after $$$k$$$ operations will be done.

package main

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

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

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

func main() {
	defer writer.Flush()
	////////////////////
	c := 0
	scan(&c)
	for c != 0 {
		solve()
		c--
	}
}

func solve() {
	n, k := 0, 0
	max := 0
	scan(&n, &k)
	m := make([]int, n)
	for i := 0; i < n; i++ {
		scan(&m[i])
		if max < m[i] {
			max = m[i]
		}
	}
	if k == 0 {
		print(n, "\n")
		return
	}
	sort.Ints(m)
	mex := -1
	for i := 0; i < n; i++ {
		if m[i] != i {
			mex = i
			break
		}
	}
	if mex == -1 {
		print(n+k, "\n")
		return
	}
	t := (max + mex + 1) / 2
	for _, v := range m {
		if v == t {
			print(n, "\n")
			return
		}
		if v > t {
			break
		}
	}
	print(n+1, "\n")
}

package main

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

func getNextString(scanner *bufio.Scanner) string {
	if !scanner.Scan() {
		panic("scan failed")
	}
	return scanner.Text()
}
func atoi(s string) int                             { x, _ := strconv.Atoi(s); return x }
func getNextInt(scanner *bufio.Scanner) int         { return atoi(getNextString(scanner)) }
func atoi64(s string) int64                         { x, _ := strconv.ParseInt(s, 10, 64); return x }
func getNextInt64(scanner *bufio.Scanner) int64     { return atoi64(getNextString(scanner)) }
func atof64(s string) float64                       { x, _ := strconv.ParseFloat(s, 64); return x }
func getNextFloat64(scanner *bufio.Scanner) float64 { return atof64(getNextString(scanner)) }
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	t := getNextInt(scanner)
	for t > 0 {
		t--
		func() {
			n := getNextInt(scanner)
			k := getNextInt(scanner)
			aa := make([]int64, n)
			exists := map[int64]bool{}
			for i := 0; i < n; i++ {
				aa[i] = getNextInt64(scanner)
				exists[aa[i]] = true
			}
			l := len(exists)
			if k == 0 {
				fmt.Fprintln(writer, l)
				return
			}
			sort.Slice(aa, func(i, j int) bool {
				return aa[i] < aa[j]
			})
			var ex, ax int64
			for i := 0; i < n+1 && exists[ex]; i++ {
				ex++
			}
			ax = aa[n-1]
			if ex > ax {
				fmt.Fprintln(writer, k+l)
				return
			}
			if exists[(ex+ax+1)/2] {
				fmt.Fprintln(writer, l)
				return
			}
			fmt.Fprintln(writer, len(exists)+1)
		}()
	}
}

package main

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

type i64 int64

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

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

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

func main() {
	var t int
	scanf("%d\n", &t)
	for t > 0 {
		var n, k, i i64
		scanf("%d %d\n", &n, &k)
		arr := make([]i64, n)
		b := i64(math.MinInt64)
		mp := make(map[i64]bool)
		for i = 0; i < n; i++ {
			if i == n-1 {
				scanf("%d\n", &arr[i])
			} else {
				scanf("%d ", &arr[i])
			}
			mp[arr[i]] = true
			b = max(b, arr[i])
		}
		if k == 0 {
			fmt.Println(n)
		} else {
			a := i64(0) //mex
			for i = 0; i <= n; i++ {
				if mp[i] == false {
					a = i
					break
				}
			}
			if a > b {
				fmt.Println(n + k)
			} else {
				ans := len(arr)
				val := (a + b + 1) / 2
				if mp[val] == false {
					ans++
				}
				fmt.Println(ans)
			}
		}
		t--
	}
}

package main

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

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

	for tc := 0; tc < tcs; tc++ {
		var n, k int
		_, _ = fmt.Fscan(in, &n, &k)

		hole := false

		mp := make(map[int]bool)
		for i := 0; i < n; i++ {
			var temp int
			_, _ = fmt.Fscan(in, &temp)

			if temp >= n {
				hole = true
			}

			mp[temp] = true
		}

		if k == 0 {
			fmt.Println(len(mp))
			continue
		}

		if hole {
			high := max(mp)
			mid := mex(mp)

			mp[(high+mid+1)/2] = true

			fmt.Println(len(mp))
			continue
		} else {
			fmt.Println(n + k)
		}

	}
}

func max(mp map[int]bool) int {
	ans := -1

	for k := range mp {
		if ans < k {
			ans = k
		}
	}

	return ans
}

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

	return -1
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, k := 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &k)
		o, mex, max, l := map[int]int{}, -1, -1, 0
		for j := 0; j < n; j++ {
			p := 0
			fmt.Fscan(f, &p)
			if p > max {
				max = p
			}
			o[p]++
		}
		for {
			_, ok := o[l]
			if !ok {
				mex = l
				break
			}
			l++
		}
		if n == len(o) && max == n-1 || k == 0 {
			fmt.Fprintln(w, n+k)
		} else {
			_, ok := o[(mex+max+1)>>1]
			if !ok {
				fmt.Fprintln(w, len(o)+1)
			} else {
				fmt.Fprintln(w, len(o))
			}
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

var T int
func main() {
    in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	for Fscan(in, &T); T > 0; T-- {
	    var n, k int
	    set := make(map[int]bool)
	    Fscan(in, &n)
	    Fscan(in, &k)
	    var s []int
	    for i := 0; i < n; i++ {
	        var x int
	        Fscan(in, &x)
	        s = append(s, x)
	        set[x] = true
	    }
	    if k == 0 {
	        Fprintln(out, n)
	        continue
	    }
	    sort.Slice(s, func(i, j int) bool {
		    return s[i] < s[j]
	    })
	    var mex, max = 0, 0
	    for _, value := range(s) {
	        if value > max {
	            max = value
	        }
	    }
	    if s[0] > 0 {
	        mex = 0
	    } else {
	        for i := 1; i < n; i++ {
	            if s[i] > s[i - 1] + 1 {
	                mex = s[i - 1] + 1
	                break
	            }
	        }
	        if mex == 0 {
	            mex = s[n - 1] + 1
	        }
	    }
	    var ans int = n
	    if (mex == max + 1)  {
	        ans += k
	    } else {
	        m := (mex + max + 1) / 2
	        if set[m] == false {
	            ans++
	        }
	    }
	    Fprintln(out, ans)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		var n, k int
		fmt.Fscan(in, &n, &k)
		isInS := make(map[int]bool, n)
		set := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &set[i])
			isInS[set[i]] = true
		}
		sort.Sort(sort.IntSlice(set))
		mex := Mex(set)
		max := set[len(set)-1]
		var res int64
		if mex == max {
			res = int64(n) + int64(k)
		} else {
			avg := int(math.Ceil((float64(mex) + float64(max)) / 2))
			if !isInS[avg] && k > 0 {
				res = int64(n) + 1
			} else {
				res = int64(n)
			}
		}
		fmt.Printf("%d\n", res)
		t--
	}
}

func Mex(set []int) int {
	for i := 0; i < len(set); i++ {
		if i != set[i] {
			return i
		}
	}
	return set[len(set)-1]
}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n, k, mex, max int
		m := make(map[int]bool)
		fmt.Fscan(in, &n, &k)
		for i := 0; i < n; i++ {
			var tp int
			fmt.Fscan(in, &tp)
			m[tp] = true
			if tp > max {
				max = tp
			}
		}
		if max == n-1 {
			fmt.Println(n + k)
			continue
		}
		for i := 0; i <= 100_000; i++ {
			if m[i] == false {
				mex = i
				break
			}
		}
		// log.Printf("mex: %#+v\n", mex)
		// log.Printf("max: %#+v\n", max)
		tp := (mex + max + 1) / 2
		// log.Printf("tp: %#+v\n", tp)
		if !m[tp] && k > 0 {
			fmt.Println(n + 1)
		} else {
			fmt.Println(n)
		}
	}
}

package main

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

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

	var T, n, k, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		mx := 0
		s := map[int]bool{}
		for i := 0; i < n; i++ {
			Fscan(in, &v)
			if v > mx {
				mx = v
			}
			s[v] = true
		}
		mex := 0
		for ; s[mex]; mex++ {
		}
		if mex > mx {
			Fprintln(out, len(s)+k)
		} else if k > 0 && !s[(mex+mx+1)/2] {
			Fprintln(out, len(s)+1)
		} else {
			Fprintln(out, len(s))
		}
	}
}

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

package main

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

}

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

var t int

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

		var n, k int
		fmt.Fscan(input, &n)
		fmt.Fscan(input, &k)

		ARRAY := make([]int64, n)

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

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

		if k == 0 {
			fmt.Println(n)
		} else {
			if ARRAY[n-1] == int64(n-1) {
				fmt.Println(n + k)
			} else {
				var indd int64
				for i := 0; i < n; i++ {
					if ARRAY[i] > int64(i) {
						indd = int64(i)
						break
					}
				}
				m := ARRAY[n-1]
				nnn := int64((m + indd + 1) / 2)
				g := 0
				for j := 0; j < n; j++ {
					if ARRAY[j] == nnn {
						g = 1
					}
					if ARRAY[j] > nnn {
						break
					}
				}
				if g == 1 {
					fmt.Println(n)
				} else {
					fmt.Println(n + 1)

				}

			}
		}

	}
}

package main

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

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

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

func main() {
	defer writer.Flush()
	////////////////////
	c := 0
	scan(&c)
	for c != 0 {
		solve()
		c--
	}
}

func solve() {
	n, k := 0, 0
	max := 0
	scan(&n, &k)
	m := make([]int, n)
	for i := 0; i < n; i++ {
		scan(&m[i])
		if max < m[i] {
			max = m[i]
		}
	}
	if k == 0 {
		print(n, "\n")
		return
	}
	sort.Ints(m)
	mex := -1
	for i := 0; i < n; i++ {
		if m[i] != i {
			mex = i
			break
		}
	}
	if mex == -1 {
		print(n+k, "\n")
		return
	}
	t := (max + mex + 1) / 2
	if t == n {
		print(n+1, "\n")
	} else {
		print(n, "\n")
	}
}

package main

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

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

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

func main() {
	defer writer.Flush()
	////////////////////
	c := 0
	scan(&c)
	for c != 0 {
		solve()
		c--
	}
}

func solve() {
	n, k := 0, 0
	max := 0
	scan(&n, &k)
	m := make(map[int]int)
	for i := 0; i < n; i++ {
		t := 0
		scan(&t)
		if max < t {
			max = t
		}
		m[t]++

	}
	mex := make([]int, 1e5)
	f := 0
	o := 0
	for i := 0; i < 1e5; i++ {
		if f == k {
			break
		}
		if m[i] == 0 {
			mex[f] = i
			f++
		}
	}
	for i := 0; i < k; i++ {
		t := (max + mex[o] + 1) / 2
		m[t]++

		if t != mex[o] && t <= max {
			break
		}
		if t == mex[o] {
			o++
		}
		if t > max {
			max = t
		}
	}
	print(len(m), "\n")
}

package main

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

func getNextString(scanner *bufio.Scanner) string {
	if !scanner.Scan() {
		panic("scan failed")
	}
	return scanner.Text()
}
func atoi(s string) int                             { x, _ := strconv.Atoi(s); return x }
func getNextInt(scanner *bufio.Scanner) int         { return atoi(getNextString(scanner)) }
func atoi64(s string) int64                         { x, _ := strconv.ParseInt(s, 10, 64); return x }
func getNextInt64(scanner *bufio.Scanner) int64     { return atoi64(getNextString(scanner)) }
func atof64(s string) float64                       { x, _ := strconv.ParseFloat(s, 64); return x }
func getNextFloat64(scanner *bufio.Scanner) float64 { return atof64(getNextString(scanner)) }
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	t := getNextInt(scanner)
	for t > 0 {
		t--
		func() {
			n := getNextInt(scanner)
			k := getNextInt(scanner)
			aa := make([]int64, n)
			exists := map[int64]bool{}
			for i := 0; i < n; i++ {
				aa[i] = getNextInt64(scanner)
				exists[aa[i]] = true
			}
			l := len(exists)
			if k == 0 {
				fmt.Fprintln(writer, l)
				return
			}
			sort.Slice(aa, func(i, j int) bool {
				return aa[i] < aa[j]
			})
			var ex, ax int64
			for i := 0; i < n+1 && exists[ex]; i++ {
				ex++
			}
			ax = aa[n-1]
			if ex > ax {
				fmt.Fprintln(writer, k+l)
				return
			}
			if exists[(ex+ax)/2] {
				fmt.Fprintln(writer, l)
				return
			}
			if ex+1 == ax && !exists[ex] {
				fmt.Fprintln(writer, l+k)
				return
			}
			fmt.Fprintln(writer, len(exists)+1)
		}()
	}
}

package main

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

func getNextString(scanner *bufio.Scanner) string {
	if !scanner.Scan() {
		panic("scan failed")
	}
	return scanner.Text()
}
func atoi(s string) int                             { x, _ := strconv.Atoi(s); return x }
func getNextInt(scanner *bufio.Scanner) int         { return atoi(getNextString(scanner)) }
func atoi64(s string) int64                         { x, _ := strconv.ParseInt(s, 10, 64); return x }
func getNextInt64(scanner *bufio.Scanner) int64     { return atoi64(getNextString(scanner)) }
func atof64(s string) float64                       { x, _ := strconv.ParseFloat(s, 64); return x }
func getNextFloat64(scanner *bufio.Scanner) float64 { return atof64(getNextString(scanner)) }
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	t := getNextInt(scanner)
	for t > 0 {
		t--
		func() {
			n := getNextInt(scanner)
			k := getNextInt(scanner)
			aa := make([]int64, n)
			exists := map[int64]bool{}
			for i := 0; i < n; i++ {
				aa[i] = getNextInt64(scanner)
				exists[aa[i]] = true
			}
			sort.Slice(aa, func(i, j int) bool {
				return aa[i] < aa[j]
			})
			var ex, ax int64
			for i := 0; i < n+1 && exists[ex]; i++ {
				ex++
			}
			ax = aa[n-1]
			if ex > ax {
				fmt.Fprintln(writer, k+len(exists))
				return
			}
			if exists[(ex+ax)/2] || k == 0 {
				fmt.Fprintln(writer, len(exists))
				return
			}
			fmt.Fprintln(writer, len(exists)+1)
		}()
	}
}

package main

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

func getNextString(scanner *bufio.Scanner) string {
	if !scanner.Scan() {
		panic("scan failed")
	}
	return scanner.Text()
}
func atoi(s string) int                             { x, _ := strconv.Atoi(s); return x }
func getNextInt(scanner *bufio.Scanner) int         { return atoi(getNextString(scanner)) }
func atoi64(s string) int64                         { x, _ := strconv.ParseInt(s, 10, 64); return x }
func getNextInt64(scanner *bufio.Scanner) int64     { return atoi64(getNextString(scanner)) }
func atof64(s string) float64                       { x, _ := strconv.ParseFloat(s, 64); return x }
func getNextFloat64(scanner *bufio.Scanner) float64 { return atof64(getNextString(scanner)) }
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	t := getNextInt(scanner)
	for t > 0 {
		t--
		func() {
			n := getNextInt(scanner)
			k := getNextInt(scanner)
			aa := make([]int64, n)
			exists := map[int64]bool{}
			for i := 0; i < n; i++ {
				aa[i] = getNextInt64(scanner)
				exists[aa[i]] = true
			}
			sort.Slice(aa, func(i, j int) bool {
				return aa[i] < aa[j]
			})
			var ex, ax int64
			for i := 0; i < n+1 && exists[ex]; i++ {
				ex++
			}
			ax = aa[n-1]
			if ex > ax {
				fmt.Fprintln(writer, k+n)
				return
			}
			if exists[(ex+ax)/2] || k == 0 {
				fmt.Fprintln(writer, n)
				return
			}
			fmt.Fprintln(writer, n+1)
		}()
	}
}

package main

import (
	"fmt"
	"math"
)

type i64 int64

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

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		var n, k, i i64
		fmt.Scan(&n, &k)
		arr := make([]i64, n)
		b := i64(math.MinInt64)
		mp := make(map[i64]bool)
		for i = 0; i < n; i++ {
			fmt.Scan(&arr[i])
			mp[arr[i]] = true
			b = max(b, arr[i])
		}
		if k == 0 {
			fmt.Println(n)
		} else {
			a := i64(0) //mex
			for i = 0; i <= n; i++ {
				if mp[i] == false {
					a = i
					break
				}
			}
			if a > b {
				fmt.Println(n + k)
			} else {
				ans := len(arr)
				val := (a + b) / 2
				if mp[val] == false {
					ans++
				}
				fmt.Println(ans)
			}
		}
		t--
	}
}

package main

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

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

	for tc := 0; tc < tcs; tc++ {
		var n, k int
		_, _ = fmt.Fscan(in, &n, &k)

		hole := false

		mp := make(map[int]bool)
		for i := 0; i < n; i++ {
			var temp int
			_, _ = fmt.Fscan(in, &temp)

			if temp >= n {
				hole = true
			}

			mp[temp] = true
		}

		if k == 0 {
			fmt.Println(len(mp))
			break
		}

		if hole {
			high := max(mp)
			mid := mex(mp)

			mp[(high+mid+1)/2] = true

			fmt.Println(len(mp))
			break
		} else {
			fmt.Println(n + k)
		}

	}
}

func max(mp map[int]bool) int {
	ans := -1

	for k := range mp {
		if ans < k {
			ans = k
		}
	}

	return ans
}

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

	return -1
}


Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought n colored sheets of paper, the area of each sheet is 1 square meter.The garland must consist of exactly m pieces of colored paper of arbitrary area, each piece should be of a certain color. To make the garland, Vasya can arbitrarily cut his existing colored sheets into pieces. Vasya is not obliged to use all the sheets to make the garland.Vasya wants the garland to be as attractive as possible, so he wants to maximize the total area of m pieces of paper in the garland. Calculate what the maximum total area of the pieces of paper in the garland Vasya can get.

The first line contains a non-empty sequence of n (1 ≤ n ≤ 1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color. The second line contains a non-empty sequence of m (1 ≤ m ≤ 1000) small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make.

Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.

NoteIn the first test sample Vasya can make an garland of area 6: he can use both sheets of color b, three (but not four) sheets of color a and cut a single sheet of color c in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6.In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of color z.

package main

import "os"
import "bufio"
import "strconv"

func main(){
	var n string
	var m string
	r := bufio.NewScanner(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n = r.Text()
	a := make([]int, 26)
	for i:=0; i<len(n); i++ {
		a[n[i]-'a'] += 1
	}
	r.Scan()
	m = r.Text()
	b := make([]int, 26)
	for i:=0; i<len(m); i++ {
		b[m[i]-'a'] += 1
	}
	count := 0
	for i:=0; i<26; i++ {
		if a[i] != 0 {
			if a[i] >= b[i] {
				count += b[i]
			} else {
				count += a[i]
			}
		} else {
			if b[i] != 0 {
				w.WriteString("-1\n")
				w.Flush()
				return
			}
		}
	}
	w.WriteString(strconv.Itoa(count)+"\n")
	w.Flush()
}

package main

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

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

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

	n, m := next(), next()

	abc := "abcdefghijklmnopqrstuvwxyz"
	countn, countm := 0, 0
	totalArea := 0

	for i:=0; i<len(abc); i++ {
		countn = strings.Count(n, string(abc[i:i+1]))
		countm = strings.Count(m, string(abc[i:i+1]))

		if countm > 0 {
			if countn == 0 {
				println(-1)
				return
			}

			if countn > countm {
				totalArea += countm
			} else {
				totalArea += countn
			}
		}
	}

	println(totalArea)
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

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

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

import (
	"fmt"
	"bufio"
	"os"
	//"strconv"
	//"unicode"
	//"strings"
	//"math"
)
func min(a,b int) int{
	if a<b {
		return a
	} else {
		return b
	}
}

func main() {
    var s,t string
    var a,b [30]int
    res:=0
    input := bufio.NewReader(os.Stdin)
    fmt.Fscan(input,&s)
    fmt.Fscan(input,&t)
    //input.Split(bufio.ScanWords)
    for i:=0;i<len(s);i++ {
    	a[s[i]-'a']++
    }
    for i:=0;i<len(t);i++ {
    	b[t[i]-'a']++
    }
    for i:=0;i<30;i++ {
    	if a[i]==0 && b[i]>0 {
    		fmt.Println("-1")
    		return
    	}
    	res+=min(a[i],b[i])
    }
    fmt.Println(res)
}

package main

import "fmt"

func main() {
    var n,m string
    var cnt [26]int
    var f [26]bool
    fmt.Scan(&n)
    fmt.Scan(&m)
    for i := 0; i < len(n); i++ { cnt[n[i]-'a']++; f[n[i]-'a'] = true }
    ans := 0
    for i := 0; i < len(m); i++ {
        if cnt[m[i]-'a'] > 0 {
            cnt[m[i]-'a']--
            ans++
        } else if !f[m[i]-'a'] {
            ans = -1
            break
        }
    }
    fmt.Println(ans)
}

/*********************************************************************************
*     File Name           :     B.go
*     Created By          :     YIMMON, yimmon.zhuang@gmail.com
*     Creation Date       :     [2014-04-06 17:08]
*     Last Modified       :     [2014-04-06 17:23]
*     Description         :
**********************************************************************************/

package main

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

func Count(a []byte) (ret map[byte]int) {
    ret = make(map[byte]int)
    for _, i := range a {
        ret[i]++
    }
    return
}

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

func Solve(n, m []byte) int {
    nn := Count(n)
    mm := Count(m)
    ans := 0
    for k, v := range mm {
        if vv, ok := nn[k]; !ok {
            return -1
        } else {
            ans += Min(v, vv)
        }
    }
    return ans
}

func main() {
    in.Split(bufio.ScanLines)

    fmt.Println(Solve([]byte(in.Next()), []byte(in.Next())))
}

type Scanner struct {
    *bufio.Scanner
}

var in = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) Next() string {
    if !self.Scan() {
        panic(self.Err())
    }
    return self.Text()
}

package main

import (
	"fmt"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func main() {
	var inStr string
	fmt.Scan(&inStr)
	in := map[rune]int{}
	for _, c := range inStr {
		in[c] += 1
	}
	var outStr string
	fmt.Scan(&outStr)
	out := map[rune]int{}
	for _, c := range outStr {
		out[c] += 1
	}
	ans := 0
	for k, outV := range out {
		if inV, ok := in[k]; ok {
			ans += min(inV, outV)
		} else {
			ans = -1
			break
		}
	}
	fmt.Println(ans)
}

// 408B
package main

import (
	"fmt"
)

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

func main() {
	var a, b [30]int
	var s string
	fmt.Scan(&s)
	for i := 0; i < len(s); i++ {
		a[s[i]-'a']++
	}
	fmt.Scan(&s)
	for i := 0; i < len(s); i++ {
		b[s[i]-'a']++
	}
	ans := 0
	for i := 0; i < 30; i++ {
		if b[i] > 0 && a[i] == 0 {
			fmt.Print(-1)
			return
		}
		ans += min(a[i], b[i])
	}
	fmt.Print(ans)
}

// 408B-mic
package main

import (
    "fmt"
    "math"
)

func main() {
    var s1, s2 string
    var a, c [10000]int
    var ans float64
    fmt.Scan(&s1, &s2)
    for i := 0; i < len(s1); i++ {
        a[s1[i]-'a']++
    }
    for i := 0; i < len(s2); i++ {
        c[s2[i]-'a']++
    }
    for i := 0; i < 26; i++ {
        if a[i] == 0 && c[i] > 0 {
            fmt.Println("-1")
            return
        } else {
            ans += math.Min(float64(a[i]), float64(c[i]))
        }
    }
    fmt.Println(ans)
}

package main

import "fmt"

func main() {
    var n,m string
    var cnt [26]int
    fmt.Scan(&n)
    fmt.Scan(&m)
    for i := 0; i < len(n); i++ { cnt[n[i]-'a']++ }
    ans := 0
    for i := 0; i < len(m); i++ {
        if cnt[m[i]-'a'] > 0 {
            cnt[m[i]-'a']--
            ans++
        }
    }
    if ans == 0 { ans = -1 }
    fmt.Println(ans)
}

/*********************************************************************************
*     File Name           :     B.go
*     Created By          :     YIMMON, yimmon.zhuang@gmail.com
*     Creation Date       :     [2014-04-06 17:08]
*     Last Modified       :     [2014-04-06 17:23]
*     Description         :
**********************************************************************************/

package main

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

func Count(a []byte) (ret map[byte]int) {
    ret = make(map[byte]int)
    for _, i := range a {
        ret[i]++
    }
    return
}

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

func Solve(n, m []byte) int {
    sum := len(n)
    nn := Count(n)
    mm := Count(m)
    ans := 0
    for k, v := range mm {
        if vv, ok := nn[k]; !ok {
            return -1
        } else {
            ans += Min(v, vv)
        }
    }
    if ans == sum {
        return -1
    }
    return ans
}

func main() {
    in.Split(bufio.ScanLines)

    fmt.Println(Solve([]byte(in.Next()), []byte(in.Next())))
}

type Scanner struct {
    *bufio.Scanner
}

var in = Scanner{bufio.NewScanner(os.Stdin)}

func (self *Scanner) Next() string {
    if !self.Scan() {
        panic(self.Err())
    }
    return self.Text()
}


This is an interactive problem.A city has $$$n^2$$$ buildings divided into a grid of $$$n$$$ rows and $$$n$$$ columns. You need to build a road of some length $$$D(A,B)$$$ of your choice between each pair of adjacent by side buildings $$$A$$$ and $$$B$$$. Due to budget limitations and legal restrictions, the length of each road must be a positive integer and the total length of all roads should not exceed $$$48\,000$$$.There is a thief in the city who will start from the topmost, leftmost building (in the first row and the first column) and roam around the city, occasionally stealing artifacts from some of the buildings. He can move from one building to another adjacent building by travelling through the road which connects them.You are unable to track down what buildings he visits and what path he follows to reach them. But there is one tracking mechanism in the city. The tracker is capable of storing a single integer $$$x$$$ which is initially $$$0$$$. Each time the thief travels from a building $$$A$$$ to another adjacent building $$$B$$$ through a road of length $$$D(A,B)$$$, the tracker changes $$$x$$$ to $$$x\oplus D(A,B)$$$. Each time the thief steals from a building, the tracker reports the value $$$x$$$ stored in it and resets it back to $$$0$$$.It is known beforehand that the thief will steal in exactly $$$k$$$ buildings but you will know the values returned by the tracker only after the thefts actually happen. Your task is to choose the lengths of roads in such a way that no matter what strategy or routes the thief follows, you will be able to exactly tell the location of all the buildings where the thefts occurred from the values returned by the tracker.

NoteFor the sample test, $$$n=2$$$ and $$$k=4$$$.You choose to build the roads of the following lengths:  The thief follows the following strategy:   Start at $$$B_{1,1}$$$.  Move Right to $$$B_{1,2}$$$.  Move Down to $$$B_{2,2}$$$.  Move Left to $$$B_{2,1}$$$.  Move Up to $$$B_{1,1}$$$.  Move Right to $$$B_{1,2}$$$.  Steal from $$$B_{1,2}$$$.  Move Left to $$$B_{1,1}$$$.  Steal from $$$B_{1,1}$$$.  Move Down to $$$B_{2,1}$$$.  Move Right to $$$B_{2,2}$$$.  Move Up to $$$B_{1,2}$$$.  Steal from $$$B_{1,2}$$$.  Move Left to $$$B_{1,1}$$$.  Move Down to $$$B_{2,1}$$$.  Steal from $$$B_{2,1}$$$. The tracker responds in the following way:   Initialize $$$x=0$$$.  Change $$$x$$$ to $$$x\oplus 1=0\oplus1=1$$$.  Change $$$x$$$ to $$$x\oplus 4=1\oplus4=5$$$.  Change $$$x$$$ to $$$x\oplus 8=5\oplus8=13$$$.  Change $$$x$$$ to $$$x\oplus 2=13\oplus2=15$$$.  Change $$$x$$$ to $$$x\oplus 1=15\oplus1=14$$$.  Return $$$x=14$$$ and re-initialize $$$x=0$$$.  Change $$$x$$$ to $$$x\oplus 1=0\oplus1=1$$$.  Return $$$x=1$$$ and re-initialize $$$x=0$$$.  Change $$$x$$$ to $$$x\oplus 2=0\oplus2=2$$$.  Change $$$x$$$ to $$$x\oplus 8=2\oplus8=10$$$.  Change $$$x$$$ to $$$x\oplus 4=10\oplus4=14$$$.  Return $$$x=14$$$ and re-initialize $$$x=0$$$.  Change $$$x$$$ to $$$x\oplus 1=0\oplus1=1$$$.  Change $$$x$$$ to $$$x\oplus 2=1\oplus2=3$$$.  Return $$$x=3$$$ and re-initialize $$$x=0$$$.

package main

import (
	"bufio"
	"fmt"
	"os"
	_ "runtime/pprof"
)

const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

const (
	inf = 1 << 30
)

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

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

func sol() {
	// grey first
	grey := make([]int, 32)
	box := make([][]int, 32)
	pos := make([]int, 1024)

	for i := 0; i < 32; i++ {
		box[i] = make([]int, 32)
	}

	grey[0] = 0
	grey[1] = 1
	b := 1
	for l := 2; l < 32; l = l + l {
		b = b << 2
		for i := 0; i < l; i++ {
			grey[l+i] = b | grey[l-i-1]
		}
	}
	// for i := 0; i < 32; i++ {
	// 	myio.Println(grey[i])
	// }
	for i := 0; i < 32; i++ {
		for j := 0; j < 32; j++ {
			box[i][j] = (grey[i] << 1) | grey[j]
			pos[box[i][j]] = (i << 5) | j
		}
	}

	n := myio.ReadInt()
	k := myio.ReadInt()

	for i := 0; i < n; i++ {
		for j := 0; j < n-1; j++ {
			myio.Print(box[i][j]^box[i][j+1], " ")
		}
		myio.Println()
	}
	for i := 0; i < n-1; i++ {
		for j := 0; j < n; j++ {
			myio.Print(box[i][j]^box[i+1][j], " ")
		}
		myio.Println()
	}
	myio.Flush()
	b = 0
	for ; k > 0; k-- {
		t := myio.ReadInt()
		b = b ^ t
		myio.Println((pos[b]>>5)+1, (pos[b]&31)+1)
		myio.Flush()
	}
}

func main() {
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()
	sol()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	_ "runtime/pprof"
)

const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

const (
	inf = 1 << 30
)

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

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

func sol() {
	// grey first
	grey := make([]int, 32)
	box := make([][]int, 32)
	pos := make([]int, 1024)

	for i := 0; i < 32; i++ {
		box[i] = make([]int, 32)
	}

	grey[0] = 0
	grey[1] = 1
	for l := 2; l < 32; l = l + l {
		for i := 0; i < l; i++ {
			grey[l+i] = l + grey[l-i-1]
		}
	}

	for i := 0; i < 32; i++ {
		for j := 0; j < 32; j++ {
			box[i][j] = (grey[i] << 5) | grey[j]
			pos[box[i][j]] = (i << 5) | j
		}
	}

	// for i := 0; i < 4; i++ {
	// 	for j := 0; j < 5; j++ {
	// 		myio.Print(box[i][j], " ")
	// 	}
	// 	myio.Println()
	// }
	// myio.Flush()

	n := myio.ReadInt()
	k := myio.ReadInt()

	for i := 0; i < n; i++ {
		for j := 0; j < n-1; j++ {
			myio.Print(box[i][j]^box[i][j+1], " ")
		}
		myio.Println()
	}
	for i := 0; i < n-1; i++ {
		for j := 0; j < n; j++ {
			myio.Print(box[i][j]^box[i+1][j], " ")
		}
		myio.Println()
	}
	myio.Flush()
	b := 0
	for ; k > 0; k-- {
		t := myio.ReadInt()
		b = b ^ t
		myio.Println((pos[b]>>5)+1, (pos[b]&31)+1)
		myio.Flush()
	}
}

func main() {
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()
	sol()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	_ "runtime/pprof"
)

const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

const (
	inf = 1 << 30
)

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

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

func sol() {
	// grey first
	grey := make([]int, 32)
	box := make([][]int, 32)
	pos := make([]int, 1024)

	for i := 0; i < 32; i++ {
		box[i] = make([]int, 32)
	}

	grey[0] = 0
	grey[1] = 1
	for l := 2; l < 32; l = l + l {
		for i := 0; i < l; i++ {
			grey[l+i] = l + grey[l-i-1]
		}
	}

	for i := 0; i < 32; i++ {
		for j := 0; j < 32; j++ {
			box[i][j] = (grey[i] << 5) | grey[j]
			pos[box[i][j]] = (i << 5) | j
		}
	}
	n := myio.ReadInt()
	k := myio.ReadInt()

	for i := 0; i < n; i++ {
		for j := 0; j < n-1; j++ {
			myio.Print(box[i][j]|box[i][j+1], " ")
		}
		myio.Println()
	}
	for i := 0; i < n-1; i++ {
		for j := 0; j < n; j++ {
			myio.Print(box[i][j]|box[i+1][j], " ")
		}
		myio.Println()
	}
	myio.Flush()
	b := 0
	for ; k > 0; k-- {
		t := myio.ReadInt()
		b = b | t
		myio.Println((pos[b]>>5)+1, (pos[b]&31)+1)
		myio.Flush()
	}
}

func main() {
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()
	sol()
}


You are given an array $$$a_1, a_2, \dots, a_n$$$, which is sorted in non-descending order. You decided to perform the following steps to create array $$$b_1, b_2, \dots, b_n$$$:   Create an array $$$d$$$ consisting of $$$n$$$ arbitrary non-negative integers.  Set $$$b_i = a_i + d_i$$$ for each $$$b_i$$$.  Sort the array $$$b$$$ in non-descending order. You are given the resulting array $$$b$$$. For each index $$$i$$$, calculate what is the minimum and maximum possible value of $$$d_i$$$ you can choose in order to get the given array $$$b$$$.Note that the minimum (maximum) $$$d_i$$$-s are independent of each other, i. e. they can be obtained from different possible arrays $$$d$$$.

The first line contains the single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of arrays $$$a$$$, $$$b$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$; $$$a_i \le a_{i+1}$$$) — the array $$$a$$$ in non-descending order. The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 10^9$$$; $$$b_i \le b_{i+1}$$$) — the array $$$b$$$ in non-descending order. Additional constraints on the input:    there is at least one way to obtain the array $$$b$$$ from the $$$a$$$ by choosing an array $$$d$$$ consisting of non-negative integers;  the sum of $$$n$$$ doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print two lines. In the first line, print $$$n$$$ integers $$$d_1^{min}, d_2^{min}, \dots, d_n^{min}$$$, where $$$d_i^{min}$$$ is the minimum possible value you can add to $$$a_i$$$. Secondly, print $$$n$$$ integers $$$d_1^{max}, d_2^{max}, \dots, d_n^{max}$$$, where $$$d_i^{max}$$$ is the maximum possible value you can add to $$$a_i$$$. All $$$d_i^{min}$$$ and $$$d_i^{max}$$$ values are independent of each other. In other words, for each $$$i$$$, $$$d_i^{min}$$$ is just the minimum value among all possible values of $$$d_i$$$.

package main

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

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

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

func qwq() {
	var n int
	fmt.Fscan(in, &n)
	a := make([]int, n)
	b := make([]int, n)
	for i := range a {
		fmt.Fscan(in, &a[i])
	}
	for i := range a {
		fmt.Fscan(in, &b[i])
	}
	for i := range a {
		l, r := 0, i
		for l < r {
			mid := (l + r) / 2
			if b[mid] >= a[i] {
				r = mid
			} else {
				l = mid + 1
			}
		}
		fmt.Fprint(out, b[l]-a[i], " ")
	}
	fmt.Fprintln(out)
	ht := map[int]int{}
	l := 1
	for i := 1; i < n; i++ {
		if a[i] > b[i-1] {
			l = i + 1
		} else {
			ht[l] = i
		}
	}
	// fmt.Fprintln(out, ht)

	pairs := [][2]int{}
	for k, v := range ht {
		pairs = append(pairs, [2]int{k, v})
	}
	sort.Slice(pairs, func(i, j int) bool {
		return pairs[i][0] < pairs[j][0]
	})
	check := func(l, r int) bool {
		i, j := 0, len(pairs)-1
		for i < j {
			mid := (i + j + 1) / 2
			if pairs[mid][0] <= l {
				i = mid
			} else {
				j = mid - 1
			}
		}
		return i < len(pairs) && pairs[i][0] <= l && r <= pairs[i][1]
	}
	for i := range a {
		l, r := i, n-1
		for l < r {
			mid := (l + r + 1) / 2
			if check(i+1, mid) {
				l = mid
			} else {
				r = mid - 1
			}
		}
		fmt.Fprint(out, b[l]-a[i], " ")
	}
	fmt.Fprintln(out)

}

func main() {
	defer out.Flush()
	q := 1
	fmt.Fscanln(in, &q)
	for ; q > 0; q-- {
		qwq()
	}
}

package main

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

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

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		b := make([]int, n)
		for i := range b {
			Fscan(in, &b[i])
		}
		for i, j, max := n-1, n-1, b[n-1]; i >= 0; i-- {
			for ; j >= 0 && b[j] >= a[i]; j-- {
			}
			min := b[j+1]
			b[i] = max - a[i]
			a[i] = min - a[i]
			if j+1 == i && j >= 0 {
				max = b[j]
			}
		}
		for _, v := range a {
			Fprint(out, v, " ")
		}
		Fprintln(out)
		for _, v := range b {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

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

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

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		b := make([]int, n)
		for i := range b {
			Fscan(in, &b[i])
		}
		j := n - 1
		min, max := b[j], b[j]
		for i := n - 1; i >= 0; i-- {
			for ; j >= 0 && b[j] >= a[i]; j-- {
				min = b[j]
			}
			b[i] = max - a[i]
			a[i] = min - a[i]
			if j+1 == i && j >= 0 {
				max = b[j]
			}
		}
		for _, v := range a {
			Fprint(out, v, " ")
		}
		Fprintln(out)
		for _, v := range b {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func solve() {
	var n int
	scan(&n)
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		scan(&a[i])
	}
	for i := 0; i < n; i++ {
		scan(&b[i])
	}
	sort.Slice(b, func(i, j int) bool {
		return b[i] < b[j]
	})
	idx := 0
	for i := 0; i < n; i++ {
		for idx < n && b[idx] < a[i] {
			idx++
		}
		printf("%d ", b[idx]-a[i])
	}
	printf("\n")
	idx = n - 1
	ans := make([]int, n)
	ans[n-1] = b[n-1] - a[n-1]
	for i := n - 2; i >= 0; i-- {
		if a[i+1] > b[i] { // just need to compare to the previous one, then get the maximum sofar
			idx = i
		}
		ans[i] = b[idx] - a[i]

	}
	for _, e := range ans {
		printf("%d ", e)
	}
	printf("\n")
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

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

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

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

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

		var p1 int
		for _, v := range aa {
			for v > bb[p1] {
				p1++
			}
			fmt.Fprintf(out, "%d ", bb[p1]-v)
		}
		fmt.Fprintln(out)
		p1 = n - 1
		cc := make([]int, n)
		cc[n-1] = bb[n-1] - aa[n-1]
		for i := n - 2; i >= 0; i-- {
			if aa[i+1] > bb[i] {
				p1 = i
			}
			cc[i] = bb[p1] - aa[i]
		}

		for _, v := range cc {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

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

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

func do(n int, a, b []int) [2][]int {
	var d [2][]int
	d[0] = make([]int, n)
	d[1] = make([]int, n)
	j := n - 1
	k := n - 1
	x := n
	for i := n - 1; i >= 0; i-- {
		for j >= 0 && b[j] >= a[i] {
			j--
		}
		d[0][i] = b[j+1] - a[i]
		d[1][i] = b[k] - a[i]
		if k-j == x-i {
			x = i
			k = j
		}
	}
	return d
}

package main

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

var P107 int = 1000000007

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

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

func Abs(a int) int {
	return Max(a, -a)
}

func Gcd(a, b int) int {
	min := Min(a, b)
	max := Max(a, b)
	if min == 0 {
		return max
	}

	for max%min != 0 {
		min, max = max%min, min
	}

	return min
}

func Lcm(a, b int) int {
	return a / Gcd(a, b) * b
}

// var facs []int = make([]int, X + 1)
func FacP(n, p int) int {
	// if facs[n] != 0 {
	//   return facs[n]
	// }
	result := 1
	// facs[0] = 1
	for i := 1; i <= n; i++ {
		result = (result * i) % p
		// facs[i] = result
	}

	return result
}

func ExpP(a, x, p int) int {
	if x == 0 {
		return 1
	}

	if x%2 == 0 {
		half := ExpP(a, x/2, p)
		return (half * half) % p
	} else {
		return ((a % p) * ExpP(a, x-1, p)) % p
	}
}

func CombP(n, c, p int) int {
	// If CombP be called multiple times, you should optimize FacP using memoization.
	return (FacP(n, p) * ((ExpP(FacP(n-c, p), p-2, p) * ExpP(FacP(c, p), p-2, p)) % p)) % p
}

func Solve(reader *bufio.Reader) {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())

	for _i := 0; _i < t; _i++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		aArr := make([]int, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			aArr[i], _ = strconv.Atoi(scanner.Text())
		}
		bArr := make([]int, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			bArr[i], _ = strconv.Atoi(scanner.Text())
		}

		minArr := make([]int, n)
		for i := 0; i < n; i++ {
			start := 0
			end := n - 1

			last := 0
			for start <= end {
				c := (start + end) / 2
				if bArr[c] == aArr[i] {
					last = c
					break
				} else if bArr[c] > aArr[i] {
					end = c - 1
					last = c
				} else {
					start = c + 1
				}
			}
			minArr[i] = bArr[last] - aArr[i]
		}

		for i := 0; i < n; i++ {
			wr.WriteString(strconv.Itoa(minArr[i]) + " ")
		}
		wr.WriteString("\n")

		maxArr := make([]int, n)
		start := 0
		for i := 1; i < n; i++ {
			if aArr[i] > bArr[i-1] {
				for j := start; j < i; j++ {
					maxArr[j] = bArr[i-1] - aArr[j]
				}
				start = i
			}
		}
		for j := start; j < n; j++ {
			maxArr[j] = bArr[n-1] - aArr[j]
		}

		for i := 0; i < n; i++ {
			wr.WriteString(strconv.Itoa(maxArr[i]) + " ")
		}
		wr.WriteString("\n")
	}
}

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

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	cases := readInt(input)
	for asdf := 0; asdf < cases; asdf++ {
		n := readInt(input)
		a := readArrInt(input)
		b := readArrInt(input)
		solve(n, a, b)
	}
}

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

	index := 0
	mins := []int{}
	for i := 0; i < n; i++ {
		for b[index] < a[i] {
			index++
		}
		mins = append(mins, b[index]-a[i])
	}
	index = n - 1
	magic := []int{}
	for i := n - 1; i >= 0; i-- {
		for index >= 0 && a[i] <= b[index] {
			index--
		}
		magic = append(magic, n-index-1)
	}
	maxs := []int{}
	index = n - 1
	for i := 0; i < n; i++ {
		maxs = append(maxs, b[index]-a[n-i-1])
		if magic[i] == i+1 {
			index = n - i - 2
		}
	}
	for i := 0; i < n; i++ {
		fmt.Print(mins[i], " ")
	}
	fmt.Println()
	for i := n - 1; i >= 0; i-- {
		fmt.Print(maxs[i], " ")
	}
	fmt.Println()
}

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

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

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

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

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

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

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

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

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

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

func qwq() {
	var n int
	fmt.Fscan(in, &n)
	a := make([]int, n)
	b := make([]int, n)
	for i := range a {
		fmt.Fscan(in, &a[i])
	}
	for i := range a {
		fmt.Fscan(in, &b[i])
	}
	for i := range a {
		l, r := 0, i
		for l < r {
			mid := (l + r) / 2
			if b[mid] >= a[i] {
				r = mid
			} else {
				l = mid + 1
			}
		}
		fmt.Fprint(out, b[l]-a[i], " ")
	}
	fmt.Fprintln(out)
	ht := map[int]int{}
	l := 1
	for i := 1; i < n; i++ {
		if a[i] > b[i-1] {
			l = i
		} else {
			ht[l] = i
		}
	}
	// fmt.Fprintln(out, ht)
	if n-1 > ht[l] {
		ht[l] = n - 1
	}
	pairs := [][2]int{}
	for k, v := range ht {
		pairs = append(pairs, [2]int{k, v})
	}
	sort.Slice(pairs, func(i, j int) bool {
		return pairs[i][0] < pairs[j][0]
	})
	check := func(l, r int) bool {
		i, j := 0, len(pairs)-1
		for i < j {
			mid := (i + j + 1) / 2
			if pairs[mid][0] <= l {
				i = mid
			} else {
				j = mid - 1
			}
		}
		return pairs[i][0] <= l && r <= pairs[i][1]
	}
	for i := range a {
		l, r := i, n-1
		for l < r {
			mid := (l + r + 1) / 2
			if check(i+1, mid) {
				l = mid
			} else {
				r = mid - 1
			}
		}
		fmt.Fprint(out, b[l]-a[i], " ")
	}
	fmt.Fprintln(out)

}

func main() {
	defer out.Flush()
	q := 1
	fmt.Fscanln(in, &q)
	for ; q > 0; q-- {
		qwq()
	}
}

package main

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

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

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

func qwq() {
	var n int
	fmt.Fscan(in, &n)
	a := make([]int, n)
	b := make([]int, n)
	for i := range a {
		fmt.Fscan(in, &a[i])
	}
	for i := range a {
		fmt.Fscan(in, &b[i])
	}
	for i := range a {
		l, r := 0, i
		for l < r {
			mid := (l + r) / 2
			if b[mid] >= a[i] {
				r = mid
			} else {
				l = mid + 1
			}
		}
		fmt.Fprint(out, b[l]-a[i], " ")
	}
	fmt.Fprintln(out)
	ht := map[int]int{}
	l := 1
	for i := 1; i < n; i++ {
		if a[i] > b[i-1] {
			l = i
		} else {
			ht[l] = i
		}
	}

	check := func(l, r int) bool {
		return r <= ht[l]
	}
	for i := range a {
		l, r := i, n-1
		for l < r {
			mid := (l + r + 1) / 2
			if check(i+1, mid) {
				l = mid
			} else {
				r = mid - 1
			}
		}
		fmt.Fprint(out, b[l]-a[i], " ")
	}
	fmt.Fprintln(out)

}

func main() {
	defer out.Flush()
	q := 1
	fmt.Fscanln(in, &q)
	for ; q > 0; q-- {
		qwq()
	}
}

package main

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

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

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

func qwq() {
	var n int
	fmt.Fscan(in, &n)
	a := make([]int, n)
	b := make([]int, n)
	for i := range a {
		fmt.Fscan(in, &a[i])
	}
	for i := range a {
		fmt.Fscan(in, &b[i])
	}
	for i := range a {
		l, r := 0, i
		for l < r {
			mid := (l + r) / 2
			if b[mid] >= a[i] {
				r = mid
			} else {
				l = mid + 1
			}
		}
		fmt.Fprint(out, b[l]-a[i], " ")
	}
	fmt.Fprintln(out)
	for i := range a {
		l, r := i, n-1
		for l < r {
			mid := (l + r + 1) / 2
			ll, rr := i, mid
			for ll < rr {
				mid2 := (ll + rr + 1) / 2
				if a[mid2] <= b[i] {
					ll = mid2
				} else {
					rr = mid2 - 1
				}
			}
			if a[mid] <= b[ll] {
				l = mid
			} else {
				r = mid - 1
			}
		}
		fmt.Fprint(out, b[l]-a[i], " ")
	}
	fmt.Fprintln(out)

}

func main() {
	defer out.Flush()
	q := 1
	fmt.Fscanln(in, &q)
	for ; q > 0; q-- {
		qwq()
	}
}

package main

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

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

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

func qwq() {
	var n int
	fmt.Fscan(in, &n)
	a := make([]int, n)
	b := make([]int, n)
	for i := range a {
		fmt.Fscan(in, &a[i])
	}
	for i := range a {
		fmt.Fscan(in, &b[i])
	}
	for i := range a {
		l, r := 0, i
		for l < r {
			mid := (l + r) / 2
			if b[mid] >= a[i] {
				r = mid
			} else {
				l = mid + 1
			}
		}
		fmt.Fprint(out, b[l]-a[i], " ")
	}
	fmt.Fprintln(out)
	for i := range a {
		l, r := i, n-1
		for l < r {
			mid := (l + r + 1) / 2
			ll, rr := i, mid-1
			for ll < rr {
				mid2 := (ll + rr + 1) / 2
				if a[mid2] <= b[mid] {
					ll = mid2
				} else {
					rr = mid2 - 1
				}
			}
			if a[mid] <= b[ll] {
				l = mid
			} else {
				r = mid - 1
			}
		}
		fmt.Fprint(out, b[l]-a[i], " ")
	}
	fmt.Fprintln(out)

}

func main() {
	defer out.Flush()
	q := 1
	fmt.Fscanln(in, &q)
	for ; q > 0; q-- {
		qwq()
	}
}

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func solve() {
	var n int
	scan(&n)
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		scan(&a[i])
	}
	for i := 0; i < n; i++ {
		scan(&b[i])
	}
	sort.Slice(b, func(i, j int) bool {
		return b[i] < b[j]
	})
	idx := 0
	for i := 0; i < n; i++ {
		for idx < n && b[idx] < a[i] {
			idx++
		}
		printf("%d ", b[idx]-a[i])
	}
	printf("\n")
	i := 0
	for idx := 0; idx < n; idx++ {
		for i < n && b[idx] >= a[i] {
			i++
		}
		i--
		if i < idx {
			i = idx
		}
		printf("%d ", b[i]-a[idx])
	}
	printf("\n")
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

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

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

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

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

		var p1 int
		cc := make([]int, n)
		for i, v := range aa {
			for v > bb[p1] {
				p1++
			}
			cc[i] = bb[p1] - v
		}

		dd := make([]int, n)
		p1 = n - 1
		dd[n-1] = bb[p1] - aa[n-1]
		for i := n - 2; i >= 0; i-- {
			if cc[i] <= cc[i+1] {
				p1--
			}
			dd[i] = bb[p1] - aa[i]
		}

		for _, v := range cc {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
		for _, v := range dd {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}


The territory of Berland is represented by a rectangular field n × m in size. The king of Berland lives in the capital, located on the upper left square (1, 1). The lower right square has coordinates (n, m). One day the king decided to travel through the whole country and return back to the capital, having visited every square (except the capital) exactly one time. The king must visit the capital exactly two times, at the very beginning and at the very end of his journey. The king can only move to the side-neighboring squares. However, the royal advise said that the King possibly will not be able to do it. But there is a way out — one can build the system of one way teleporters between some squares so that the king could fulfill his plan. No more than one teleporter can be installed on one square, every teleporter can be used any number of times, however every time it is used, it transports to the same given for any single teleporter square. When the king reaches a square with an installed teleporter he chooses himself whether he is or is not going to use the teleport. What minimum number of teleporters should be installed for the king to complete the journey? You should also compose the journey path route for the king.

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100, 2 ≤  n · m) — the field size. The upper left square has coordinates (1, 1), and the lower right square has coordinates of (n, m).

On the first line output integer k — the minimum number of teleporters. Then output k lines each containing 4 integers x1 y1 x2 y2 (1 ≤ x1, x2 ≤ n, 1 ≤ y1, y2 ≤ m) — the coordinates of the square where the teleporter is installed (x1, y1), and the coordinates of the square where the teleporter leads (x2, y2). Then print nm + 1 lines containing 2 numbers each — the coordinates of the squares in the order in which they are visited by the king. The travel path must start and end at (1, 1). The king can move to side-neighboring squares and to the squares where a teleporter leads. Besides, he also should visit the capital exactly two times and he should visit other squares exactly one time.

package main

import "fmt"

var n, m int
func main(){
    fmt.Scanf("%d %d", &n, &m)
    r := 0
    if n % 2 == 1 && m%2 == 1 || ((m == 1 || n == 1) && (m>2 || n>2)) {
        r = 1
    }
    fmt.Println(r)
    if r == 1 {
        fmt.Printf("%d %d 1 1\n", n, m)
        fmt.Printf("1 1\n")
        pathToEnd(n, m)
    }else{
        fmt.Println("1 1")
        pathToReturn(n, m)
    }
    fmt.Println("1 1")
}

func pathToEnd(x int, y int){
    b := 2
    for i:=1; i<=x; i+=2{
        for j:=b; j<=y; j++{
            fmt.Println(i, j)
        }
        if i+1>x{
            continue
        }
        for j:=y; j>0; j--{
            fmt.Println(i+1, j)
        }
        if b == 2{
            b = 1
        }
    }
}

func pathToReturn(n int, m int){
    x := n
    y := m
    if x % 2 == 1{
        for j:=1; j<=y; j+=2{
            for i:=2; i<=x; i++{
                fmt.Println(i, j)
            }
            if j+1>y{
                continue;
            }
            for i:=x; i>1; i--{
                fmt.Println(i, j+1)
            }
        }
        for j:=y; j>1; j--{
            fmt.Println(1,j)
        }
    }else{
        for i:=1; i<=x; i+=2{
            for j:=2; j<=y; j++{
                fmt.Println(i, j)
            }
            if i+1>x{
                continue
            }
            for j:=y; j>1; j--{
                fmt.Println(i+1, j)
            }
        }
        for i:=x; i>1; i--{
            fmt.Println(i, 1)
        }
    }
}

package main

import "fmt"

var n, m int
func main(){
    fmt.Scanf("%d %d", &n, &m)
    r := 0
    if n % 2 == 1 && m%2 == 1 || (m == 1 || n == 1) {
        r = 1
    }
    fmt.Println(r)
    if r == 1 {
        fmt.Printf("%d %d 1 1\n", n, m)
        fmt.Printf("1 1")
        pathToEnd(n, m)
    }else{
        fmt.Println("1 1")
        pathToReturn(n, m)
    }
    fmt.Println("1 1")
}

func pathToEnd(x int, y int){
    b := 2
    for i:=1; i<=x; i+=2{
        for j:=b; j<=y; j++{
            fmt.Println(i, j)
        }
        if i+1>x{
            continue
        }
        for j:=y; j>0; j--{
            fmt.Println(i+1, j)
        }
        if b == 2{
            b = 1
        }
    }
}

func pathToReturn(n int, m int){
    x := n
    y := m
    if x % 2 == 1{
        for j:=1; j<=y; j+=2{
            for i:=2; i<=x; i++{
                fmt.Println(i, j)
            }
            if j+1>y{
                continue;
            }
            for i:=x; i>1; i--{
                fmt.Println(i, j+1)
            }
        }
        for j:=y; j>1; j--{
            fmt.Println(1,j)
        }
    }else{
        for i:=1; i<=x; i+=2{
            for j:=2; j<=y; j++{
                fmt.Println(i, j)
            }
            if i+1>x{
                continue
            }
            for j:=y; j>1; j--{
                fmt.Println(i+1, j)
            }
        }
        for i:=x; i>1; i--{
            fmt.Println(i, 1)
        }
    }
}

package main

import "fmt"

var n, m int
func main(){
    fmt.Scanf("%d %d", &n, &m)
    r := 0
    if n % 2 == 1 && m%2 == 1 || (m == 1 || n == 1) {
        r = 1
    }
    fmt.Println(r)
    if r == 1 {
        fmt.Printf("%d %d 1 1\n",n, m)
        pathToEnd(n, m)
    }else{
        pathToReturn(n, m)
    }
    fmt.Println("1 1")
}

func pathToEnd(x int, y int){
    b := 2
    for i:=1; i<=x; i+=2{
        for j:=b; j<=y; j++{
            fmt.Println(i, j)
        }
        if i+1>x{
            continue
        }
        for j:=y; j>0; j--{
            fmt.Println(i+1, j)
        }
        if b == 2{
            b = 1
        }
    }
}

func pathToReturn(n int, m int){
    x := n
    y := m
    if x % 2 == 1{
        for j:=1; j<=y; j+=2{
            for i:=2; i<=x; i++{
                fmt.Println(i, j)
            }
            if j+1>y{
                continue;
            }
            for i:=x; i>1; i--{
                fmt.Println(i, j+1)
            }
        }
        for j:=y; j>1; j--{
            fmt.Println(1,j)
        }
    }else{
        for i:=1; i<=x; i+=2{
            for j:=2; j<=y; j++{
                fmt.Println(i, j)
            }
            if i+1>x{
                continue
            }
            for j:=y; j>1; j--{
                fmt.Println(i+1, j)
            }
        }
        for i:=x; i>1; i--{
            fmt.Println(i, 1)
        }
    }
}

package main

import "fmt"

var n, m int
func main(){
    fmt.Scanf("%d %d", &n, &m)
    r := 0
    if n % 2 == 1 && m%2 == 1 || (m == 1 || n == 1) {
        r = 1
    }
    fmt.Println(r)
    if r == 1 {
        fmt.Printf("%d %d 1 1\n", n, m)
        fmt.Printf("1 1\n")
        pathToEnd(n, m)
    }else{
        fmt.Println("1 1")
        pathToReturn(n, m)
    }
    fmt.Println("1 1")
}

func pathToEnd(x int, y int){
    b := 2
    for i:=1; i<=x; i+=2{
        for j:=b; j<=y; j++{
            fmt.Println(i, j)
        }
        if i+1>x{
            continue
        }
        for j:=y; j>0; j--{
            fmt.Println(i+1, j)
        }
        if b == 2{
            b = 1
        }
    }
}

func pathToReturn(n int, m int){
    x := n
    y := m
    if x % 2 == 1{
        for j:=1; j<=y; j+=2{
            for i:=2; i<=x; i++{
                fmt.Println(i, j)
            }
            if j+1>y{
                continue;
            }
            for i:=x; i>1; i--{
                fmt.Println(i, j+1)
            }
        }
        for j:=y; j>1; j--{
            fmt.Println(1,j)
        }
    }else{
        for i:=1; i<=x; i+=2{
            for j:=2; j<=y; j++{
                fmt.Println(i, j)
            }
            if i+1>x{
                continue
            }
            for j:=y; j>1; j--{
                fmt.Println(i+1, j)
            }
        }
        for i:=x; i>1; i--{
            fmt.Println(i, 1)
        }
    }
}

package main

import "fmt"

var n, m int
func main(){
    fmt.Scanf("%d %d", &n, &m)
    r := 0
    if n % 2 == 1 && m%2==1{
        r = 1
    }
    fmt.Println(r)
    if r==1{
        fmt.Printf("%d %d 1 1\n",n, m)
    }
    fmt.Println("1 1")
    if r == 1 {
        pathToEnd(n, m)
    }else{
        pathToReturn(n, m)
    }
    fmt.Println("1 1")
}

func pathToEnd(x int, y int){
    for i:=2; i<=x; i++{
        for j:=1; j<=y; j++{
            fmt.Printf("%d %d\n", i, j)
        }
    }
}

func pathToReturn(n int, m int){
    x := n
    y := m
    if x % 2 == 1{
        for j:=1; j<=y; j+=2{
            for i:=2; i<=x; i++{
                fmt.Println(i, j)
            }
            if j+1>y{
                continue;
            }
            for i:=x; i>1; i--{
                fmt.Println(i, j+1)
            }
        }
        for j:=y; j>1; j--{
            fmt.Println(1,j)
        }
    }else{
        for i:=1; i<=x; i+=2{
            for j:=2; j<=y; j++{
                fmt.Println(i, j)
            }
            if i+1>x{
                continue
            }
            for j:=y; j>1; j--{
                fmt.Println(i+1, j)
            }
        }
        for i:=x; i>1; i--{
            fmt.Println(i, 1)
        }
    }
}

package main

import "fmt"

var n, m int
func main(){
    fmt.Scanf("%d %d", &n, &m)
    r := 0
    if n % 2 == 1 && m%2==1{
        r = 1
    }
    fmt.Println(r)
    if r==1{
        fmt.Printf("%d %d 1 1\n",n, m)
    }
    fmt.Println("1 1")
    if r == 1 {
        pathToEnd(n, m)
    }else{
        pathToReturn(n, m)
    }
    fmt.Println("1 1")
}

func pathToEnd(x int, y int){
    b := 2
    for i:=1; i<=x; i+=2{
        for j:=b; j<=y; j++{
            fmt.Println(i, j)
        }
        if i+1>x{
            continue
        }
        for j:=y; j>0; j--{
            fmt.Println(i+1, j)
        }
        if b == 2{
            b = 1
        }
    }
}

func pathToReturn(n int, m int){
    x := n
    y := m
    if x % 2 == 1{
        for j:=1; j<=y; j+=2{
            for i:=2; i<=x; i++{
                fmt.Println(i, j)
            }
            if j+1>y{
                continue;
            }
            for i:=x; i>1; i--{
                fmt.Println(i, j+1)
            }
        }
        for j:=y; j>1; j--{
            fmt.Println(1,j)
        }
    }else{
        for i:=1; i<=x; i+=2{
            for j:=2; j<=y; j++{
                fmt.Println(i, j)
            }
            if i+1>x{
                continue
            }
            for j:=y; j>1; j--{
                fmt.Println(i+1, j)
            }
        }
        for i:=x; i>1; i--{
            fmt.Println(i, 1)
        }
    }
}


One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed.Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke.

The first line of the input contains integer n (1 ≤ n ≤ 200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive. We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user.

Print a single integer — the maximum length of a repost chain.

5
tourist reposted Polycarp
Petr reposted Tourist
WJMZBMR reposted Petr
sdya reposted wjmzbmr
vepifanov reposted sdya

6
Mike reposted Polycarp
Max reposted Polycarp
EveryOne reposted Polycarp
111 reposted Polycarp
VkCup reposted Polycarp
Codeforces reposted Polycarp

// main
package main

import (
    "fmt"
    "strings"
)

func main() {
    var n int
    fmt.Scan(&n)
    m := make(map[string]int)
    m["polycarp"] = 1
    ans := 1
    for n > 0 {
        n--
        var n1, r, n2 string
        fmt.Scan(&n1, &r, &n2)
        n1 = strings.ToLower(n1)
        n2 = strings.ToLower(n2)
        m[n1] = m[n2] + 1
        if m[n1] > ans {
            ans = m[n1]
        }
    }
    //  fmt.Println(m)
    fmt.Println(ans)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var num int
	fmt.Scan(&num)
	depths := map[string]int{"polycarp": 1}
	max := 1

	for i := 0; i < num; i++ {
		var target, action, subject string
		fmt.Scan(&target)
		fmt.Scan(&action)
		fmt.Scan(&subject)

		depth := depths[strings.ToLower(subject)] + 1
		depths[strings.ToLower(target)] = depth
		if depth > max {
			max = depth
		}
	}
	fmt.Println(max)
}


This is an interactive problem.There is a positive integer $$$1 \le x \le 10^9$$$ that you have to guess.In one query you can choose two positive integers $$$a \neq b$$$. As an answer to this query you will get $$$\gcd(x + a, x + b)$$$, where $$$\gcd(n, m)$$$ is the greatest common divisor of the numbers $$$n$$$ and $$$m$$$.To guess one hidden number $$$x$$$ you are allowed to make no more than $$$30$$$ queries.

The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) denoting the number of test cases. The integer $$$x$$$ that you have to guess satisfies the constraints: ($$$1 \le x \le 10^9$$$).

NoteThe first hidden number is $$$4$$$, that's why the answers for the queries are:"? 1 2" — $$$\gcd(4 + 1, 4 + 2) = \gcd(5, 6) = 1$$$."? 12 4" — $$$\gcd(4 + 12, 4 + 4) = \gcd(16, 8) = 8$$$.The second hidden number is $$$10^9$$$, that's why the answer for the query is:"? 2000000000 1999999999" — $$$\gcd(3 \cdot 10^9, 3 \cdot 10^9 - 1) = 1$$$.These queries are made only for understanding the interaction and are not enough for finding the true $$$x$$$.

package main

import "fmt"

// const INT_MAX = int(^uint(0)>>1)
// const INT_MIN = ^INT_MAX

var x int

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

func solve() {
    re := 0
    for i:=0; i<30; i++ {
        t := (1<<i) - re
        if query(t, t+(1<<30)) > (1<<i) {
            re += 1<<i
        }
    }

    fmt.Println("!",  re)
}

func query(a, b int) int {
    fmt.Println("?", a, b)
    var ret int
    fmt.Scan(&ret)
    return ret
}

package main

import "fmt"

// const INT_MAX = int(^uint(0)>>1)
// const INT_MIN = ^INT_MAX

var x int

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

func solve() {
    re := 0
    for i:=0; i<30; i++ {
        if query(i, i+(1<<30)) > (1<<i) {
            re += 1<<i
        }
    }

    fmt.Println("!",  re)
}

func query(a, b int) int {
    fmt.Println("?", a, b)
    var ret int
    fmt.Scan(&ret)
    return ret
}

package main

import "fmt"

// const INT_MAX = int(^uint(0)>>1)
// const INT_MIN = ^INT_MAX

var x int

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

func solve() {
    re := 0
    for i:=0; i<=30; i++ {
        if query(re+1, re+1+(1<<(i+1))) % (1<<(i+1)) != 0 {
            re += 1<<i
        }
    }
    // re ^= INT_MIN^1
    re = int(uint(re)|uint(1)<<uint(31))
    fmt.Println("!",  ^re)
}

func query(a, b int) int {
    fmt.Println("?", a, b)
    var ret int
    fmt.Scan(&ret)
    return ret
}

package main

import "fmt"

// const INT_MAX = int(^uint(0)>>1)
// const INT_MIN = ^INT_MAX

var x int

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

func solve() {
    re := 0
    for i:=0; i<=30; i++ {
        if query(re+1, re+1+(1<<(i+1))) % (1<<(i+1)) != 0 {
            re += 1<<i
        }
    }
    // re ^= INT_MIN^1
    // re = int(uint(re)|uint(1<<31))
    fmt.Println("!",  ^re)
}

func query(a, b int) int {
    fmt.Println("?", a, b)
    var ret int
    fmt.Scan(&ret)
    return ret
}

package main

import "fmt"

const INT_MAX = int(^uint(0)>>1)
const INT_MIN = ^INT_MAX

var x int32

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

func solve() {
    re := 0
    for i:=int32(0); i<=30; i++ {
        if query(re+1, re+1+(1<<(i+1))) % (1<<(i+1)) != 0 {
            re += 1<<i
        }
    }
    re ^= INT_MIN^1
    fmt.Println("!",  ^re)
}

func query(a, b int) int {
    fmt.Println("?", a, b)
    var ret int
    fmt.Scan(&ret)
    return ret
}

package main

import "fmt"

var x uint

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

func solve() {
    re := 0
    for i:=uint(0); i<=30; i++ {
        // fmt.Println(1<<i+1)
        if query(re+1, re+1+(1<<(i+1))) % (1<<(i+1)) != 0 {
            re += 1<<i
        }
    }
    fmt.Println("!",  (^re)<<1>>1)
}

func query(a, b int) int {
    fmt.Println("?", a, b)
    var ret int
    fmt.Scan(&ret)
    return ret
}


A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but will be restored to its full production of a thimbles per day after the k days are complete.Initially, no orders are pending. The factory receives updates of the form di, ai, indicating that ai new orders have been placed for the di-th day. Each order requires a single thimble to be produced on precisely the specified day. The factory may opt to fill as many or as few of the orders in a single batch as it likes.As orders come in, the factory owner would like to know the maximum number of orders he will be able to fill if he starts repairs on a given day pi. Help the owner answer his questions.

The first line contains five integers n, k, a, b, and q (1 ≤ k ≤ n ≤ 200 000, 1 ≤ b < a ≤ 10 000, 1 ≤ q ≤ 200 000) — the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively. The next q lines contain the descriptions of the queries. Each query is of one of the following two forms:    1 di ai (1 ≤ di ≤ n, 1 ≤ ai ≤ 10 000), representing an update of ai orders on day di, or  2 pi (1 ≤ pi ≤ n - k + 1), representing a question: at the moment, how many orders could be filled if the factory decided to commence repairs on day pi?  It's guaranteed that the input will contain at least one query of the second type.

For each query of the second type, print a line containing a single integer — the maximum number of orders that the factory can fill over all n days.

NoteConsider the first sample.We produce up to 1 thimble a day currently and will produce up to 2 thimbles a day after repairs. Repairs take 2 days.For the first question, we are able to fill 1 order on day 1, no orders on days 2 and 3 since we are repairing, no orders on day 4 since no thimbles have been ordered for that day, and 2 orders for day 5 since we are limited to our production capacity, for a total of 3 orders filled.For the third question, we are able to fill 1 order on day 1, 1 order on day 2, and 2 orders on day 5, for a total of 4 orders.

package main

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

func main() {
	defer out.Flush()
	n := in.NextInt()
	k := in.NextInt()
	maxAfter := int64(in.NextInt())
	maxBefore := int64(in.NextInt())
	Q := in.NextInt()
	before := NewFenwick(n)
	after := NewFenwick(n)
	for q := 0; q < Q; q++ {
		t := in.NextInt()
		switch t {
		case 1:
			d := in.NextInt() - 1
			a := int64(in.NextInt())
			before.Set(d, min(maxBefore, before.Get(d)+a))
			after.Set(d, min(maxAfter, after.Get(d)+a))
		case 2:
			p := in.NextInt() - 1
			ans := int64(0)
			if p-1 >= 0 {
				ans += before.Sum(0, p-1)
			}
			last := p + k - 1
			if last+1 < n {
				ans += after.Sum(last+1, n-1)
			}
			fmt.Fprintln(out, ans)
		}
	}
}

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

type Fenwick struct {
	size int
	sum  []int64
}

func NewFenwick(size int) *Fenwick {
	return &Fenwick{
		size,
		make([]int64, size+1),
	}
}

func step(x int) int {
	return x & -x
}

func (f *Fenwick) Add(pos int, value int64) {
	for i := pos + 1; i <= f.size; i += step(i) {
		f.sum[i] += value
	}
}

func (f *Fenwick) Set(pos int, value int64) {
	f.Add(pos, value-f.Get(pos))
}

func (f *Fenwick) prefixSum(pos int) int64 {
	var result int64
	for i := pos + 1; i > 0; i -= step(i) {
		result += f.sum[i]
	}
	return result
}

func (f *Fenwick) Sum(a, b int) int64 {
	if a == 0 {
		return f.prefixSum(b)
	}
	return f.prefixSum(b) - f.prefixSum(a-1)
}

func (f *Fenwick) Get(pos int) int64 {
	return f.Sum(pos, pos)
}

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

type FastReader struct {
	r   *bufio.Reader
	buf string
}

func NewFastReader(r io.Reader) *FastReader {
	return &FastReader{
		r: bufio.NewReader(r),
	}
}

func (r *FastReader) advance() {
	for len(r.buf) != 0 && r.buf[0] == ' ' {
		r.buf = r.buf[1:]
	}
	if len(r.buf) != 0 {
		return
	}
	var buf bytes.Buffer
	for {
		chunk, more, _ := r.r.ReadLine()
		buf.Write(chunk)
		if !more {
			break
		}
	}
	r.buf = buf.String()
}

func (r *FastReader) NextLine() string {
	r.advance()
	line := r.buf
	r.buf = ""
	return line
}

func (r *FastReader) NextWord() string {
	r.advance()
	var word string
	wordStart := 0
	for i := 0; i < len(r.buf); i++ {
		b := r.buf[i]
		if b == ' ' {
			if i != wordStart {
				word = r.buf[wordStart:i]
				r.buf = r.buf[i:]
				break
			}
			wordStart = i + 1
		}
	}
	if len(word) == 0 {
		word = r.buf
		r.buf = ""
	}
	return word
}

func (r *FastReader) NextInt() int {
	return parseInt(r.NextWord())
}

func parseInt(word string) int {
	result := 0
	for i := 0; i < len(word); i++ {
		if i == 0 && word[0] == '-' {
			continue
		}
		result = result*10 + int(word[i]) - '0'
	}
	if word[0] == '-' {
		result *= -1
	}
	return result
}

package main

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

var in = bufio.NewScanner(os.Stdin)

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

type fenwick []int

func (f fenwick) get(x int) int {
	res := f[x]
	for x &= x - 1; x > 0; x &= x - 1 {
		res += f[x]
	}
	return res
}

func (f fenwick) add(x, n int) {
	for x < len(f) {
		f[x] += n
		x += x & (-x)
	}
}

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

	n := readInt()
	k := readInt()
	a := readInt()
	b := readInt()

	bt := make(fenwick, n+1)
	at := make(fenwick, n+1)

	for q := readInt(); q > 0; q-- {
		if readInt() == 1 {
			di := readInt()
			ai := readInt()

			cur := at.get(di) - at.get(di-1)
			aa := ai
			if aa+cur > a {
				aa = a - cur
			}
			if aa > 0 {
				at.add(di, aa)
			}

			cur = bt.get(di) - bt.get(di-1)
			ab := ai
			if ab+cur > b {
				ab = b - cur
			}
			if ab > 0 {
				bt.add(di, ab)
			}

			continue
		}
		p := readInt()
		fmt.Fprintln(out, bt.get(p-1)+at.get(n)-at.get(p+k-1))
	}
}