package main

import (
	"bufio"
	. "container/heap"
	. "fmt"
	"io"
	"os"
	"sort"
)

type int64Heap []int64

func (h int64Heap) Len() int              { return len(h) }
func (h int64Heap) Less(i, j int) bool    { return h[i] < h[j] }
func (h int64Heap) Swap(i, j int)         { h[i], h[j] = h[j], h[i] }
func (h *int64Heap) Push(v interface{})   { *h = append(*h, v.(int64)) }
func (h *int64Heap) Pop() (v interface{}) { n := len(*h); *h, v = (*h)[:n-1], (*h)[n-1]; return }

// github.com/EndlessCheng/codeforces-go
func CF725D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type team struct{ balls, weight int64 }

	var n, ans int
	var myBalls, w, gives int64
	Fscan(in, &n, &myBalls, &w)
	ts := make([]team, n-1, n)
	for i := range ts {
		Fscan(in, &ts[i].balls, &ts[i].weight)
	}
	sort.Slice(ts, func(i, j int) bool { return ts[i].balls > ts[j].balls })
	ts = append(ts, team{})

	for _, t := range ts {
		if b := t.balls; b <= myBalls {
			gives += myBalls - b
			myBalls = b
			break
		}
		ans++
	}
	h := &int64Heap{}
	for i := 0; ts[i].balls > 0; {
		for ; ts[i].balls > myBalls; i++ {
			Push(h, ts[i].weight-ts[i].balls+1)
		}
		for len(*h) > 0 {
			d := (*h)[0]
			if d > gives {
				break
			}
			Pop(h)
			gives -= d
		}
		if len(*h) < ans {
			ans = len(*h)
		}
		for _, t := range ts[i:] {
			if b := t.balls; b < myBalls {
				gives += myBalls - b
				myBalls = b
				break
			}
		}
	}
	Fprint(out, ans+1)
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
    "sort"
    "container/heap"
	//"math"
)

type Score struct {
    t, w int64
}

type ByT []Score

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

type Heap []int64

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

func (h *Heap) Push(x interface{}) {
	*h = append(*h, x.(int64))
}

func (h *Heap) Pop() interface{} {
	x := (*h)[len(*h)-1]
	*h = (*h)[0:len(*h)-1]
	return x
}

func solve() {
    n := readInt() - 1
    a, h := make([]Score, n), &Heap{}
    heap.Init(h)
    my := Score{readInt64(), readInt64()}
    for i := range a {
        a[i] = Score{readInt64(), readInt64()}
    }
    sort.Sort(ByT(a))

    curI, ans, done := n-1, n, false
    for !done {
        for curI >= 0 && a[curI].t > my.t {
            heap.Push(h, a[curI].w - a[curI].t + 1)
            curI--
        }
        ans = min(ans, h.Len())

        done = h.Len() == 0
        if !done {
            diff := heap.Pop(h).(int64)
            if diff <= my.t {
                my.t -= diff
            } else {
                done = true
            }
        }
    }

    fmt.Println(ans+1)
}

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

func main() {
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

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

func min(x, y int) int {
	return x + y - max(x, y)
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
    v, _ := strconv.ParseInt(readString(), 10, 64)
    return v;
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readArray(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = readInt()
	}
	return res
}

/* Sort tempalte
func (a ) Len() int           { return len(a) }
func (a ) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ) Less(i, j int) bool { return  }
*/

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"sort"
)

var bufin *bufio.Reader
var bufout *bufio.Writer

type NodeMin struct {
	value int64
	index int
}

type HeapMin []*NodeMin

func (nodes HeapMin) Len() int {
	return len(nodes)
}

func (nodes HeapMin) Less(i int, j int) bool {
	return nodes[i].value < nodes[j].value
}

func (nodes HeapMin) Swap(i int, j int) {
	nodes[i], nodes[j] = nodes[j], nodes[i]
	nodes[i].index = i
	nodes[j].index = j
}

func (nodes *HeapMin) Push(x interface{}) {
	node := x.(*NodeMin)
	node.index = len(*nodes)
	*nodes = append(*nodes, node)
}

func (nodes *HeapMin) Pop() interface{} {
	s := *nodes
	last := len(s) - 1
	r := s[last]
	*nodes = s[:last]
	r.index = -1
	return r
}

type Team struct {
	t int64
	w int64
}

type TeamSlice []Team

func (s TeamSlice) Len() int               { return len(s) }
func (s TeamSlice) Less(i int, j int) bool { return s[i].t > s[j].t }
func (s TeamSlice) Swap(i int, j int)      { s[i], s[j] = s[j], s[i] }

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	var n int
	var t, w int64
	var hmin HeapMin
	var queue TeamSlice

	fmt.Fscanf(bufin, "%d\n", &n)
	fmt.Fscanf(bufin, "%d %d\n", &t, &w)

	balloon := t
	rank := 1

	for i := 2; i <= n; i++ {
		fmt.Fscanf(bufin, "%d %d\n", &t, &w)
		if t > balloon {
			heap.Push(&hmin, &NodeMin{value: w - t + 1})
			rank++
		} else {
			queue = append(queue, Team{t: t, w: w})
		}
	}

	sort.Sort(queue)
	nq := len(queue)

	bestRank := rank
	pos := 0

	for hmin.Len() > 0 {
		node := heap.Pop(&hmin).(*NodeMin)

		t = node.value
		if t > balloon {
			break
		}

		rank--
		for balloon -= t; (pos < nq) && (queue[pos].t > balloon); pos++ {
			heap.Push(&hmin, &NodeMin{value: queue[pos].w - queue[pos].t + 1})
			rank++
		}

		if rank < bestRank {
			bestRank = rank
		}
	}

	fmt.Fprintf(bufout, "%d\n", bestRank)
}

package main

import (
	"bufio"
	. "container/heap"
	. "fmt"
	"io"
	"os"
	"sort"
)

type int64Heap []int64

func (h int64Heap) Len() int              { return len(h) }
func (h int64Heap) Less(i, j int) bool    { return h[i] < h[j] }
func (h int64Heap) Swap(i, j int)         { h[i], h[j] = h[j], h[i] }
func (h *int64Heap) Push(v interface{})   { *h = append(*h, v.(int64)) }
func (h *int64Heap) Pop() (v interface{}) { n := len(*h); *h, v = (*h)[:n-1], (*h)[n-1]; return }

// github.com/EndlessCheng/codeforces-go
func CF725D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type team struct{ balls, weight int64 }

	var n, ans int
	var myBalls, w, gives int64
	Fscan(in, &n, &myBalls, &w)
	ts := make([]team, n-1, n)
	for i := range ts {
		Fscan(in, &ts[i].balls, &ts[i].weight)
	}
	sort.Slice(ts, func(i, j int) bool { return ts[i].balls > ts[j].balls })
	ts = append(ts, team{})

	for _, t := range ts {
		if t.balls <= myBalls {
			gives = myBalls - t.balls
			myBalls = t.balls
			break
		}
		ans++
	}
	h := &int64Heap{}
	for i := 0; ts[i].balls > 0; {
		for ; ts[i].balls > myBalls; i++ {
			Push(h, ts[i].weight-ts[i].balls+1)
		}
		for len(*h) > 0 {
			d := (*h)[0]
			if d > gives {
				break
			}
			Pop(h)
			gives -= d
		}
		if len(*h) < ans {
			ans = len(*h)
		}
		for _, t := range ts[i:] {
			if b := t.balls; b < myBalls {
				gives += myBalls - b
				myBalls = b
				break
			}
		}
	}
	Fprint(out, ans+1)
}

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

package main

import (
	"bufio"
	. "container/heap"
	. "fmt"
	"io"
	"os"
	"sort"
)

type int64Heap []int64

func (h int64Heap) Len() int              { return len(h) }
func (h int64Heap) Less(i, j int) bool    { return h[i] < h[j] }
func (h int64Heap) Swap(i, j int)         { h[i], h[j] = h[j], h[i] }
func (h *int64Heap) Push(v interface{})   { *h = append(*h, v.(int64)) }
func (h *int64Heap) Pop() (v interface{}) { n := len(*h); *h, v = (*h)[:n-1], (*h)[n-1]; return }

// github.com/EndlessCheng/codeforces-go
func CF725D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type team struct{ balls, weight int64 }

	var n, ans int
	var myBalls, w, gives int64
	Fscan(in, &n, &myBalls, &w)
	ts := make([]team, n-1, n)
	for i := range ts {
		Fscan(in, &ts[i].balls, &ts[i].weight)
	}
	sort.Slice(ts, func(i, j int) bool { return ts[i].balls > ts[j].balls })
	ts = append(ts, team{})

	for _, t := range ts {
		if t.balls <= myBalls {
			gives = myBalls - t.balls
			myBalls = t.balls
			break
		}
		ans++
	}
	h := &int64Heap{}
	for i := 0; i < n && ts[i].balls > 0; {
		for ; i < n && ts[i].balls > myBalls; i++ {
			Push(h, ts[i].weight-ts[i].balls+1)
		}
		for len(*h) > 0 {
			d := (*h)[0]
			if d > gives {
				break
			}
			Pop(h)
			gives -= d
		}
		if len(*h) < ans {
			ans = len(*h)
		}
		for j := i; j < n; j++ {
			if ts[j].balls < myBalls {
				gives += myBalls - ts[j].balls
				myBalls = ts[j].balls
				break
			}
		}
	}
	Fprint(out, ans+1)
}

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

package main

import (
	"bufio"
	. "container/heap"
	. "fmt"
	"io"
	"os"
	"sort"
)

type int64Heap []int64

func (h int64Heap) Len() int              { return len(h) }
func (h int64Heap) Less(i, j int) bool    { return h[i] < h[j] }
func (h int64Heap) Swap(i, j int)         { h[i], h[j] = h[j], h[i] }
func (h *int64Heap) Push(v interface{})   { *h = append(*h, v.(int64)) }
func (h *int64Heap) Pop() (v interface{}) { n := len(*h); *h, v = (*h)[:n-1], (*h)[n-1]; return }

// github.com/EndlessCheng/codeforces-go
func CF725D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type team struct{ balls, weight int64 }

	var n, ans int
	var myBalls, w, gives int64
	Fscan(in, &n, &myBalls, &w)
	ts := make([]team, n-1, n)
	for i := range ts {
		Fscan(in, &ts[i].balls, &ts[i].weight)
	}
	sort.Slice(ts, func(i, j int) bool { return ts[i].balls > ts[j].balls })
	ts = append(ts, team{})

	for _, t := range ts {
		if t.balls <= myBalls {
			gives = myBalls - t.balls
			myBalls = t.balls
			break
		}
		ans++
	}
	h := &int64Heap{}
	for i := 0; ts[i].balls > 0; {
		for ; ts[i].balls > myBalls; i++ {
			Push(h, ts[i].weight-ts[i].balls+1)
		}
		for len(*h) > 0 {
			d := (*h)[0]
			if d > gives {
				break
			}
			Pop(h)
			gives -= d
		}
		if len(*h) < ans {
			ans = len(*h)
		}
		for j := i; j < n; j++ {
			if ts[j].balls < myBalls {
				gives += myBalls - ts[j].balls
				myBalls = ts[j].balls
				break
			}
		}
	}
	Fprint(out, ans+1)
}

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

package main

import (
	"bufio"
	. "container/heap"
	. "fmt"
	"io"
	"os"
	"sort"
)

type int64Heap []int64

func (h int64Heap) Len() int              { return len(h) }
func (h int64Heap) Less(i, j int) bool    { return h[i] < h[j] }
func (h int64Heap) Swap(i, j int)         { h[i], h[j] = h[j], h[i] }
func (h *int64Heap) Push(v interface{})   { *h = append(*h, v.(int64)) }
func (h *int64Heap) Pop() (v interface{}) { n := len(*h); *h, v = (*h)[:n-1], (*h)[n-1]; return }

// github.com/EndlessCheng/codeforces-go
func CF725D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type team struct{ balls, weight int64 }

	var n int
	var myBalls, w, gives int64
	Fscan(in, &n, &myBalls, &w)
	ts := make([]team, n-1, n)
	for i := range ts {
		Fscan(in, &ts[i].balls, &ts[i].weight)
	}
	sort.Slice(ts, func(i, j int) bool { return ts[i].balls > ts[j].balls })
	ts = append(ts, team{})

	ans := n
	for _, t := range ts {
		if t.balls <= myBalls {
			gives = myBalls - t.balls
			myBalls = t.balls
			break
		}
	}
	h := &int64Heap{}
	for i := 0; i < n && ts[i].balls > 0; {
		for ; i < n && ts[i].balls > myBalls; i++ {
			Push(h, ts[i].weight-ts[i].balls+1)
		}
		for len(*h) > 0 {
			d := (*h)[0]
			if d > gives {
				break
			}
			Pop(h)
			gives -= d
		}
		if len(*h) < ans {
			ans = len(*h)
		}
		for j := i; j < n; j++ {
			if ts[j].balls < myBalls {
				gives += myBalls - ts[j].balls
				myBalls = ts[j].balls
				break
			}
		}
	}
	Fprint(out, ans+1)
}

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


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) bool {
		var n int
		Fscan(in, &n)
		b := make([]int, n)
		for i := range b {
			Fscan(in, &b[i])
		}
		cnts := map[int]int{}
		for _, v := range b {
			cnts[v]++
			if cnts[v] > 1 {
				return true
			}
		}
		return  false
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		Fprintln(out, map[bool]string{true: "YES", false: "NO"}[solve(Case)])
	}
}

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

package main

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

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n int
	var b []int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		b = make([]int, n)
		for i := range b {
			fmt.Fscan(in, &b[i])
		}
		sort.Ints(b)
		result := false
		for i := 1; i < n; i++ {
			if b[i] == b[i-1] {
				result = true
				break
			}
		}
		if result {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Fscan(reader, &t)

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

		b := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(reader, &b[j])
		}

		sort.Ints(b)

		result := "NO"
		for j := 1; j < n; j++ {
			if b[j] == b[j-1] {
				result = "YES"
				break
			}
		}

		fmt.Println(result)
	}
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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 gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

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

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; 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 {
	cache := map[int64]bool{}
	for _, d := range a {
		if cache[d] {
			return "YES"
		}
		cache[d] = true
	}
	return "NO"
}

// Written by : Syed Mujtaba
// Seek knowledge from the cradle to the grave
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 main() {
  defer writer.Flush()
  var t int
  fmt.Scanf("%d\n", &t)

  for i := 0; i < t; i++ {
  	var n int
  	scanf("%d\n", &n)
  	mp := make(map[int]int)
  	for j := 0; j < n; j++ {
  		var x int
  		scanf("%d", &x)
  		mp[x] = 1
  		if j != n - 1 {
  			scanf(" ")
  		} else {
  			scanf("\n")
  		}
  	}
  	if len(mp) == n {
  		printf("NO\n")
  	} else {
  		printf("YES\n")
  	}
  }
}

package main

import (
	"fmt"
	"bufio"
	"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 solveA() {
	n := 0
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		printf("1 ")
	}
	printf("\n")
}

func solveB() {
	n := 0
	scanf("%d\n", &n)
	d := make(map[int]int)
	ans := "NO"
	for k, i := 0, 0; i < n; i++ {
		if i + 1 == n {
			scanf("%d\n", &k)
		} else {
			scanf("%d ", &k)
		}
		d[k]++
		if d[k] > 1 {
			ans = "YES"
		}
	}
	printf(ans + "\n")
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solveB()
	}
}

/*
URL:
https://codeforces.com/contest/1438/problem/B
*/

package main

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

var (
	t int

	n int
	B []int
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		n = readi()
		B = readis(n)

		solve()
	}
}

func solve() {
	memo := make(map[int]bool)
	for _, b := range B {
		memo[b] = true
	}

	if len(memo) == n {
		printf("NO\n")
	} else {
		printf("YES\n")
	}
}

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

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

// Written by : Syed Mujtaba
// Seek knowledge from the cradle to the grave
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 main() {
  defer writer.Flush()
  var t int
  scanf("%d\n", &t)

  for i := 0; i < t; i++ {
  	var n int
  	scanf("%d\n", &n)
  	mp := make(map[int]int)
  	for j := 0; j < n; j++ {
  		var x int
  		scanf("%d ", &x)
  		mp[x] = 1
  	}
  	if len(mp) == n {
  		printf("NO\n")
  	} else {
  		printf("YES\n")
  	}
  }
}

package main

import (
	"fmt"
	"bufio"
	"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 solveA() {
	n := 0
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		printf("1 ")
	}
	printf("\n")
}

func solveB() {
	n := 0
	scanf("%d\n", &n)
	d := make(map[int]int)
	ans := "NO"
	for k, i := 0, 0; i < n; i++ {
		scanf("%d ", &k)
		d[k]++
		if d[k] > 1 {
			ans = "YES"
		}
	}
	printf(ans + "\n")
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solveB()
	}
}

package main

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

func main() {
	rd, _ := os.Open("input")
	in := bufio.NewReader(rd)
	//in := bufio.NewReader(os.Stdin)

	var t, n int
	var b []int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		b = make([]int, n)
		for i := range b {
			fmt.Fscan(in, &b[i])
		}
		sort.Ints(b)
		result := false
		for i := 1; i < n; i++ {
			if b[i] == b[i-1] {
				result = true
				break
			}
		}
		if result {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}


package main

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

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

	n := io.NextInt()
	a := io.NextInts(n)

	var solve func(l, r, d int) int64
	solve = func(l, r, d int) int64 {
		if l == r {
			return 0
		}
		m := l
		for i := l + 1; i < r; i++ {
			if a[i] < a[m] {
				m = i
			}
		}
		ver := int64(r - l)
		res := int64(a[m]-d) + solve(l, m, a[m]) + solve(m+1, r, a[m])
		if ver < res {
			return ver
		}
		return res
	}

	io.Println(solve(0, n, 0))
}

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

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

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

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

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

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

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n := readNum(reader)
	A := readNNums(reader, n)
	fmt.Println(solve(n, A))
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, A []int) int {

	var loop func(l, r int, x int) int

	loop = func(l, r int, x int) int {
		y := A[l]
		for i := l + 1; i <= r; i++ {
			if A[i] < y {
				y = A[i]
			}
		}
		cnt := r - l + 1
		if y-x >= cnt {
			return cnt
		}
		res := y - x
		i := l
		for i <= r {
			if A[i] == y {
				i++
				continue
			}
			// A[i] != y
			j := i
			for i <= r && A[i] > y {
				i++
			}
			res += loop(j, i-1, y)
		}
		return min(res, cnt)
	}

	return loop(0, n-1, 0)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1400E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var f func([]int, int) int
	f = func(a []int, low int) int {
		if len(a) == 0 {
			return 0
		}
		mi := int(1e9)
		for _, v := range a {
			mi = min(mi, v)
		}
		c, p := mi-low, 0
		for i, v := range a {
			if v == mi {
				c += f(a[p:i], mi)
				p = i + 1
			}
		}
		c += f(a[p:], mi)
		return min(c, len(a))
	}
	var n int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	Fprint(out, f(a, 0))
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1400E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var f func([]int, int) int
	f = func(a []int, low int) int {
		if len(a) <= 1 {
			return len(a)
		}
		mi := int(1e9)
		for _, v := range a {
			mi = min(mi, v)
		}
		c, p := mi-low, 0
		for i, v := range a {
			if v == mi {
				c += f(a[p:i], mi)
				p = i + 1
			}
		}
		c += f(a[p:], mi)
		return min(c, len(a))
	}
	var n int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	Fprint(out, f(a, 0))
}

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


package main

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

var _x = uint(1)

func fastRand() uint {
	_x ^= _x << 13
	_x ^= _x >> 17
	_x ^= _x << 5
	return _x
}

type node struct {
	lr       [2]*node
	priority uint
	key      int
	value    int
}

func (o *node) rotate(d int) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	return x
}

type treap struct {
	root       *node
	comparator func(a, b int) int
}

func newTreap() *treap {
	return &treap{comparator: func(a, b int) int {
		if a < b {
			return 0
		}
		if a > b {
			return 1
		}
		return -1
	}}
}

func (t *treap) _put(o *node, key int) *node {
	if o == nil {
		return &node{priority: fastRand(), key: key, value: 1}
	}
	if cmp := t.comparator(key, o.key); cmp >= 0 {
		o.lr[cmp] = t._put(o.lr[cmp], key)
		if o.lr[cmp].priority > o.priority {
			o = o.rotate(cmp ^ 1)
		}
	} else {
		o.value++
	}
	return o
}

func (t *treap) put(key int) { t.root = t._put(t.root, key) }

func (t *treap) _delete(o *node, key int) *node {
	if o == nil {
		return nil
	}
	if cmp := t.comparator(key, o.key); cmp >= 0 {
		o.lr[cmp] = t._delete(o.lr[cmp], key)
	} else {
		if o.value > 1 {
			o.value--
		} else {
			if o.lr[1] == nil {
				return o.lr[0]
			}
			if o.lr[0] == nil {
				return o.lr[1]
			}
			cmp2 := 0
			if o.lr[0].priority > o.lr[1].priority {
				cmp2 = 1
			}
			o = o.rotate(cmp2)
			o.lr[cmp2] = t._delete(o.lr[cmp2], key)
		}
	}
	return o
}

func (t *treap) delete(key int) { t.root = t._delete(t.root, key) }

func (t *treap) max() int {
	var max *node
	for o := t.root; o != nil; o = o.lr[1] {
		max = o
	}
	return max.key
}

func (t *treap) floor(key int) int {
	var floor *node
	for o := t.root; o != nil; {
		switch cmp := t.comparator(key, o.key); {
		case cmp == 0:
			o = o.lr[0]
		case cmp > 0:
			floor = o
			o = o.lr[1]
		default:
			return o.key
		}
	}
	return floor.key
}

// github.com/EndlessCheng/codeforces-go
func Sol706D(reader io.Reader, writer io.Writer) {
	min := func(a, b int) int {
		if a <= b {
			return a
		}
		return b
	}
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	t := newTreap()
	t.put(0)

	nextFloor := func(bitPos int, floor, x int) (f int, i int) {
		for i = bitPos; i >= 0; i-- {
			ui := uint(i)
			bitFloor := floor >> ui & 1
			bitX := x >> ui & 1
			if bitFloor == 1 && bitX == 1 {
				// mask floor
				check := floor&^(1<<ui) | (1<<ui - 1)
				newFloor := t.floor(check)
				return newFloor, i - 1
			}
		}
		return -1, -1
	}

	var q, x int
	var op string
	for Fscan(in, &q); q > 0; q-- {
		switch Fscan(in, &op, &x); op[0] {
		case '+':
			t.put(x)
		case '-':
			t.delete(x)
		default:
			floor := t.max()
			if floor == 0 {
				Fprintln(out, x)
				continue
			}
			ans := floor ^ x
			var newFloor int
			for i := min(bits.Len(uint(floor)), bits.Len(uint(x))) - 1; i >= 0; {
				newFloor, i = nextFloor(i, floor, x)
				if newFloor == -1 {
					break
				}
				if newXor := newFloor ^ x; newXor > ans {
					ans = newXor
					floor = newFloor
				}
			}
			Fprintln(out, ans)
		}
	}
}

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

package main

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

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

// Node is a Trie node
type Node struct {
	val   int
	child [2]*Node
}

func create(v int) *Node {
	r := &Node{
		val:   0,
		child: [2]*Node{nil, nil},
	}
	return r
}

func add(x int, i int, node *Node) {
	node.val++
	if i < 0 {
		return
	}
	bit := (x >> uint(i)) & 1
	if node.child[bit] == nil {
		node.child[bit] = create(0)
	}
	add(x, i-1, node.child[bit])
}

func del(x int, i int, node *Node) {
	node.val--
	if i < 0 {
		return
	}
	bit := (x >> uint(i)) & 1
	del(x, i-1, node.child[bit])
}

func query(x int, i int, node *Node, res int) int {
	if i < 0 {
		return res
	}

	bit := (x >> uint(i)) & 1
	rbit := 1 - bit

	if (node.child[rbit] != nil) && (node.child[rbit].val > 0) {
		return query(x, i-1, node.child[rbit], res+(1<<uint(i)))
	}

	if (node.child[bit] != nil) && (node.child[bit].val > 0) {
		return query(x, i-1, node.child[bit], res)
	}

	return -1
}

const maxbit = 30

var n int
var root *Node

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	in.Scan()
	n, _ = strconv.Atoi(in.Text())

	root = create(0)
	add(0, maxbit, root)

	for i := 0; i < n; i++ {
		in.Scan()
		c := in.Text()

		in.Scan()
		x, _ := strconv.Atoi(in.Text())

		if c == "+" {
			add(x, maxbit, root)
		} else if c == "-" {
			del(x, maxbit, root)
		} else {
			res := query(x, maxbit, root, 0)
			out.WriteString(strconv.Itoa(res))
			out.WriteByte('\n')
		}
	}
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Trie struct {
  Next []*Trie
  Count int
}

const numBits = 30

func newTrie() *Trie {
  return &Trie{ make([]*Trie, 2), 0 }
}

func insert(trie *Trie, x, delta int) {
  mask := 1 << (numBits - 1)
  for mask > 0 {
    a := 0
    if x & mask > 0 {
      a = 1
    }
    if trie.Next[a] == nil {
      trie.Next[a] = newTrie()
    }
    trie = trie.Next[a]
    trie.Count += delta
    mask >>= 1
  }
}

func xor(trie *Trie, x int) int {
  mask := 1 << (numBits - 1)
  result := 0
  for mask > 0 {
    if mask & x == 0 && trie.Next[1] != nil && trie.Next[1].Count > 0 {
      result |= mask
      trie = trie.Next[1]
    } else if mask & x != 0 && trie.Next[0] != nil && trie.Next[0].Count > 0 {
      result |= mask
      trie = trie.Next[0]
    } else if trie.Next[0] != nil && trie.Next[0].Count > 0 {
      trie = trie.Next[0]
    } else {
      trie = trie.Next[1]
    }
    mask >>= 1
  }
  return result
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  q := getI()
  trie := newTrie()
  insert(trie, 0, 1)
  for qi := 0; qi < q; qi++ {
    op, x := getS(), getI()
    if op == "+" {
      insert(trie, x, 1)
    } else if op == "-" {
      insert(trie, x, -1)
    } else {
      writer.WriteString(fmt.Sprintf("%d\n", xor(trie, x)))
    }
  }
}

package main

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

// node represents a node in a trie that is used to track the elements of the multiset.
// The trie has 33 levels of nodes and so 32 levels of edges.
type node struct {
	count    int
	children [2]*node
}

var root *node = &node{}

func alloc(pn **node) *node {
	if *pn == nil {
		*pn = &node{}
	}
	return *pn
}

func visitRec(n *node, val uint, mask uint, delta int) {
	n.count += delta
	if mask == 0 {
		return
	}
	idx := 0
	if val&mask != 0 {
		idx = 1
	}
	visitRec(alloc(&n.children[idx]), val, mask>>1, delta)
}

func add(val uint) {
	visitRec(root, val, 0x80000000, 1)
}

func remove(val uint) {
	visitRec(root, val, 0x80000000, -1)
}

func findRec(n *node, val uint, mask uint) uint {
	if mask == 0 {
		return 0
	}
	idx := 0
	if val&mask != 0 {
		idx = 1
	}
	if n.children[idx] != nil && n.children[idx].count > 0 {
		return mask + findRec(n.children[idx], val, mask>>1)
	} else {
		return findRec(n.children[1-idx], val, mask>>1)
	}
}

func find(val uint) uint {
	return findRec(root, val, 0x80000000)
}

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

	var q int
	fmt.Fscanf(reader, "%d ", &q)
	ret := make([]uint, 0)
	add(0)
	for i := 0; i < q; i++ {
		var op string
		fmt.Fscanf(reader, "%s ", &op)
		var val uint
		fmt.Fscanf(reader, "%d ", &val)
		switch op {
		case "+":
			add(val)
		case "-":
			remove(val)
		case "?":
			ret = append(ret, find(^val))
		}
	}
	for _, x := range ret {
		fmt.Printf("%d\n", x)
	}
}

package main

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

var _x = uint(1)

func fastRand() uint {
	_x ^= _x << 13
	_x ^= _x >> 17
	_x ^= _x << 5
	return _x
}

type node struct {
	lr       [2]*node
	priority uint
	key      int
	value    int
}

func (o *node) rotate(d int) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	return x
}

type treap struct {
	root       *node
	comparator func(a, b int) int
}

func newTreap() *treap {
	return &treap{comparator: func(a, b int) int {
		if a < b {
			return 0
		}
		if a > b {
			return 1
		}
		return -1
	}}
}

func (t *treap) _put(o *node, key int) *node {
	if o == nil {
		return &node{priority: fastRand(), key: key, value: 1}
	}
	if cmp := t.comparator(key, o.key); cmp >= 0 {
		o.lr[cmp] = t._put(o.lr[cmp], key)
		if o.lr[cmp].priority > o.priority {
			o = o.rotate(cmp ^ 1)
		}
	} else {
		o.value++
	}
	return o
}

func (t *treap) put(key int) { t.root = t._put(t.root, key) }

func (t *treap) _delete(o *node, key int) *node {
	if o == nil {
		return nil
	}
	if cmp := t.comparator(key, o.key); cmp >= 0 {
		o.lr[cmp] = t._delete(o.lr[cmp], key)
	} else {
		if o.value > 1 {
			o.value--
		} else {
			if o.lr[1] == nil {
				return o.lr[0]
			}
			if o.lr[0] == nil {
				return o.lr[1]
			}
			cmp2 := 0
			if o.lr[0].priority > o.lr[1].priority {
				cmp2 = 1
			}
			o = o.rotate(cmp2)
			o.lr[cmp2] = t._delete(o.lr[cmp2], key)
		}
	}
	return o
}

func (t *treap) delete(key int) { t.root = t._delete(t.root, key) }

func (t *treap) max() int {
	var max *node
	for o := t.root; o != nil; o = o.lr[1] {
		max = o
	}
	return max.key
}

func (t *treap) floor(key int) int {
	var floor *node
	for o := t.root; o != nil; {
		switch cmp := t.comparator(key, o.key); {
		case cmp == 0:
			o = o.lr[0]
		case cmp > 0:
			floor = o
			o = o.lr[1]
		default:
			return o.key
		}
	}
	return floor.key
}

// github.com/EndlessCheng/codeforces-go
func Sol706D(reader io.Reader, writer io.Writer) {
	bitLength := func(n int) (c int) {
		for ; n > 0; n >>= 1 {
			c++
		}
		return
	}
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	t := newTreap()
	t.put(0)

	nextUp := func(bitPos int, up, x int) (int, int) {
		for i := bitPos; i >= 0; i-- {
			ui := uint(i)
			if up>>ui&1 == 1 && x>>ui&1 == 1 {
				check := up&^(1<<ui) | (1<<ui - 1)
				return t.floor(check), i - 1
			}
		}
		return -1, -1
	}

	var q, x int
	var op string
	for Fscan(in, &q); q > 0; q-- {
		switch Fscan(in, &op, &x); op[0] {
		case '+':
			t.put(x)
		case '-':
			t.delete(x)
		default:
			up := t.max()
			if up == 0 {
				Fprintln(out, x)
				continue
			}
			ans := up ^ x
			minL := bitLength(up)
			if l := bitLength(x); l < minL {
				minL = l
			}
			var newUp int
			for i := minL - 1; i >= 0; {
				newUp, i = nextUp(i, up, x)
				if newUp == -1 {
					break
				}
				if newXor := newUp ^ x; newXor > ans {
					ans = newXor
					up = newUp
				}
			}
			Fprintln(out, ans)
		}
	}
}

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

package main

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

var _x = uint(time.Now().UnixNano())

func fastRand() uint {
	_x ^= _x << 13
	_x ^= _x >> 17
	_x ^= _x << 5
	return _x
}

type node struct {
	lr    [2]*node
	p     uint
	key   int
	value int
}

func (o *node) rotate(d int) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	return x
}

type treap struct {
	root       *node
	comparator func(a, b int) int
}

func newTreap() *treap {
	return &treap{comparator: func(a, b int) int {
		if a < b {
			return 0
		}
		if a > b {
			return 1
		}
		return -1
	}}
}

func (t *treap) _put(o *node, key int) *node {
	if o == nil {
		return &node{p: fastRand(), key: key, value: 1}
	}
	if cmp := t.comparator(key, o.key); cmp >= 0 {
		o.lr[cmp] = t._put(o.lr[cmp], key)
		if o.lr[cmp].p > o.p {
			o = o.rotate(cmp ^ 1)
		}
	} else {
		o.value++
	}
	return o
}

func (t *treap) put(key int) { t.root = t._put(t.root, key) }

func (t *treap) _delete(o *node, key int) *node {
	if o == nil {
		return nil
	}
	if cmp := t.comparator(key, o.key); cmp >= 0 {
		o.lr[cmp] = t._delete(o.lr[cmp], key)
	} else {
		if o.value > 1 {
			o.value--
		} else {
			if o.lr[1] == nil {
				return o.lr[0]
			}
			if o.lr[0] == nil {
				return o.lr[1]
			}
			cmp2 := 0
			if o.lr[0].p > o.lr[1].p {
				cmp2 = 1
			}
			o = o.rotate(cmp2)
			o.lr[cmp2] = t._delete(o.lr[cmp2], key)
		}
	}
	return o
}

func (t *treap) delete(key int) { t.root = t._delete(t.root, key) }

func (t *treap) max() int {
	var max *node
	for o := t.root; o != nil; o = o.lr[1] {
		max = o
	}
	return max.key
}

func (t *treap) ceiling(key int) int {
	var ceiling *node
	for o := t.root; o != nil; {
		switch cmp := t.comparator(key, o.key); {
		case cmp == 0:
			ceiling = o
			o = o.lr[0]
		case cmp > 0:
			o = o.lr[1]
		default:
			return o.key
		}
	}
	return ceiling.key
}

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

	t := newTreap()
	t.put(0)
	var q, x int
	var op string
	for Fscan(in, &q); q > 0; q-- {
		switch Fscan(in, &op, &x); op[0] {
		case '+':
			t.put(x)
		case '-':
			t.delete(x)
		default:
			mx := t.max()
			mix := 0
			for i := 29; i >= 0; i-- {
				ui := uint(i)
				mix |= 1 << ui &^ x
				if mix > mx {
					mix ^= 1 << ui
				} else if up := t.ceiling(mix); up>>ui != mix>>ui {
					mix ^= 1 << ui
				}
			}
			Fprintln(out, mix^x)
		}
	}
}

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

package main

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

var _x = uint(time.Now().UnixNano())

func fastRand() uint {
	_x ^= _x << 13
	_x ^= _x >> 17
	_x ^= _x << 5
	return _x
}

type node struct {
	lr    [2]*node
	p     uint
	key   int
	value int
}

func (o *node) rotate(d int) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	return x
}

type treap struct {
	root       *node
	comparator func(a, b int) int
}

func newTreap() *treap {
	return &treap{comparator: func(a, b int) int {
		if a < b {
			return 0
		}
		if a > b {
			return 1
		}
		return -1
	}}
}

func (t *treap) _put(o *node, key int) *node {
	if o == nil {
		return &node{p: fastRand(), key: key, value: 1}
	}
	if cmp := t.comparator(key, o.key); cmp >= 0 {
		o.lr[cmp] = t._put(o.lr[cmp], key)
		if o.lr[cmp].p > o.p {
			o = o.rotate(cmp ^ 1)
		}
	} else {
		o.value++
	}
	return o
}

func (t *treap) put(key int) { t.root = t._put(t.root, key) }

func (t *treap) _delete(o *node, key int) *node {
	if o == nil {
		return nil
	}
	if cmp := t.comparator(key, o.key); cmp >= 0 {
		o.lr[cmp] = t._delete(o.lr[cmp], key)
	} else {
		if o.value > 1 {
			o.value--
		} else {
			if o.lr[1] == nil {
				return o.lr[0]
			}
			if o.lr[0] == nil {
				return o.lr[1]
			}
			cmp2 := 0
			if o.lr[0].p > o.lr[1].p {
				cmp2 = 1
			}
			o = o.rotate(cmp2)
			o.lr[cmp2] = t._delete(o.lr[cmp2], key)
		}
	}
	return o
}

func (t *treap) delete(key int) { t.root = t._delete(t.root, key) }

func (t *treap) max() int {
	var max *node
	for o := t.root; o != nil; o = o.lr[1] {
		max = o
	}
	return max.key
}

func (t *treap) ceiling(key int) int {
	var ceiling *node
	for o := t.root; o != nil; {
		switch cmp := t.comparator(key, o.key); {
		case cmp == 0:
			ceiling = o
			o = o.lr[0]
		case cmp > 0:
			o = o.lr[1]
		default:
			return o.key
		}
	}
	return ceiling.key
}

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

	t := newTreap()
	t.put(0)
	var q, x int
	var op string
	for Fscan(in, &q); q > 0; q-- {
		switch Fscan(in, &op, &x); op[0] {
		case '+':
			t.put(x)
		case '-':
			t.delete(x)
		default:
			mx := t.max()
			mix := 0
			for i := 30; i >= 0; i-- {
				ui := uint(i)
				mix |= 1 << ui &^ x
				if mix > mx {
					mix ^= 1 << ui
				} else if up := t.ceiling(mix); up>>ui != mix>>ui {
					mix ^= 1 << ui
				}
			}
			Fprintln(out, mix^x)
		}
	}
}

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

package main

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

var _x = uint(1)

func fastRand() uint {
	_x ^= _x << 13
	_x ^= _x >> 17
	_x ^= _x << 5
	return _x
}

type node struct {
	lr    [2]*node
	p     uint
	key   int
	value int
}

func (o *node) rotate(d int) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	return x
}

type treap struct {
	root       *node
	comparator func(a, b int) int
}

func newTreap() *treap {
	return &treap{comparator: func(a, b int) int {
		if a < b {
			return 0
		}
		if a > b {
			return 1
		}
		return -1
	}}
}

func (t *treap) _put(o *node, key int) *node {
	if o == nil {
		return &node{p: fastRand(), key: key, value: 1}
	}
	if cmp := t.comparator(key, o.key); cmp >= 0 {
		o.lr[cmp] = t._put(o.lr[cmp], key)
		if o.lr[cmp].p > o.p {
			o = o.rotate(cmp ^ 1)
		}
	} else {
		o.value++
	}
	return o
}

func (t *treap) put(key int) { t.root = t._put(t.root, key) }

func (t *treap) _delete(o *node, key int) *node {
	if o == nil {
		return nil
	}
	if cmp := t.comparator(key, o.key); cmp >= 0 {
		o.lr[cmp] = t._delete(o.lr[cmp], key)
	} else {
		if o.value > 1 {
			o.value--
		} else {
			if o.lr[1] == nil {
				return o.lr[0]
			}
			if o.lr[0] == nil {
				return o.lr[1]
			}
			cmp2 := 0
			if o.lr[0].p > o.lr[1].p {
				cmp2 = 1
			}
			o = o.rotate(cmp2)
			o.lr[cmp2] = t._delete(o.lr[cmp2], key)
		}
	}
	return o
}

func (t *treap) delete(key int) { t.root = t._delete(t.root, key) }

func (t *treap) max() int {
	var max *node
	for o := t.root; o != nil; o = o.lr[1] {
		max = o
	}
	return max.key
}

func (t *treap) ceiling(key int) int {
	var ceiling *node
	for o := t.root; o != nil; {
		switch cmp := t.comparator(key, o.key); {
		case cmp == 0:
			ceiling = o
			o = o.lr[0]
		case cmp > 0:
			o = o.lr[1]
		default:
			return o.key
		}
	}
	return ceiling.key
}

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

	t := newTreap()
	t.put(0)
	var q, x int
	var op string
	for Fscan(in, &q); q > 0; q-- {
		switch Fscan(in, &op, &x); op[0] {
		case '+':
			t.put(x)
		case '-':
			t.delete(x)
		default:
			mx := t.max()
			mix := 0
			for i := 30; i >= 0; i-- {
				ui := uint(i)
				mix |= 1 << ui &^ x
				if mix > mx {
					mix ^= 1 << ui
				} else if up := t.ceiling(mix); up>>ui != mix>>ui {
					mix ^= 1 << ui
				}
			}
			Fprintln(out, mix^x)
		}
	}
}

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

package main

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

var _x = uint(1)

func fastRand() uint {
	_x ^= _x << 13
	_x ^= _x >> 17
	_x ^= _x << 5
	return _x
}

type node struct {
	lr       [2]*node
	priority uint
	key      int
	value    int
}

func (o *node) rotate(d int) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	return x
}

type treap struct {
	root       *node
	comparator func(a, b int) int
}

func newTreap() *treap {
	return &treap{comparator: func(a, b int) int {
		if a < b {
			return 0
		}
		if a > b {
			return 1
		}
		return -1
	}}
}

func (t *treap) _put(o *node, key int) *node {
	if o == nil {
		return &node{priority: fastRand(), key: key, value: 1}
	}
	if cmp := t.comparator(key, o.key); cmp >= 0 {
		o.lr[cmp] = t._put(o.lr[cmp], key)
		if o.lr[cmp].priority > o.priority {
			o = o.rotate(cmp ^ 1)
		}
	} else {
		o.value++
	}
	return o
}

func (t *treap) put(key int) { t.root = t._put(t.root, key) }

func (t *treap) _delete(o *node, key int) *node {
	if o == nil {
		return nil
	}
	if cmp := t.comparator(key, o.key); cmp >= 0 {
		o.lr[cmp] = t._delete(o.lr[cmp], key)
	} else {
		if o.value > 1 {
			o.value--
		} else {
			if o.lr[1] == nil {
				return o.lr[0]
			}
			if o.lr[0] == nil {
				return o.lr[1]
			}
			cmp2 := 0
			if o.lr[0].priority > o.lr[1].priority {
				cmp2 = 1
			}
			o = o.rotate(cmp2)
			o.lr[cmp2] = t._delete(o.lr[cmp2], key)
		}
	}
	return o
}

func (t *treap) delete(key int) { t.root = t._delete(t.root, key) }

func (t *treap) max() int {
	var max *node
	for o := t.root; o != nil; o = o.lr[1] {
		max = o
	}
	return max.key
}

func (t *treap) floor(key int) int {
	var floor *node
	for o := t.root; o != nil; {
		switch cmp := t.comparator(key, o.key); {
		case cmp == 0:
			o = o.lr[0]
		case cmp > 0:
			floor = o
			o = o.lr[1]
		default:
			return o.key
		}
	}
	return floor.key
}

// github.com/EndlessCheng/codeforces-go
func Sol706D(reader io.Reader, writer io.Writer) {
	bitLength := func(n int) int {
		c := 1
		if n>>16 > 0 {
			c += 16
			n >>= 16
		}
		if n>>8 > 0 {
			c += 8
			n >>= 8
		}
		if n>>4 > 0 {
			c += 4
			n >>= 4
		}
		if n>>2 > 0 {
			c += 2
			n >>= 2
		}
		if n-1 > 0 {
			c++
		}
		return c
	}
	min := func(a, b int) int {
		if a <= b {
			return a
		}
		return b
	}
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	t := newTreap()
	t.put(0)

	nextFloor := func(bitPos int, floor, x int) (f int, i int) {
		for i = bitPos; i >= 0; i-- {
			ui := uint(i)
			bitFloor := floor >> ui & 1
			bitX := x >> ui & 1
			if bitFloor == 1 && bitX == 1 {
				// mask floor
				check := floor&^(1<<ui) | (1<<ui - 1)
				newFloor := t.floor(check)
				return newFloor, i - 1
			}
		}
		return -1, -1
	}

	var q, x int
	var op string
	for Fscan(in, &q); q > 0; q-- {
		switch Fscan(in, &op, &x); op[0] {
		case '+':
			t.put(x)
		case '-':
			t.delete(x)
		default:
			floor := t.max()
			if floor == 0 {
				Fprintln(out, x)
				continue
			}
			ans := floor ^ x
			var newFloor int
			for i := min(bitLength(floor), bitLength(x)) - 1; i >= 0; {
				newFloor, i = nextFloor(i, floor, x)
				if newFloor == -1 {
					break
				}
				if newXor := newFloor ^ x; newXor > ans {
					ans = newXor
					floor = newFloor
				}
			}
			Fprintln(out, ans)
		}
	}
}

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

package main

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

var _x = uint(1)

func fastRand() uint {
	_x ^= _x << 13
	_x ^= _x >> 17
	_x ^= _x << 5
	return _x
}

type node struct {
	lr       [2]*node
	priority uint
	key      int
	value    int
}

func (o *node) rotate(d int) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	return x
}

type treap struct {
	root       *node
	comparator func(a, b int) int
}

func newTreap() *treap {
	return &treap{comparator: func(a, b int) int {
		if a < b {
			return 0
		}
		if a > b {
			return 1
		}
		return -1
	}}
}

func (t *treap) _put(o *node, key int) *node {
	if o == nil {
		return &node{priority: fastRand(), key: key, value: 1}
	}
	if cmp := t.comparator(key, o.key); cmp >= 0 {
		o.lr[cmp] = t._put(o.lr[cmp], key)
		if o.lr[cmp].priority > o.priority {
			o = o.rotate(cmp ^ 1)
		}
	} else {
		o.value++
	}
	return o
}

func (t *treap) put(key int) { t.root = t._put(t.root, key) }

func (t *treap) _delete(o *node, key int) *node {
	if o == nil {
		return nil
	}
	if cmp := t.comparator(key, o.key); cmp >= 0 {
		o.lr[cmp] = t._delete(o.lr[cmp], key)
	} else {
		if o.value > 1 {
			o.value--
		} else {
			if o.lr[1] == nil {
				return o.lr[0]
			}
			if o.lr[0] == nil {
				return o.lr[1]
			}
			cmp2 := 0
			if o.lr[0].priority > o.lr[1].priority {
				cmp2 = 1
			}
			o = o.rotate(cmp2)
			o.lr[cmp2] = t._delete(o.lr[cmp2], key)
		}
	}
	return o
}

func (t *treap) delete(key int) { t.root = t._delete(t.root, key) }

func (t *treap) max() int {
	var max *node
	for o := t.root; o != nil; o = o.lr[1] {
		max = o
	}
	return max.key
}

func (t *treap) floor(key int) int {
	var floor *node
	for o := t.root; o != nil; {
		switch cmp := t.comparator(key, o.key); {
		case cmp == 0:
			o = o.lr[0]
		case cmp > 0:
			floor = o
			o = o.lr[1]
		default:
			return o.key
		}
	}
	return floor.key
}

//

func (o *node) String() string {
	var s string
	if o.value == 1 {
		s = Sprintf("%v", o.key)
	} else {
		s = Sprintf("%v(%v)", o.key, o.value)
	}
	return s
}

func (o *node) draw(prefix string, isTail bool, str *string) {
	if o.lr[1] != nil {
		newPrefix := prefix
		if isTail {
			newPrefix += "│   "
		} else {
			newPrefix += "    "
		}
		o.lr[1].draw(newPrefix, false, str)
	}
	*str += prefix
	if isTail {
		*str += "└── "
	} else {
		*str += "┌── "
	}
	*str += o.String() + "\n"
	if o.lr[0] != nil {
		newPrefix := prefix
		if isTail {
			newPrefix += "    "
		} else {
			newPrefix += "│   "
		}
		o.lr[0].draw(newPrefix, true, str)
	}
}

func (t *treap) String() string {
	if t.root == nil {
		return "BST (empty)\n"
	}
	str := "BST\n"
	t.root.draw("", true, &str)
	return str
}

func (t *treap) keys() (keys []int) {
	var o *node
	q := []*node{t.root}
	for len(q) > 0 {
		o, q = q[0], q[1:]
		if o == nil {
			continue
		}
		keys = append(keys, o.key)
		for _, ch := range o.lr {
			q = append(q, ch)
		}
	}
	sort.Ints(keys)
	return
}

// github.com/EndlessCheng/codeforces-go
func Sol706D(reader io.Reader, writer io.Writer) {
	bitLength := func(n int) int {
		c := 1
		if n>>16 > 0 {
			c += 16
			n >>= 16
		}
		if n>>8 > 0 {
			c += 8
			n >>= 8
		}
		if n>>4 > 0 {
			c += 4
			n >>= 4
		}
		if n>>2 > 0 {
			c += 2
			n >>= 2
		}
		if n-1 > 0 {
			c++
		}
		return c
	}
	min := func(a, b int) int {
		if a <= b {
			return a
		}
		return b
	}
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	t := newTreap()
	t.put(0)

	nextFloor := func(bitPos int, floor, x int) (f int, i int) {
		for i = bitPos; i >= 0; i-- {
			ui := uint(i)
			bitFloor := floor >> ui & 1
			bitX := x >> ui & 1
			if bitFloor != bitX {
				continue
			}
			if bitFloor == 1 {
				// mask floor
				check := floor&^(1<<ui) | (1<<ui - 1)
				newFloor := t.floor(check)
				return newFloor, i - 1
			}
		}
		return -1, -1
	}

	var q, x int
	var op string
	for Fscan(in, &q); q > 0; q-- {
		switch Fscan(in, &op, &x); op[0] {
		case '+':
			t.put(x)
		case '-':
			t.delete(x)
		default:
			floor := t.max()
			if floor == 0 {
				Fprintln(out, x)
				continue
			}
			ans := floor ^ x
			fl := bitLength(floor)
			xl := bitLength(x)
			minL := min(fl, xl)
			var newFloor int
			for i := minL - 1; i >= 0; {
				newFloor, i = nextFloor(i, floor, x)
				if floor == -1 {
					break
				}
				if newXor := newFloor ^ x; newXor > ans {
					ans = newXor
					floor = newFloor
				}
			}
			Fprintln(out, ans)
		}
	}
}

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

package main

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

type node struct {
	counter int
	child   [2]*node
}

var root = &node{}

func alloc(pn **node) *node {
	if *pn == nil {
		*pn = &node{}
	}
	return *pn
}

func visitRec(n *node, val uint, mask uint, delta int) {
	n.counter += delta
	if mask == 0 {
		return
	}
	idx := 0
	if val&mask != 0 {
		idx = 1
	}
	visitRec(alloc(&n.child[idx]), val, mask>>1, delta)
}

func add(val uint) {
	visitRec(root, val, 0x80000000, 1)
}

func remove(val uint) {
	visitRec(root, val, 0x80000000, -1)
}

func findRec(n *node, val uint, mask uint) uint {
	if mask == 0 {
		return 0
	}
	idx := 0
	if val&mask != 0 {
		idx = 1
	}
	if n.child[idx] != nil && n.child[idx].counter > 0 {
		return mask + findRec(n.child[idx], val, mask>>1)
	} else {
		return findRec(n.child[1-idx], val, mask>>1)
	}
}

func find(val uint) uint {
	return findRec(root, val, 0x80000000)
}

func main() {
	in := bufio.NewScanner(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	in.Scan()
	entries, _ := strconv.Atoi(in.Text())

	values := make([]uint, 0)
	add(0)

	for i := 0; i < entries; i++ {
		in.Scan()
		sign := in.Text()

		in.Scan()
		x, _ := strconv.Atoi(in.Text())
		value := uint(x)

		switch sign {
		case "+":
			add(value)
		case "-":
			remove(value)
		case "?":
			values = append(values, find(^value))
		}
	}
	for _, x := range values {
		fmt.Printf("%d\n", x)
	}
}

package main

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

type Node struct {
	left *Node
	right *Node
	value int
}

const (
	BYTE_COUNT = 31
)

func (n *Node) Change (numberBytes []int, delta int) {
	if len(numberBytes) == 0 {
		return
	}

	numberByte := numberBytes[0]

	if numberByte == 0 {
		if n.left == nil { n.left = &Node{} }
		n.left.value += delta
		n.left.Change(numberBytes[1:], delta)
	} else {
		if n.right == nil { n.right = &Node{} }
		n.right.value += delta
		n.right.Change(numberBytes[1:], delta)
	}
}

func (n *Node) FindMax (numberBytes []int) []int {
	result := make([]int, 0)
	currentNode := n
	for _, numberByte := range numberBytes {
		if numberByte == 0 {
			if currentNode.right != nil && currentNode.right.value > 0 {
				result = append(result, 1)
				currentNode = currentNode.right
			} else {
				result = append(result, 0)
				currentNode = currentNode.left
			}
		} else {
			if currentNode.left != nil && currentNode.left.value > 0 {
				result = append(result, 1)
				currentNode = currentNode.left
			} else {
				result = append(result, 0)
				currentNode = currentNode.right
			}
		}
	}
	return result
}

func leftPad2Len(s string, padStr string, overallLen int) string {
	var padCountInt int
	padCountInt = 1 + ((overallLen-len(padStr))/len(padStr))
	var retStr = strings.Repeat(padStr, padCountInt) + s
	return retStr[(len(retStr)-overallLen):]
}

func toBytes(x int) []int {
	var err error
	var parsedInt int64
	result := make([]int, 0)
	for _, i := range leftPad2Len(fmt.Sprintf("%b", x), "0", BYTE_COUNT) {
		parsedInt, err = strconv.ParseInt(string(i), 10, 0)
		if err != nil {
			fmt.Println("ANOTHER_ZALUPEHA", err)
		}
		result = append(result, int(parsedInt))
	}
	return result
}

func fromBytes(numberBytes []int) int {
	strs := make([]string, len(numberBytes))
	for idx, numberByte := range numberBytes {
		strs[idx] = strconv.Itoa(numberByte)
	}

	result, err := strconv.ParseInt(strings.Join(strs, ""), 2, 0)
	if err != nil {
		fmt.Println("ZALUPEHA", err)
	}

	return int(result)
}

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}

func getI() int {
  return int(getI64())
}

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

func main()  {
	var (
		q, x int
		command string
	)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	q = getI()

	root := Node{}
	root.Change(toBytes(0), 1)

	for i := 0; i < q; i++ {
		command, x = getS(), getI()

		//fmt.Println(command, x)

		if command == "+" {
			root.Change(toBytes(x), 1)
		} else if command == "-" {
			root.Change(toBytes(x), -1)
		} else {
			fmt.Println(fromBytes(root.FindMax(toBytes(x))))
		}
	}

}

package main

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

type node struct {
	counter int
	child   [2]*node
}

var root = &node{}

func alloc(pn **node) *node {
	if *pn == nil {
		*pn = &node{}
	}
	return *pn
}

func visitRec(n *node, val uint, mask uint, delta int) {
	n.counter += delta
	if mask == 0 {
		return
	}
	idx := 0
	if val&mask != 0 {
		idx = 1
	}
	visitRec(alloc(&n.child[idx]), val, mask>>1, delta)
}

func add(val uint) {
	visitRec(root, val, 0x80000000, 1)
}

func remove(val uint) {
	visitRec(root, val, 0x80000000, -1)
}

func findRec(n *node, val uint, mask uint) uint {
	if mask == 0 {
		return 0
	}
	idx := 0
	if val&mask != 0 {
		idx = 1
	}
	if n.child[idx] != nil && n.child[idx].counter > 0 {
		return mask + findRec(n.child[idx], val, mask>>1)
	} else {
		return findRec(n.child[1-idx], val, mask>>1)
	}
}

func find(val uint) uint {
	return findRec(root, val, 0x80000000)
}

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

	var entries int
	fmt.Fscanf(reader, "%d ", &entries)
	values := make([]uint, 0)
	add(0)

	for i := 0; i < entries; i++ {
		var sign string
		fmt.Fscanf(reader, "%s ", &sign)
		var value uint
		fmt.Fscanf(reader, "%d ", &value)
		switch sign {
		case "+":
			add(value)
		case "-":
			remove(value)
		case "?":
			values = append(values, find(^value))
		}
	}
	for _, x := range values {
		fmt.Printf("%d \n", x)
	}
}

package main

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

type node struct {
	counter int
	child   [2]*node
}

var root = &node{}

func alloc(pn **node) *node {
	if *pn == nil {
		*pn = &node{}
	}
	return *pn
}

func visitRec(n *node, val uint, mask uint, delta int) {
	n.counter += delta
	if mask == 0 {
		return
	}
	idx := 0
	if val&mask != 0 {
		idx = 1
	}
	visitRec(alloc(&n.child[idx]), val, mask>>1, delta)
}

func add(val uint) {
	visitRec(root, val, 0x80000000, 1)
}

func remove(val uint) {
	visitRec(root, val, 0x80000000, -1)
}

func findRec(n *node, val uint, mask uint) uint {
	if mask == 0 {
		return 0
	}
	idx := 0
	if val&mask != 0 {
		idx = 1
	}
	if n.child[idx] != nil && n.child[idx].counter > 0 {
		return mask + findRec(n.child[idx], val, mask>>1)
	} else {
		return findRec(n.child[1-idx], val, mask>>1)
	}
}

func find(val uint) uint {
	return findRec(root, val, 0x80000000)
}

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

	var entries int
	_, _ = fmt.Fscanf(reader, "%d ", &entries)
	values := make([]uint, 0)
	add(0)

	for i := 0; i < entries; i++ {
		var sign string
		_, _ = fmt.Fscanf(reader, "%s ", &sign)
		var value uint
		_, _ = fmt.Fscanf(reader, "%d ", &value)
		switch sign {
		case "+":
			add(value)
		case "-":
			remove(value)
		case "?":
			values = append(values, find(^value))
		}
	}
	for _, x := range values {
		fmt.Printf("%d\n", x)
	}
}

package main

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

type node struct {
	counter int
	child   [2]*node
}

var root = &node{}

func alloc(pn **node) *node {
	if *pn == nil {
		*pn = &node{}
	}
	return *pn
}

func visitRec(n *node, val uint, mask uint, delta int) {
	n.counter += delta
	if mask == 0 {
		return
	}
	idx := 0
	if val&mask != 0 {
		idx = 1
	}
	visitRec(alloc(&n.child[idx]), val, mask>>1, delta)
}

func add(val uint) {
	visitRec(root, val, 0x80000000, 1)
}

func remove(val uint) {
	visitRec(root, val, 0x80000000, -1)
}

func findRec(n *node, val uint, mask uint) uint {
	if mask == 0 {
		return 0
	}
	idx := 0
	if val&mask != 0 {
		idx = 1
	}
	if n.child[idx] != nil && n.child[idx].counter > 0 {
		return mask + findRec(n.child[idx], val, mask>>1)
	} else {
		return findRec(n.child[1-idx], val, mask>>1)
	}
}

func find(val uint) uint {
	return findRec(root, val, 0x80000000)
}

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

	var entries int
	fmt.Fscanf(reader, "%d ", &entries)
	values := make([]uint, 0)
	add(0)

	for i := 0; i < entries; i++ {
		var sign string
		fmt.Fscanf(reader, "%s ", &sign)
		var value uint
		fmt.Fscanf(reader, "%d ", &value)
		switch sign {
		case "+":
			add(value)
		case "-":
			remove(value)
		case "?":
			values = append(values, find(^value))
		}
	}
	for _, x := range values {
		fmt.Printf("%d\n", x)
	}
}

package main

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

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

// Node is a Trie node
type Node struct {
	val   int
	child [2]*Node
}

func create(v int) *Node {
	r := &Node{
		val:   0,
		child: [2]*Node{nil, nil},
	}
	return r
}

func add(x int, i int, node *Node) {
	node.val++
	if i < 0 {
		return
	}
	bit := (x >> uint(i)) & 1
	if node.child[bit] == nil {
		node.child[bit] = create(0)
	}
	add(x, i-1, node.child[bit])
}

func del(x int, i int, node *Node) {
	node.val--
	if i < 0 {
		return
	}
	bit := (x >> uint(i)) & 1
	del(x, i-1, node.child[bit])
}

func query(x int, i int, node *Node, res int) int {
	if i < 0 {
		return res
	}

	bit := (x >> uint(i)) & 1
	rbit := 1 - bit

	if (node.child[rbit] != nil) && (node.child[rbit].val > 0) {
		return query(x, i-1, node.child[rbit], res+(1<<uint(i)))
	}

	if (node.child[bit] != nil) && (node.child[bit].val > 0) {
		return query(x, i-1, node.child[bit], res)
	}

	return -1
}

const maxbit = 30

var n int
var root *Node

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	in.Scan()
	n, _ = strconv.Atoi(in.Text())

	root = create(0)

	for i := 0; i < n; i++ {
		in.Scan()
		c := in.Text()

		in.Scan()
		x, _ := strconv.Atoi(in.Text())

		if c == "+" {
			add(x, maxbit, root)
		} else if c == "-" {
			del(x, maxbit, root)
		} else {
			res := query(x, maxbit, root, 0)
			out.WriteString(strconv.Itoa(res))
			out.WriteByte('\n')
		}
	}
}

package main

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

var _x = uint(1)

func fastRand() uint {
	_x ^= _x << 13
	_x ^= _x >> 17
	_x ^= _x << 5
	return _x
}

type node struct {
	lr    [2]*node
	p     uint
	key   int
	value int
}

func (o *node) rotate(d int) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	return x
}

type treap struct {
	root       *node
	comparator func(a, b int) int
}

func newTreap() *treap {
	return &treap{comparator: func(a, b int) int {
		if a < b {
			return 0
		}
		if a > b {
			return 1
		}
		return -1
	}}
}

func (t *treap) _put(o *node, key int) *node {
	if o == nil {
		return &node{p: fastRand(), key: key, value: 1}
	}
	if cmp := t.comparator(key, o.key); cmp >= 0 {
		o.lr[cmp] = t._put(o.lr[cmp], key)
		if o.lr[cmp].p > o.p {
			o = o.rotate(cmp ^ 1)
		}
	} else {
		o.value++
	}
	return o
}

func (t *treap) put(key int) { t.root = t._put(t.root, key) }

func (t *treap) _delete(o *node, key int) *node {
	if o == nil {
		return nil
	}
	if cmp := t.comparator(key, o.key); cmp >= 0 {
		o.lr[cmp] = t._delete(o.lr[cmp], key)
	} else {
		if o.value > 1 {
			o.value--
		} else {
			if o.lr[1] == nil {
				return o.lr[0]
			}
			if o.lr[0] == nil {
				return o.lr[1]
			}
			cmp2 := 0
			if o.lr[0].p > o.lr[1].p {
				cmp2 = 1
			}
			o = o.rotate(cmp2)
			o.lr[cmp2] = t._delete(o.lr[cmp2], key)
		}
	}
	return o
}

func (t *treap) delete(key int) { t.root = t._delete(t.root, key) }

func (t *treap) max() int {
	var max *node
	for o := t.root; o != nil; o = o.lr[1] {
		max = o
	}
	return max.key
}

func (t *treap) ceiling(key int) int {
	var ceiling *node
	for o := t.root; o != nil; {
		switch cmp := t.comparator(key, o.key); {
		case cmp == 0:
			ceiling = o
			o = o.lr[0]
		case cmp > 0:
			o = o.lr[1]
		default:
			return o.key
		}
	}
	return ceiling.key
}

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

	t := newTreap()
	t.put(0)
	var q, x int
	var op string
	for Fscan(in, &q); q > 0; q-- {
		switch Fscan(in, &op, &x); op[0] {
		case '+':
			t.put(x)
		case '-':
			t.delete(x)
		default:
			mx := t.max()
			mix := 0
			for i := 29; i >= 0; i-- {
				ui := uint(i)
				s1 := 1 << ui &^ x
				if s1 == 0 {
					continue
				}
				mix |= s1
				if mix > mx {
					mix ^= 1 << ui
				} else if up := t.ceiling(mix); up>>ui != mix>>ui {
					mix ^= 1 << ui
				}
			}
			Fprintln(out, mix^x)
		}
	}
}

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

package main

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

var _x = uint(1)

func fastRand() uint {
	_x ^= _x << 13
	_x ^= _x >> 17
	_x ^= _x << 5
	return _x
}

type node struct {
	lr       [2]*node
	priority uint
	key      int
	value    int
}

func (o *node) rotate(d int) *node {
	x := o.lr[d^1]
	o.lr[d^1] = x.lr[d]
	x.lr[d] = o
	return x
}

type treap struct {
	root       *node
	comparator func(a, b int) int
}

func newTreap() *treap {
	return &treap{comparator: func(a, b int) int {
		if a < b {
			return 0
		}
		if a > b {
			return 1
		}
		return -1
	}}
}

func (t *treap) _put(o *node, key int) *node {
	if o == nil {
		return &node{priority: fastRand(), key: key, value: 1}
	}
	if cmp := t.comparator(key, o.key); cmp >= 0 {
		o.lr[cmp] = t._put(o.lr[cmp], key)
		if o.lr[cmp].priority > o.priority {
			o = o.rotate(cmp ^ 1)
		}
	} else {
		o.value++
	}
	return o
}

func (t *treap) put(key int) { t.root = t._put(t.root, key) }

func (t *treap) _delete(o *node, key int) *node {
	if o == nil {
		return nil
	}
	if cmp := t.comparator(key, o.key); cmp >= 0 {
		o.lr[cmp] = t._delete(o.lr[cmp], key)
	} else {
		if o.value > 1 {
			o.value--
		} else {
			if o.lr[1] == nil {
				return o.lr[0]
			}
			if o.lr[0] == nil {
				return o.lr[1]
			}
			cmp2 := 0
			if o.lr[0].priority > o.lr[1].priority {
				cmp2 = 1
			}
			o = o.rotate(cmp2)
			o.lr[cmp2] = t._delete(o.lr[cmp2], key)
		}
	}
	return o
}

func (t *treap) delete(key int) { t.root = t._delete(t.root, key) }

func (t *treap) max() int {
	var max *node
	for o := t.root; o != nil; o = o.lr[1] {
		max = o
	}
	return max.key
}

func (t *treap) floor(key int) int {
	var floor *node
	for o := t.root; o != nil; {
		switch cmp := t.comparator(key, o.key); {
		case cmp == 0:
			o = o.lr[0]
		case cmp > 0:
			floor = o
			o = o.lr[1]
		default:
			return o.key
		}
	}
	if floor == nil {
		return 0
	}
	return floor.key
}

func (t *treap) ceiling(key int) (ceiling *node) {
	for o := t.root; o != nil; {
		switch cmp := t.comparator(key, o.key); {
		case cmp == 0:
			ceiling = o
			o = o.lr[0]
		case cmp > 0:
			o = o.lr[1]
		default:
			return o
		}
	}
	return
}

//

func (o *node) String() string {
	var s string
	if o.value == 1 {
		s = Sprintf("%v", o.key)
	} else {
		s = Sprintf("%v(%v)", o.key, o.value)
	}
	return s
}

func (o *node) draw(prefix string, isTail bool, str *string) {
	if o.lr[1] != nil {
		newPrefix := prefix
		if isTail {
			newPrefix += "│   "
		} else {
			newPrefix += "    "
		}
		o.lr[1].draw(newPrefix, false, str)
	}
	*str += prefix
	if isTail {
		*str += "└── "
	} else {
		*str += "┌── "
	}
	*str += o.String() + "\n"
	if o.lr[0] != nil {
		newPrefix := prefix
		if isTail {
			newPrefix += "    "
		} else {
			newPrefix += "│   "
		}
		o.lr[0].draw(newPrefix, true, str)
	}
}

func (t *treap) String() string {
	if t.root == nil {
		return "BST (empty)\n"
	}
	str := "BST\n"
	t.root.draw("", true, &str)
	return str
}

// github.com/EndlessCheng/codeforces-go
func Sol706D(reader io.Reader, writer io.Writer) {
	bitLength := func(n int) int {
		c := 1
		if n>>16 > 0 {
			c += 16
			n >>= 16
		}
		if n>>8 > 0 {
			c += 8
			n >>= 8
		}
		if n>>4 > 0 {
			c += 4
			n >>= 4
		}
		if n>>2 > 0 {
			c += 2
			n >>= 2
		}
		if n-1 > 0 {
			c++
		}
		return c
	}
	min := func(a, b int) int {
		if a <= b {
			return a
		}
		return b
	}
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	t := newTreap()
	t.put(0)

	nextFloor := func(bitPos int, floor, x int) (f int, i int) {
		for i = bitPos; i >= 0; i-- {
			ui := uint(i)
			bitFloor := floor >> ui & 1
			bitX := x >> ui & 1
			if bitFloor != bitX {
				continue
			}
			if bitFloor == 1 {
				// mask floor
				check := floor&^(1<<ui) | (1<<ui - 1)
				newFloor := t.floor(check)
				return newFloor, i
			}
		}
		return -1, -1
	}

	var q, x int
	var op string
	for Fscan(in, &q); q > 0; q-- {
		switch Fscan(in, &op, &x); op[0] {
		case '+':
			t.put(x)
		case '-':
			t.delete(x)
		default:
			floor := t.max()
			if floor == 0 {
				Fprintln(out, x)
				continue
			}
			ans := floor ^ x
			fl := bitLength(floor)
			xl := bitLength(x)
			minL := min(fl, xl)
			for i := minL - 1; i >= 0; {
				floor, i = nextFloor(i, floor, x)
				if floor == -1 {
					break
				}
				if newXor := floor ^ x; newXor > ans {
					ans = newXor
				}
			}
			Fprintln(out, ans)
		}
	}
}

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


package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n, k := readTwoNums(reader)
	E := make([][]int, n-1)
	for i := 0; i < n-1; i++ {
		E[i] = readNNums(reader, 2)
	}
	res := solve(n, k, E)
	fmt.Println(res)
}

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

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

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

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

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

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

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

	return i
}

const MOD = 998244353

func modAdd(a, b int64) int64 {
	a += b
	a %= MOD
	return a
}

func modMul(a, b int64) int64 {
	a *= b
	a %= MOD
	return a
}

func solve(n, k int, E [][]int) int {
	g := NewGraph(n, len(E)*2)
	for _, e := range E {
		u, v := e[0], e[1]
		g.AddEdge(u-1, v-1)
		g.AddEdge(v-1, u-1)
	}

	dp := make([][]int64, n)
	for i := 0; i < n; i++ {
		dp[i] = make([]int64, n+1)
	}

	var dfs func(p, u int) int

	aux := make([]int64, n+1)

	dfs = func(p, u int) int {
		dp[u][0] = 1
		h := 1
		for i := g.nodes[u]; i > 0; i = g.next[i] {
			v := g.to[i]
			if p == v {
				continue
			}
			vh := dfs(u, v)
			uh := max(h, vh+1)

			for a := 0; a < uh; a++ {
				aux[a] = 0
			}

			for a := 0; a < h; a++ {
				for b := 0; b < vh; b++ {
					if a+b+1 <= k {
						aux[max(a, b+1)] = modAdd(aux[max(a, b+1)], modMul(dp[u][a], dp[v][b]))
					}
					if a <= k && b <= k {
						aux[a] = modAdd(aux[a], modMul(dp[u][a], dp[v][b]))
					}
				}
			}
			h = uh
			for a := 0; a < h; a++ {
				dp[u][a] = aux[a]
			}
		}
		return h
	}
	dfs(-1, 0)

	var res int64
	for i := 0; i <= k; i++ {
		res = modAdd(res, dp[0][i])
	}

	return int(res)
}

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

type Graph struct {
	nodes []int
	next  []int
	to    []int
	cur   int
}

func NewGraph(n int, e int) Graph {
	nodes := make([]int, n)
	next := make([]int, e+3)
	to := make([]int, e+3)
	var cur int
	return Graph{nodes, next, to, cur}
}

func (g *Graph) AddEdge(u, v int) {
	g.cur++
	g.next[g.cur] = g.nodes[u]
	g.nodes[u] = g.cur
	g.to[g.cur] = v
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1499F(_r io.Reader, out io.Writer) {
	const mod = 998244353
	in := bufio.NewReader(_r)
	var n, k, v, w int
	Fscan(in, &n, &k)
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	var f func(v, fa int) []int64
	f = func(v, fa int) []int64 {
		res := []int64{1}
		for _, w := range g[v] {
			if w == fa {
				continue
			}
			r := f(w, v)
			s := int64(0)
			for _, v := range r {
				s += v
			}
			s %= mod
			a := make([]int64, max(len(res), len(r)+1))
			for i, v := range res {
				a[i] = v * s
			}
			for i, v := range res {
				for j, w := range r {
					if i+j >= k {
						break
					}
					a[max(i, j+1)] += v * w % mod
				}
			}
			for i, v := range a {
				a[i] = v % mod
			}
			res = a
		}
		return res
	}
	res := f(0, -1)
	ans := int64(0)
	for _, v := range res {
		ans += v
	}
	Fprint(out, ans%mod)
}

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

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	const P = 998244353
	var n, k, v, w int
	Scan(&n, &k)
	g := make([][]int, n+1)
	for i := 1; i < n; i++ {
		Scan(&v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	var f func(v, p int) []int64
	f = func(v, p int) []int64 {
		res := []int64{1}
		for _, w := range g[v] {
			if w == p {
				continue
			}
			r := f(w, v)
			s := int64(0)
			for _, v := range r {
				s += v
			}
			s %= P
			a := make([]int64, max(len(res), len(r)+1))
			for i, v := range res {
				a[i] = v * s
			}
			for i, v := range res {
				for j, w := range r {
					if i+j >= k {
						break
					}
					a[max(i, j+1)] += v * w % P
				}
			}
			for i, v := range a {
				a[i] = v % P
			}
			res = a
		}
		return res
	}
	s := int64(0)
	for _, v := range f(1, 0) {
		s += v
	}
	Print(s % P)
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"runtime/debug"
)

// github.com/EndlessCheng/codeforces-go
func init() { debug.SetGCPercent(-1) }

func CF1499F(_r io.Reader, out io.Writer) {
	const mod = 998244353
	in := bufio.NewReader(_r)
	var n, k, v, w int
	Fscan(in, &n, &k)
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	var f func(v, fa int) []int64
	f = func(v, fa int) []int64 {
		res := []int64{1}
		for _, w := range g[v] {
			if w == fa {
				continue
			}
			r := f(w, v)
			s := int64(0)
			for _, v := range r {
				s += v
			}
			s %= mod
			a := make([]int64, max(len(res), len(r)+1))
			for i, v := range res {
				a[i] = v * s
			}
			for i, v := range res {
				for j, w := range r {
					if i+j >= k {
						break
					}
					a[max(i, j+1)] += v * w % mod
				}
			}
			for i, v := range a {
				a[i] = v % mod
			}
			res = a
		}
		return res
	}
	res := f(0, -1)
	ans := int64(0)
	for _, v := range res {
		ans += v
	}
	Fprint(out, ans%mod)
}

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

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

package main
import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	const P = 998244353
	var n, k, v, w int
	Scan(&n, &k)
	g := make([][]int, n+1)
	for i := 1; i < n; i++ {
		Scan(&v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	var f func(v, p int) []int64
	f = func(v, p int) []int64 {
		dp := []int64{1}
		for _, w := range g[v] {
			if w == p {
				continue
			}
			r := f(w, v)
			s := int64(0)
			for _, v := range r {
				s += v
			}
			s %= P
			d := make([]int64, max(len(dp), len(r)+1))
			for i, v := range dp {
				d[i] = v * s
			}
			for i, v := range dp {
				for j, w := range r {
					if i+j >= k {
						break
					}
					i = max(i, j+1)
					d[i] = (d[i] + v*w) % P
				}
			}
			dp = d
		}
		return dp
	}
	s := int64(0)
	for _, v := range f(1, 0) {
		s += v
	}
	Print(s % P)
}

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

package main
import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	const P = 998244353
	var n, k, v, w int
	Scan(&n, &k)
	g := make([][]int, n+1)
	for i := 1; i < n; i++ {
		Scan(&v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	var f func(v, p int) []int64
	f = func(v, p int) []int64 {
		dp := []int64{1}
		for _, w = range g[v] {
			if w == p {
				continue
			}
			r := f(w, v)
			s := int64(0)
			for _, v := range r {
				s += v
			}
			s %= P
			d := make([]int64, max(len(dp), len(r)+1))
			for i, v := range dp {
				d[i] = v * s
			}
			for i, v := range dp {
				for j, w := range r {
					if i+j >= k {
						break
					}
					i = max(i, j+1)
					d[i] = (d[i] + v*w) % P
				}
			}
			dp = d
		}
		return dp
	}
	s := int64(0)
	for _, v := range f(1, 0) {
		s += v
	}
	Print(s % P)
}

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