package main

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

func main() {

tc:
	for t := ReadInt(); t > 0; t-- {
		n, d := ReadInt64(), ReadInt64()

		for a := int64(0); a <= n; a++ {
			//if math.Ceil(float64(d)/float64(a))-float64(1) > float64(n) {
			if a +  (d + a) / (a+1) <= n{
				out <- "YES"
				continue tc
			}
		}
		out <- "NO"
	}
	close(out)
	outWg.Wait()
}

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

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	// set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(writer *bufio.Writer) {
		defer outWg.Done()
		defer writer.Flush()

		for line := range out {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

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

func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}

func ReadInt() int64 {
	intStr := ReadString()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func ReadInt64() int64 {
	intStr := ReadString()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ReadInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Max(args ...int64) int64 {
	maxV := int64(math.MinInt64)
	for _, v := range args {
		if v > maxV {
			maxV = v
		}
	}
	return maxV
}

func Min(args ...int64) int64 {
	minV := int64(math.MaxInt64)
	for _, v := range args {
		if v < minV {
			minV = v
		}
	}
	return minV
}

package main

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

const INFINITY = math.MaxInt32/2 - 1

func exec(stdin *Stdin, stdout *Stdout) {
	for t := stdin.ReadInt(); t > 0; t-- {
		n := stdin.ReadInt64()
		d := stdin.ReadInt64()

		ok := false
		for x := int64(0); x*x <= d; x++ {
			if x+CeilDiv64(d, x+1) <= n {
				ok = true
				break
			}
		}

		if ok {
			stdout.Println("YES")
		} else {
			stdout.Println("NO")
		}
	}
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), INFINITY)
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadInt64() int64 {
	n, _ := strconv.ParseInt(s.Read(), 10, 64)
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

func (s *Stdin) ReadIntSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt()
	}
	return a
}

func (s *Stdin) ReadStringSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = s.Read()
	}
	return a
}

func (s *Stdin) ReadFloat64Slice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadFloat64()
	}
	return a
}

func (s *Stdin) ReadInt64Slice(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt64()
	}
	return a
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

func Min(a int, b ...int) int {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max(a int, b ...int) int {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs(x int) int {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func IsPrime(x int) bool {
	if x < 2 {
		return false
	}

	for i := 2; i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm(x, y int) int {
	return x * y / Gcd(x, y)
}

func CeilDiv(x, y int) int {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

func LCS(s, t string) string {
	n := len(s)
	m := len(t)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, m+1)
	}

	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			if s[i-1] == t[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
			}
		}
	}

	x := n
	y := m
	u := make([]byte, dp[n][m])
	i := dp[n][m] - 1
	for x > 0 && y > 0 {
		if dp[x][y] == dp[x-1][y] {
			x--
		} else if dp[x][y] == dp[x][y-1] {
			y--
		} else {
			x--
			y--
			u[i] = s[x]
			i--
		}
	}

	return string(u)
}

// [0..n) から r個選んだ組合せを生成する。
// r < 0 の場合はすべての組合せを生成する。
func Combinations(n int, r int) [][]int {
	a := [][]int{}
	for i := uint(0); i < (1 << uint(n)); i++ {
		b := []int{}
		for j := uint(0); j < uint(n); j++ {
			if i&(uint(1)<<j) != 0 {
				b = append(b, int(j))
			}
		}

		if r < 0 || len(b) == r {
			a = append(a, b)
		}
	}
	return a
}

// [0..n)の順列を生成する。
func Permutations(n int) [][]int {
	type e struct {
		bit uint
		a   []int
	}

	q := []*e{}
	for i := 0; i < n; i++ {
		q = append(q, &e{bit: 1 << uint(i), a: []int{i}})
	}

	p := [][]int{}
	for x := 0; x < len(q); x++ {
		cur := q[x]
		if cur.bit == (1<<uint(n) - 1) {
			p = append(p, cur.a)
			continue
		}

		for i := 0; i < n; i++ {
			if cur.bit&(1<<uint(i)) != 0 {
				continue
			}

			m := len(cur.a) + 1
			b := make([]int, m)
			copy(b, cur.a)
			b[m-1] = i
			q = append(q, &e{bit: cur.bit | (1 << uint(i)), a: b})
		}
	}
	return p
}

func ReverseSlice(v interface{}) {
	if reflect.TypeOf(v).Kind() == reflect.Slice {
		slice := reflect.ValueOf(v)
		for i1, n := 0, slice.Len(); i1 < n/2; i1++ {
			i2 := n - i1 - 1
			v1 := reflect.ValueOf(slice.Index(i1).Interface())
			slice.Index(i1).Set(slice.Index(i2))
			slice.Index(i2).Set(v1)
		}
	}
}

func ReverseString(s string) string {
	t := []rune(s)
	ReverseSlice(t)
	return string(t)
}

func ToStringSlice(slice interface{}) []string {
	// 本来はerrを返却すべき。 利用する側(=自分)は引数がsliceであることを知っている。
	if reflect.TypeOf(slice).Kind() != reflect.Slice {
		panic(fmt.Sprintf("%v is not slice", slice))
	}

	src := reflect.ValueOf(slice)
	n := src.Len()
	dst := make([]string, n)
	for i := 0; i < n; i++ {
		dst[i] = fmt.Sprintf("%v", src.Index(i))
	}
	return dst
}

func CreateMatrix(x, y int) [][]int {
	matrix := make([][]int, x)
	for i := 0; i < x; i++ {
		matrix[i] = make([]int, y)
	}
	return matrix
}

func Min64(a int64, b ...int64) int64 {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max64(a int64, b ...int64) int64 {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs64(x int64) int64 {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow64(x, y int64) int64 {
	z := int64(1)
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y--
		}
	}
	return z
}

func IsPrime64(x int64) bool {
	if x < 2 {
		return false
	}

	for i := int64(2); i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd64(x, y int64) int64 {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm64(x, y int64) int64 {
	return x * y / Gcd64(x, y)
}

func CeilDiv64(x, y int64) int64 {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	//fmt.Println("debug", t)
	for tt := int64(0); tt < t; tt++ {
		n, d := int64(0), int64(0)
		fmt.Fscanf(in, "%d %d\n", &n, &d)
		//fmt.Println("debugwtf", n, d)
		best := d
		for i := int64(1); i <= n && (i-1)*(i-1) <= d; i++ {
			cur := i + (d / (i + 1))
			if d%(i+1) != 0 {
				cur++
			}
			//fmt.Println(i, cur)
			if cur < best {
				best = cur
			}
		}
		if best > n {
			fmt.Fprintf(out, "NO\n")
		} else {
			fmt.Fprintf(out, "YES\n")
		}
	}
	return
}

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

func same(s string, ss string) bool {
	a := make([]int, 26)
	for i := 0; i < len(s); i++ {
		b := int(s[i] - 'a')
		a[b]++
	}
	for i := 0; i < len(ss); i++ {
		b := int(ss[i] - 'a')
		a[b]--
		if a[b] == -1 {
			return false
		}
	}
	for i := 0; i < 26; i++ {
		if a[i] != 0 {
			return false
		}
	}
	return true
}

package main

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

func ceil(n, m int) int {
	return (n + m - 1) / m
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	T := nextInt(sc)
	ans := make([]int, T)
	for i := 0; i < T; i++ {
		n := nextInt(sc)
		d := nextInt(sc)
		if n >= d { // no optimization needed
			ans[i] = 1
		} else {
			// x + ceil(d,x+1) <= n を満たすxがあるかどうか？
			ok, ng := 0, n
			for abs(ok-ng) > 1 {
				mid := (ok + ng) / 2
				// fmt.Printf("ok %d, ng %d, ng %d\n", ok, ng, mid)
				if mid+ceil(d, mid+1) <= n {
					// fmt.Println("found ok", mid)
					ok = mid
				} else {
					ng = mid
				}
			}
			if 0 < ok && ok < n {
				ans[i] = ok
			}
		}
	}
	wtr := bufio.NewWriter(os.Stdout)
	for i := 0; i < T; i++ {
		if ans[i] >= 1 {
			fmt.Fprintln(wtr, "YES")
		} else {
			fmt.Fprintln(wtr, "NO")
		}
	}
	wtr.Flush()
}

package main

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

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return a
}

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

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 {
			fmt.Fprint(wr, " ")
		}
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

var (
	T int
	n int
	d int
)

func main() {
	sc.Split(bufio.ScanWords)
	T = scanInt()
	for cas := 0; cas < T; cas++ {
		n = scanInt()
		d = scanInt()
		ans := d
		for i := 2; i <= 100000; i++ {
			tmp := d / i
			if d%i != 0 {
				tmp++
			}
			tmp += i - 1
			if tmp < ans {
				ans = tmp
			}
		}
		if ans <= n {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func calc_days(d, x int64) int64 {
	return x + int64(math.Ceil(float64(d)/float64(x+1)))
}

func bin_search(n, d, l, r int64) bool {
	if l > r {
		return false
	}
	mid := l + (r-l)/2
	days := calc_days(d, mid)
	if days <= n {
		return true
	}
	return bin_search(n, d, l, mid-1) || bin_search(n, d, mid+1, r)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var t int
	var n, d int64
	fmt.Fscanln(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscanln(reader, &n, &d)
		if d <= n || bin_search(n, d, 1, n-1) {
			fmt.Fprintln(writer, "YES")
			continue
		}
		fmt.Fprintln(writer, "NO")
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"sync"
)
func work() {
	n := ReadInt()
	d := ReadInt()
	Mn := n + 1
	for L, R := 1, 1; L <= d; L = R + 1 {
		R =  d / ( d / L)
		tmp := L - 1 + d / L
		if d % L != 0 {
			tmp++
		}
		Mn = min(Mn, tmp)
	}
	if Mn > n {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}
func main() {
	for i := ReadInt() ; i > 0; i-- {
		work()
	}
	close(out)
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup
func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	i, _ := strconv.ParseInt(intStr, 10, 32)
	return int(i)
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	//set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(write *bufio.Writer) {
		defer outWg.Done()
		defer write.Flush()

		for line := range out {
			write.WriteString(line + "\n")
		}
	}(writer)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i<t; i++{
		var n, d int
		fmt.Scanf("%d %d\n", &n, &d)
		dSqrt := math.Sqrt(float64(d))
		if float64(n) >= math.Ceil(2*dSqrt- 1){
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}

}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1288A(in io.Reader, out io.Writer) {
	var t, n, d int
o:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &d)
		s := int(math.Sqrt(float64(d)))
		for i := s - 10; i < s+10; i++ {
			if i >= 0 && i+(d-1)/(i+1)+1 <= n {
				Fprintln(out, "YES")
				continue o
			}
		}
		Fprintln(out, "NO")
	}
}

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

package main

import (
	. "fmt"
	"math"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	var t, n, d int
o:
	for Scan(&t); t > 0; t-- {
		Scan(&n, &d)
		s := int(math.Sqrt(float64(d)))
		for i := s - 9; i < s+9; i++ {
			if i >= 0 && i+(d-1)/(i+1)+1 <= n {
				Println("YES")
				continue o
			}
		}
		Println("NO")
	}
}

package main

import (
	. "fmt"
	"math"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	var t, n, d int
	for Scan(&t); t > 0; t-- {
		if Scan(&n, &d); n >= int(math.Ceil(2*math.Sqrt(float64(d))-1)) {
			Println("YES")
		} else {
			Println("NO")
		}
	}
}

package main

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

func main() {
	var T int
	fmt.Fscanln(os.Stdin, &T)

	var n, d int
	var found bool
	for i := 0; i < T; i++ {
		fmt.Fscanln(os.Stdin, &n, &d)
		if n >= d {
			fmt.Println("yes")
			continue
		}
		found = false
		for x := 0; x < n; x++ {
			if x + int(math.Ceil(float64(d) / float64(x + 1))) <= n {
				found = true
				break
			}
		}
		if found {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

package main

import "fmt"

func main() {

	//get T
	var T int
	fmt.Scan(&T)

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

		// get input
		var n, d int
		fmt.Scan(&n, &d)

		ok := false
		for x := 0; x < n; x++ {

			if (x+1)*(n-x) >= d {
				ok = true
				break
			}
		}

		if ok {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

package main

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

func main() {

tc:
	for t := ReadInt(); t > 0; t-- {
		n, d := ReadInt64(), ReadInt64()
		//if d <= n {
		//	out <- "YES"
		//	continue
		//}

		for a := n-2; a > 0; a-- {
			if math.Ceil(float64(d)/float64(a))-float64(1) > float64(n) {
				out <- "NO"
				continue tc
			}
		}
		out <- "YES"
	}
	close(out)
	outWg.Wait()
}

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

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	// set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(writer *bufio.Writer) {
		defer outWg.Done()
		defer writer.Flush()

		for line := range out {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

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

func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}

func ReadInt() int64 {
	intStr := ReadString()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func ReadInt64() int64 {
	intStr := ReadString()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ReadInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Max(args ...int64) int64 {
	maxV := int64(math.MinInt64)
	for _, v := range args {
		if v > maxV {
			maxV = v
		}
	}
	return maxV
}

func Min(args ...int64) int64 {
	minV := int64(math.MaxInt64)
	for _, v := range args {
		if v < minV {
			minV = v
		}
	}
	return minV
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	//fmt.Println("debug", t)
	for tt := int64(0); tt < t; tt++ {
		n, d := int64(0), int64(0)
		fmt.Fscanf(in, "%d %d\n", &n, &d)
		//fmt.Println("debugwtf", n, d)
		best := d
		for i := int64(1); i < n; i++ {
			cur := i + (d / (i + 1))
			if d%(i+1) != 0 {
				cur++
			}
			//fmt.Println(i, cur)
			if cur < best {
				best = cur
			} else {
				break
			}
		}
		if best > n {
			fmt.Fprintf(out, "NO\n")
		} else {
			fmt.Fprintf(out, "YES\n")
		}
	}
	return
}

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

func same(s string, ss string) bool {
	a := make([]int, 26)
	for i := 0; i < len(s); i++ {
		b := int(s[i] - 'a')
		a[b]++
	}
	for i := 0; i < len(ss); i++ {
		b := int(ss[i] - 'a')
		a[b]--
		if a[b] == -1 {
			return false
		}
	}
	for i := 0; i < 26; i++ {
		if a[i] != 0 {
			return false
		}
	}
	return true
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, d := 0, 0
		fmt.Fscanf(in, "%d %d\n", &n, &d)
		//fmt.Println(n, d)
		best := d
		for i := 0; i < n; i++ {
			cur := i + (d / (i + 1))
			if d%(i+1) != 0 {
				cur++
			}
			//fmt.Println(i, cur)
			if cur < best {
				best = cur
			} else {
				break
			}
		}
		if best > n {
			fmt.Fprintf(out, "NO\n")
		} else {
			fmt.Fprintf(out, "YES\n")
		}
	}
	return
}

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

func same(s string, ss string) bool {
	a := make([]int, 26)
	for i := 0; i < len(s); i++ {
		b := int(s[i] - 'a')
		a[b]++
	}
	for i := 0; i < len(ss); i++ {
		b := int(ss[i] - 'a')
		a[b]--
		if a[b] == -1 {
			return false
		}
	}
	for i := 0; i < 26; i++ {
		if a[i] != 0 {
			return false
		}
	}
	return true
}

package main

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

func ceil(n, m int) int {
	return (n + m - 1) / m
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	T := nextInt(sc)
	ans := make([]int, T)
	for i := 0; i < T; i++ {
		n := nextInt(sc)
		d := nextInt(sc)
		if n >= d { // no optimization needed
			ans[i] = 1
		} else {
			// x + ceil(d,x+1) <= n を満たすxがあるかどうか？
			left, right := 1, int(1e9)+1
			ok := false
			for right-left > 1 {
				mid := (right + left) / 2
				// fmt.Printf("left %d, mid %d, right %d\n", left, mid, right)
				if ceil(d, mid+1) <= n-mid {
					// fmt.Println("found ok", mid)
					ok = true
					left = mid
				} else {
					right = mid
				}
			}
			if ok {
				ans[i] = left
			}
		}
	}
	wtr := bufio.NewWriter(os.Stdout)
	for i := 0; i < T; i++ {
		if ans[i] >= 1 {
			fmt.Fprintln(wtr, "YES")
		} else {
			fmt.Fprintln(wtr, "NO")
		}
	}
	wtr.Flush()
}

package main

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

func ceil(n, m int) int {
	return (n + m - 1) / m
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	T := nextInt(sc)
	ans := make([]int, T)
	for i := 0; i < T; i++ {
		n := nextInt(sc)
		d := nextInt(sc)
		if n >= d { // no optimization needed
			ans[i] = 1
		} else {
			// x + ceil(d,x+1) <= n を満たすxがあるかどうか？
			left, right := 0, int(1e9)+1
			ok := false
			for right-left > 1 {
				mid := (right + left) / 2
				if ceil(d, mid+1) <= n-mid {
					ok = true
					left = mid
				} else {
					right = mid
				}
			}
			if ok {
				ans[i] = left
			}
		}
	}
	wtr := bufio.NewWriter(os.Stdout)
	for i := 0; i < T; i++ {
		if ans[i] >= 1 {
			fmt.Fprintln(wtr, "YES")
		} else {
			fmt.Fprintln(wtr, "NO")
		}
	}
	wtr.Flush()
}

package main

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

func calc_days(d, x int64) int64 {
	return x + int64(math.Ceil(float64(d)/float64(x+1)))
}

func bin_search(n, d, l, r int64) bool {
	if l > r {
		return false
	}
	mid := l + (r-l)/2
	days := calc_days(d, mid)
	if days <= n {
		return true
	}
	return bin_search(n, d, l, mid-1)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var t int
	var n, d int64
	fmt.Fscanln(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscanln(reader, &n, &d)
		if d <= n || bin_search(n, d, 1, d-1) {
			fmt.Fprintln(writer, "YES")
			continue
		}
		fmt.Fprintln(writer, "NO")
	}
}

package main

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

const limit = 1000000000

func calc_days(d, x int64) int64 {
	return x + int64(math.Ceil(float64(d)/float64(x+1)))
}

func bin_search(n, d, l, r int64) bool {
	if l > r {
		return false
	}
	mid := l + (r-l)/2
	days := calc_days(d, mid)
	if days <= n {
		return true
	}
	return bin_search(n, d, l, mid-1)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var t int
	var n, d int64
	fmt.Fscanln(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscanln(reader, &n, &d)
		if d <= n || bin_search(n, d, 1, limit) {
			fmt.Fprintln(writer, "YES")
			continue
		}
		fmt.Fprintln(writer, "NO")
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for i := 0; i<t; i++{
		var n, d int
		dSqrt := math.Sqrt(float64(d))
		if float64(n) >= math.Ceil(2*dSqrt - 1){
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}

}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for i := 0; i<t; i++{
		var n, d int
		fmt.Scanf("%d %d", &n, &d)
		dSqrt := math.Sqrt(float64(d))
		if float64(n) >= math.Ceil(2*dSqrt- 1){
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}

}

package main

import (
	. "fmt"
	"math"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	var t, n, d int
	for Scan(&t); t > 0; t-- {
		if Scan(&n, &d); n >= int(2*math.Sqrt(float64(d))-1) {
			Println("YES")
		} else {
			Println("NO")
		}
	}
}

package main

import "fmt"

func main() {

	// get input
	var inp int
	fmt.Scan(&inp)

	if inp%2 == 0 && inp > 3 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

const INFINITY = math.MaxInt32/2 - 1

func exec(stdin *Stdin, stdout *Stdout) {
	for t := stdin.ReadInt(); t > 0; t-- {
		n := stdin.ReadInt64()
		d := stdin.ReadInt64()

		x := (d - 1) / 2
		if x+CeilDiv64(d, x+1) <= n {
			stdout.Println("YES")
		} else {
			stdout.Println("NO")
		}
	}
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), INFINITY)
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadInt64() int64 {
	n, _ := strconv.ParseInt(s.Read(), 10, 64)
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

func (s *Stdin) ReadIntSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt()
	}
	return a
}

func (s *Stdin) ReadStringSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = s.Read()
	}
	return a
}

func (s *Stdin) ReadFloat64Slice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadFloat64()
	}
	return a
}

func (s *Stdin) ReadInt64Slice(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt64()
	}
	return a
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

func Min(a int, b ...int) int {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max(a int, b ...int) int {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs(x int) int {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func IsPrime(x int) bool {
	if x < 2 {
		return false
	}

	for i := 2; i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm(x, y int) int {
	return x * y / Gcd(x, y)
}

func CeilDiv(x, y int) int {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

func LCS(s, t string) string {
	n := len(s)
	m := len(t)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, m+1)
	}

	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			if s[i-1] == t[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
			}
		}
	}

	x := n
	y := m
	u := make([]byte, dp[n][m])
	i := dp[n][m] - 1
	for x > 0 && y > 0 {
		if dp[x][y] == dp[x-1][y] {
			x--
		} else if dp[x][y] == dp[x][y-1] {
			y--
		} else {
			x--
			y--
			u[i] = s[x]
			i--
		}
	}

	return string(u)
}

// [0..n) から r個選んだ組合せを生成する。
// r < 0 の場合はすべての組合せを生成する。
func Combinations(n int, r int) [][]int {
	a := [][]int{}
	for i := uint(0); i < (1 << uint(n)); i++ {
		b := []int{}
		for j := uint(0); j < uint(n); j++ {
			if i&(uint(1)<<j) != 0 {
				b = append(b, int(j))
			}
		}

		if r < 0 || len(b) == r {
			a = append(a, b)
		}
	}
	return a
}

// [0..n)の順列を生成する。
func Permutations(n int) [][]int {
	type e struct {
		bit uint
		a   []int
	}

	q := []*e{}
	for i := 0; i < n; i++ {
		q = append(q, &e{bit: 1 << uint(i), a: []int{i}})
	}

	p := [][]int{}
	for x := 0; x < len(q); x++ {
		cur := q[x]
		if cur.bit == (1<<uint(n) - 1) {
			p = append(p, cur.a)
			continue
		}

		for i := 0; i < n; i++ {
			if cur.bit&(1<<uint(i)) != 0 {
				continue
			}

			m := len(cur.a) + 1
			b := make([]int, m)
			copy(b, cur.a)
			b[m-1] = i
			q = append(q, &e{bit: cur.bit | (1 << uint(i)), a: b})
		}
	}
	return p
}

func ReverseSlice(v interface{}) {
	if reflect.TypeOf(v).Kind() == reflect.Slice {
		slice := reflect.ValueOf(v)
		for i1, n := 0, slice.Len(); i1 < n/2; i1++ {
			i2 := n - i1 - 1
			v1 := reflect.ValueOf(slice.Index(i1).Interface())
			slice.Index(i1).Set(slice.Index(i2))
			slice.Index(i2).Set(v1)
		}
	}
}

func ReverseString(s string) string {
	t := []rune(s)
	ReverseSlice(t)
	return string(t)
}

func ToStringSlice(slice interface{}) []string {
	// 本来はerrを返却すべき。 利用する側(=自分)は引数がsliceであることを知っている。
	if reflect.TypeOf(slice).Kind() != reflect.Slice {
		panic(fmt.Sprintf("%v is not slice", slice))
	}

	src := reflect.ValueOf(slice)
	n := src.Len()
	dst := make([]string, n)
	for i := 0; i < n; i++ {
		dst[i] = fmt.Sprintf("%v", src.Index(i))
	}
	return dst
}

func CreateMatrix(x, y int) [][]int {
	matrix := make([][]int, x)
	for i := 0; i < x; i++ {
		matrix[i] = make([]int, y)
	}
	return matrix
}

func Min64(a int64, b ...int64) int64 {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max64(a int64, b ...int64) int64 {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs64(x int64) int64 {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow64(x, y int64) int64 {
	z := int64(1)
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y--
		}
	}
	return z
}

func IsPrime64(x int64) bool {
	if x < 2 {
		return false
	}

	for i := int64(2); i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd64(x, y int64) int64 {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm64(x, y int64) int64 {
	return x * y / Gcd64(x, y)
}

func CeilDiv64(x, y int64) int64 {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}


package main

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

func main() {
	var n int
	var potential []string

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

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

	if s, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		u := re.ReplaceAllString(s, "")
		n, err = strconv.Atoi(u)
		if err != nil {
			return
		}
	}
	fmt.Printf("%s %s\n", potential[0], potential[1])

	for i := 0; i < n; i++ {
		if _in, err := reader.ReadString('\n'); err != nil {
			if err == io.EOF {
				break
			} else {
				return
			}
		} else {
			ab := strings.Split(re.ReplaceAllString(_in, ""), " ")
			if len(ab) != 2 {
				return
			}
			if potential[0] == ab[0] {
				potential[0] = ab[1]
			} else if potential[1] == ab[0] {
				potential[1] = ab[1]
			}
			fmt.Printf("%s %s\n", potential[0], potential[1])
		}
	}
}

package main

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

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

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

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

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

func main() {
	defer w.Flush()
	var n int
	var a, b string
	for I(&a, &b, &n) == nil {
		solve(a, b, n)
	}
}

func solve(a, b string, n int) {
	O(a, " ", b, "\n")
	for i := 0; i < n; i++ {
		var c, d string
		I(&c, &d)
		if a == c {
			a = d
		} else {
			b = d
		}
		O(a, " ", b, "\n")
	}
}

package main

import (
	"fmt"
)

func determine_victims() {
	var name1, name2, name3, name4 string
	var n int

	fmt.Scanln(&name1, &name2)
	fmt.Scanln(&n)

	fmt.Println(name1, name2)

	for i := 0; i<n; i++ {
		fmt.Scanln(&name3, &name4)
		if name1 == name3 {
			name1 = name4
		} else {
			name2 = name4
		}
		fmt.Println(name1, name2)
	}
}

func main() {
	determine_victims()
}

package main

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

func solve() {
	mm := make(map[string]bool)
	mm[readString()] = true
	mm[readString()] = true
	printPeople(mm)
	n := readInt()
	for i := 0; i < n; i++ {
		p1 := readString()
		delete(mm, p1)
		mm[readString()] = true
		printPeople(mm)
	}
}

func printPeople(mm map[string]bool) {
	res := ""
	for k, _ := range mm {
		if res == "" {
			res = k
		} else {
			res += " " + k
		}
	}
	fmt.Println(res)
}

var scanner *bufio.Scanner

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

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

// 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 readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main

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

func main() {
	cin := NewParser(bufio.NewReaderSize(os.Stdin, 1<<16))
	a := cin.nextString()
	b := cin.nextString()
	fmt.Printf("%s %s\n", a, b)
	n := cin.nextInt()
	for i := 0; i < n; i++ {
		c := cin.nextString()
		d := cin.nextString()
		if c == a || c == b {
			if c == a {
				a = d
			} else {
				b = d
			}
		} else if d == a || d == b {
			if d == a {
				a = c
			} else {
				b = c
			}
		} else {
			panic("bad input")
		}
		fmt.Printf("%s %s\n", a, b)
	}
}

// some io

type ParserReader struct {
	r   io.ByteReader
	err error
	c   byte
}

func NewParser(r io.ByteReader) *ParserReader {
	return &ParserReader{r, nil, 0}
}

func (p *ParserReader) next() error {
	p.c, p.err = p.r.ReadByte()
	return p.err
}

func isDigit(c byte) bool {
	return '0' <= c && c <= '9'
}

func (p *ParserReader) nextUInt64() uint64 {
	for !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var r uint64
	for isDigit(p.c) && p.err == nil {
		r = r*10 + uint64(p.c-'0')
		p.next()
	}
	return r
}

func (p *ParserReader) nextUInt() uint {
	for !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var r uint
	for isDigit(p.c) && p.err == nil {
		r = r*10 + uint(p.c-'0')
		p.next()
	}
	return r
}

func (p *ParserReader) nextInt64() int64 {
	for p.c != '-' && !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var sign bool
	if p.c == '-' {
		sign = true
	}
	r := int64(p.nextUInt64())
	if sign {
		return -r
	}
	return r
}

func (p *ParserReader) nextInt() int {
	for p.c != '-' && !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var sign bool
	if p.c == '-' {
		sign = true
	}
	r := int(p.nextUInt())
	if sign {
		return -r
	}
	return r
}

func isSpace(c byte) bool {
	return c < 32 || c == ' ' || c == '\n' || c == '\t'
}

func (p *ParserReader) nextString() string {
	for isSpace(p.c) && p.err == nil {
		p.next()
	}
	r := make([]byte, 0, 1)
	for !isSpace(p.c) && p.err == nil {
		r = append(r, p.c)
		p.next()
	}
	return string(r)
}

package main

import (
	"fmt"
)

func main() {
	var arr, arrTmp [2]string
	var testcount int
	fmt.Scanf("%s %s\n", &arr[0], &arr[1])
	fmt.Scanf("%d\n", &testcount)
	for i := 0; i < testcount; i++ {
		fmt.Printf("%s %s\n", arr[0], arr[1])
		fmt.Scanf("%s %s\n", &arrTmp[0], &arrTmp[1])
		if arrTmp[0] == arr[0] {
			arr[0] = arrTmp[1]
		} else {
			arr[1] = arrTmp[1]
		}
	}
	fmt.Printf("%s %s\n", arr[0], arr[1])
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	line, _ := reader.ReadString('\n')
	arr := strings.Split(strings.TrimSpace(line), " ")
	line, _ = reader.ReadString('\n')
	testcount, _ := strconv.Atoi(strings.TrimSpace(line))
	for i := 0; i < testcount; i++ {
		writer.WriteString(arr[0] + " " + arr[1] + "\n")
		line, _ = reader.ReadString('\n')
		tmp := strings.Split(strings.TrimSpace(line), " ")
		if tmp[0] == arr[0] {
			arr[0] = tmp[1]
		} else {
			arr[1] = tmp[1]
		}
	}
	writer.WriteString(arr[0] + " " + arr[1] + "\n")
	writer.Flush()
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	arr := strings.Split(strings.TrimSpace(line), " ")
	line, _ = reader.ReadString('\n')
	testcount, _ := strconv.Atoi(strings.TrimSpace(line))
	for i := 0; i < testcount; i++ {
		fmt.Printf("%s %s\n", arr[0], arr[1])
		line, _ = reader.ReadString('\n')
		tmp := strings.Split(strings.TrimSpace(line), " ")
		if tmp[0] == arr[0] {
			arr[0] = tmp[1]
		} else {
			arr[1] = tmp[1]
		}
	}
	fmt.Printf("%s %s\n", arr[0], arr[1])
}

package main

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

func main() {
	sc := NewScanner()
	A, B := sc.Next(), sc.Next()
	N := sc.NextInt()
	fmt.Println(A, B)
	for i := 0; i < N; i++ {
		C, D := sc.Next(), sc.Next()
		if A == C {
			A = D
		} else {
			B = D
		}
		fmt.Println(A, B)
	}

}

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

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

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

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

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

	return mp
}

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

package main

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

func main() {
	f, _ := os.Open("a.in")
	cin := NewParser(bufio.NewReaderSize(f, 1<<16))
	// cin := NewParser(bufio.NewReaderSize(os.Stdin, 1<<16))
	a := cin.nextString()
	b := cin.nextString()
	fmt.Printf("%s %s\n", a, b)
	n := cin.nextInt()
	for i := 0; i < n; i++ {
		c := cin.nextString()
		d := cin.nextString()
		if c == a || c == b {
			if c == a {
				a = d
			} else {
				b = d
			}
		} else if d == a || d == b {
			if d == a {
				a = c
			} else {
				b = c
			}
		} else {
			panic("bad input")
		}
		fmt.Printf("%s %s\n", a, b)
	}
}

// some io

type ParserReader struct {
	r   io.ByteReader
	err error
	c   byte
}

func NewParser(r io.ByteReader) *ParserReader {
	return &ParserReader{r, nil, 0}
}

func (p *ParserReader) next() error {
	p.c, p.err = p.r.ReadByte()
	return p.err
}

func isDigit(c byte) bool {
	return '0' <= c && c <= '9'
}

func (p *ParserReader) nextUInt64() uint64 {
	for !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var r uint64
	for isDigit(p.c) && p.err == nil {
		r = r*10 + uint64(p.c-'0')
		p.next()
	}
	return r
}

func (p *ParserReader) nextUInt() uint {
	for !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var r uint
	for isDigit(p.c) && p.err == nil {
		r = r*10 + uint(p.c-'0')
		p.next()
	}
	return r
}

func (p *ParserReader) nextInt64() int64 {
	for p.c != '-' && !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var sign bool
	if p.c == '-' {
		sign = true
	}
	r := int64(p.nextUInt64())
	if sign {
		return -r
	}
	return r
}

func (p *ParserReader) nextInt() int {
	for p.c != '-' && !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var sign bool
	if p.c == '-' {
		sign = true
	}
	r := int(p.nextUInt())
	if sign {
		return -r
	}
	return r
}

func isSpace(c byte) bool {
	return c < 32 || c == ' ' || c == '\n' || c == '\t'
}

func (p *ParserReader) nextString() string {
	for isSpace(p.c) && p.err == nil {
		p.next()
	}
	r := make([]byte, 0, 1)
	for !isSpace(p.c) && p.err == nil {
		r = append(r, p.c)
		p.next()
	}
	return string(r)
}


package main

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

func main() {
	start := time.Now()
	defer func() {
		run := time.Since(start)
		_ = run
		// fmt.Println("Run in", run)
	}()

	var stdin *bufio.Reader
	// LOCAL
	f, _ := os.Open("input.txt")
	stdin = bufio.NewReader(f)

	// ONLINE JUDGE
	stdin = bufio.NewReader(os.Stdin)

	var n, x, y int
	fmt.Fscan(stdin, &n, &x, &y)

	var a = make([]int, n)
	var cnt = 0
	for i := 0; i < n; i++ {
		fmt.Fscan(stdin, &a[i])
		if a[i] <= x {
			cnt++
		}
	}

	if x > y {
		fmt.Println(n)
	} else {
		fmt.Println((cnt + 1) / 2)
	}
}

package main

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

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

func ReadInt() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}

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

    n := ReadInt()
    x := ReadInt()
    y := ReadInt()

    v := make([]int, n)

    for i := 0; i < n; i++ {
    	v[i] = ReadInt()
    }

    if x > y {
    	writer.WriteString(strconv.Itoa(n))
    	return
    }

    resp := 0

    for i := 0; i < n; i++ {
    	if v[i] <= x {
    		resp++
    	}
    }

    if resp % 2 != 0 {
    	resp++
    }

	writer.WriteString(strconv.Itoa(resp/2))
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

func init() {
	scanner.Split(bufio.ScanWords)
}

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

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

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

func scanInt() int {
	scanner.Scan()
	v, _ := strconv.Atoi(scanner.Text())
	return v
}

func scanInts(n int) []int {
	l := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		l[i], _ = strconv.Atoi(scanner.Text())
	}

	return l
}

func scanInts64(n int64) []int64 {
	l := make([]int64, n)
	for i := int64(0); i < n; i++ {
		scanner.Scan()
		l[i], _ = strconv.ParseInt(scanner.Text(), 10, 64)
	}

	return l
}

func scanBool() bool {
	scanner.Scan()
	v, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return v == 1
}

func scanBools(n int64) []bool {
	l := make([]bool, n)
	for i := int64(0); i < n; i++ {
		scanner.Scan()
		v, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		l[i] = v == 1
	}

	return l
}

func scanUint64() uint64 {
	scanner.Scan()
	v, _ := strconv.ParseUint(scanner.Text(), 10, 64)
	return v
}

type ByAge []uint64

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

func main() {
	n, x, y := scanInt(), scanInt(), scanInt()

	a := scanInts(n)

	if x > y {
		fmt.Println(n)
		return
	}

	cnt := 0
	for i := 0; i < n; i++ {
		if a[i] <= x {
			cnt++
		}
	}

	cnt = int(math.Ceil(float64(cnt) / 2.0))
	fmt.Println(cnt)
}

func skipZero(a []uint64) []uint64 {
	for len(a) > 0 && a[0] == 0 {
		a = a[1:]
	}

	return a
}

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}

	return -a
}

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

	return b
}

package main

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

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n ,x,y int
	fmt.Fscanf(buf, "%d %d %d\n", &n,&x,&y)
	var cnt int=0
	for i:= 0;i < n;i++{
		var v int
		fmt.Fscanf(buf, "%d", &v)
		if v <= x{
			cnt++
		}
	}
	if x > y{
		fmt.Printf("%d\n", n)
	}else if x == y{
		fmt.Printf("%d\n", (cnt+1)/2)
	}else{
		fmt.Printf("%d\n", (cnt+1)/2)
	}

}


package main

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

func main(){
	var s string
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	s = r.Text()
	len := len(s)
	mark := 0
	n, m := 0, 0
	num := make([]int, 1010)
	for i:=0; i<len; i++ {
		if string(s[i]) == "." {
			mark = i
			n = int(s[i-1])-'0'
			m = int(s[i+1])-'0'
		}
	}
	for i:=mark-1; i>=0; i-- {
		num[i] = int(s[i]) - '0'
	}
	if n == 9 {
		w.WriteString("GOTO Vasilisa.\n")
	} else if m < 5 {
		for i:=0; i<mark; i++ {
			w.WriteString(string(s[i]))
		}
		w.WriteString("\n")
	} else if m >= 5 {
		num[mark-1] += 1
		for i:=mark-1; i>=0; i-- {
			if num[i]>=10 && i!= 0 {
				num[i] -= 10
				num[i-1] += 1
			}
		}
		for i:=0; i<=mark-1; i++ {
			w.WriteString(strconv.Itoa(num[i]))
		}
		w.WriteString("\n")
	}
	w.Flush()
}

package main

import "fmt"

func main() {
    var s string
    fmt.Scan(&s)
    prev, next := make([]int,0,len(s)), 0
    for k, v := range s {
        if v == '.' {
            next = int(s[k+1]-'0')
            break
        }
        prev = append(prev,int(v-'0'))
    }
    if prev[len(prev)-1] == 9 {
        fmt.Println("GOTO Vasilisa.")
    } else {
        if next >= 5 { prev[len(prev)-1]++ }
        for _, v := range prev {
            fmt.Print(v)
        }
        fmt.Println()
    }
}

// 99A-mic_rizal
package main

import (
    "fmt"
    "strconv"
)

func main() {
    var str string
    var in int
    fmt.Scan(&str)
    l := len(str)
    for i := 0; i < l-1; i++ {
        if str[i] == '.' {
            in = i
            break
        }
    }
    m, _ := strconv.Atoi(string(str[in+1]))
    if str[in-1] == '9' {
        fmt.Println("GOTO Vasilisa.")
        return
    } else if m >= 5 {
        for i := 0; i < l-2; i++ {
            if str[i+1] == '.' {
                a, _ := strconv.Atoi(string(str[i]))
                fmt.Print(a + 1)
                break
            } else {
                if str[i] != '.' {
                    fmt.Print(string(str[i]))
                }
            }
        }
        fmt.Println()
    } else {
        for i := 0; i < l-1; i++ {
            if str[i] == '.' {
                break
            }
            fmt.Print(string(str[i]))
        }
        fmt.Println()
        return
    }
}

package main

import "fmt"

func main() {
    var s string
    fmt.Scan(&s)
    prev, next := make([]int,0,len(s)), 0
    for k, v := range s {
        if v == '.' {
            next = int(s[k+1]-'0')
            break
        }
        prev = append(prev,int(v-'0'))
    }
    if prev[len(prev)-1] == 9 {
        fmt.Println("GOTO Vasilisa")
    } else {
        if next >= 5 { prev[len(prev)-1]++ }
        for _, v := range prev {
            fmt.Print(v)
        }
        fmt.Println()
    }
}

package main

import "fmt"

func main() {
    var s string
    var prev,next int
    fmt.Scan(&s)
    for k, v := range s {
        if v == '.' {
            prev = int(s[k-1]-'0')
            next = int(s[k+1]-'0')
            break
        }
    }
    if prev == 9 {
        fmt.Println("GOTO Vasilisa")
    } else if next < 5 {
        fmt.Println(prev)
    } else {
        fmt.Println(prev+1)
    }
}

package main

import "fmt"

func main() {
    var s string
    fmt.Scan(&s)
    prev, next := 0, 0
    for k, v := range s {
        if v == '.' {
            next = int(s[k+1]-'0')
            break
        }
        prev = (prev*10)+int(v-'0')
    }
    if prev%10 == 9 {
        fmt.Println("GOTO Vasilisa")
    } else if next < 5 {
        fmt.Println(prev)
    } else {
        fmt.Println(prev+1)
    }
}

// 99A-mic_rizal
package main

import (
    "fmt"
    "strconv"
)

func main() {
    var str string
    var in int
    fmt.Scan(&str)
    l := len(str)
    for i := 0; i < l-1; i++ {
        if str[i] == '.' {
            in = i
            break
        }
    }
    m, _ := strconv.Atoi(string(str[in+1]))
    if str[in-1] == '9' {
        fmt.Println("GOTO Vasilisa.")
        return
    } else if m >= 5 {
        for i := 0; i < l-2; i++ {
            if str[i+1] == '.' {
                a, _ := strconv.Atoi(string(str[i]))
                fmt.Print(a + 1)
            } else {
                if str[i] != '.' {
                    fmt.Print(string(str[i]))
                }
            }
        }
        fmt.Println()
    } else {
        for i := 0; i < l-1; i++ {
            if str[i] == '.' {
                break
            }
            fmt.Print(string(str[i]))
        }
        fmt.Println()
        return
    }
}

// 99A-mic_rizal
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var str string
	var in int
	fmt.Scan(&str)
	l := len(str)
	for i := 0; i < l-1; i++ {
		if str[i] == '.' {
			in = i
			break
		}
	}
	m, _ := strconv.Atoi(string(str[in+1]))
	if str[in-1] == '9' {
		fmt.Println("GOTO Vasilisa.")
		return
	} else if m >= 5 {
		a, _ := strconv.ParseFloat(str, 0)
		fmt.Println(int(a) + 1)
		return
	} else {
		for i := 0; i < l-1; i++ {
			if str[i] == '.' {
				break
			}
			fmt.Print(string(str[i]))
		}
		fmt.Println()
		return
	}
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF766E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, v, w int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	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)
	}

	ans := int64(0)
	var f func(v, fa int) [20][2]int
	f = func(v, fa int) (cnt [20][2]int) {
		av := a[v]
		ans += int64(av)
		for i := 0; i < 20; i++ {
			cnt[i][av>>i&1]++
		}
		for _, w := range g[v] {
			if w != fa {
				c := f(w, v)
				for i, p := range c[:] {
					ans += (int64(cnt[i][0])*int64(p[1]) + int64(cnt[i][1])*int64(p[0])) * int64(1<<i)
					cnt[i][av>>i&1] += p[0]
					cnt[i][av>>i&1^1] += p[1]
				}
			}
		}
		return
	}
	f(0, -1)
	Fprint(out, ans)
}

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

package main

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

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

	var n, v, w int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	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)
	}

	ans := int64(0)
	var f func(v, fa int) [20][2]int
	f = func(v, fa int) (cnt [20][2]int) {
		av := a[v]
		ans += int64(av)
		for i := 0; i < 20; i++ {
			cnt[i][av>>i&1]++
		}
		for _, w := range g[v] {
			if w != fa {
				for i, p := range f(w, v) {
					ans += (int64(cnt[i][0])*int64(p[1]) + int64(cnt[i][1])*int64(p[0])) * int64(1<<i)
					cnt[i][av>>i&1] += p[0]
					cnt[i][av>>i&1^1] += p[1]
				}
			}
		}
		return
	}
	f(0, -1)
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF766E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, v, w int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	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)
	}

	ans := int64(0)
	var f func(v, fa int) [20][2]int
	f = func(v, fa int) (cnt [20][2]int) {
		av := a[v]
		ans += int64(av)
		for i := 0; i < 20; i++ {
			cnt[i][av>>i&1] = 1
		}
		for _, w := range g[v] {
			if w != fa {
				for i, p := range f(w, v) {
					ans += (int64(cnt[i][0])*int64(p[1]) + int64(cnt[i][1])*int64(p[0])) * int64(1<<i)
					cnt[i][av>>i&1] += p[0]
					cnt[i][av>>i&1^1] += p[1]
				}
			}
		}
		return
	}
	f(0, -1)
	Fprint(out, ans)
}

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

package main

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

var stdReader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() (result int) {
	var negative, started bool
READER_LOOP:
	for {
		char, err := stdReader.ReadByte()
		switch {
		case err != nil:
			break READER_LOOP
		case char == '-':
			negative = true
		case unicode.IsDigit(rune(char)):
			started = true
			result = result*10 + int(char&0xf)
		case started:
			break READER_LOOP
		}
	}
	if negative {
		result = -result
	}
	return
}

const bits = 30

type value struct {
	zeros, ones int
}

var kick, next, dest []int

var adjacent, saturation []int

var original [][bits]bool

var node [][bits]value

var edge []*[bits]value

func maybePush(v, u, e int) {
	if edge[e] != nil {
		return
	}
	if adjacent[v] == saturation[v] {
		// substract and push
		edge[e] = new([bits]value)
		for b := 0; b < bits; b++ {
			push := node[v][b]
			if original[v][b] {
				push.zeros -= edge[e^1][b].zeros
				push.ones -= edge[e^1][b].ones
			} else {
				push.zeros -= edge[e^1][b].ones
				push.ones -= edge[e^1][b].zeros
			}
			edge[e][b] = push
			if original[u][b] {
				node[u][b].zeros += push.zeros
				node[u][b].ones += push.ones
			} else {
				node[u][b].zeros += push.ones
				node[u][b].ones += push.zeros
			}
		}
		saturation[u]++
	} else if adjacent[v] == saturation[v]+1 && edge[e^1] == nil {
		// push as is
		edge[e] = new([bits]value)
		for b := 0; b < bits; b++ {
			edge[e][b] = node[v][b]
			if original[u][b] {
				node[u][b].zeros += node[v][b].zeros
				node[u][b].ones += node[v][b].ones
			} else {
				node[u][b].zeros += node[v][b].ones
				node[u][b].ones += node[v][b].zeros
			}
		}
		saturation[u]++
	}
}

func dfs(v, p int) {
	var pe int
	for e := kick[v]; e >= 0; e = next[e] {
		u := dest[e]
		maybePush(v, u, e)
		if u == p {
			pe = e
		} else {
			dfs(u, v)
		}
	}
	if p >= 0 {
		maybePush(v, p, pe)
	}
}

func main() {
	n := readInt()
	node = make([][bits]value, n)
	edge = make([]*[bits]value, (n-1)*2)
	original = make([][bits]bool, n)
	for i := range node {
		a := readInt()
		for j := range node[i] {
			original[i][j] = a%2 == 0
			node[i][j] = value{
				zeros: 1 - a%2,
				ones:  a % 2,
			}
			a /= 2
		}
	}
	kick = make([]int, n)
	for i := range kick {
		kick[i] = -1
	}
	next = make([]int, (n-1)*2)
	dest = make([]int, (n-1)*2)
	adjacent = make([]int, n)
	saturation = make([]int, n)
	for i := 0; i < n-1; i++ {
		a, b := readInt()-1, readInt()-1
		adjacent[a]++
		adjacent[b]++

		// edge i * 2: a -> b
		next[i*2] = kick[a]
		dest[i*2] = b
		kick[a] = i * 2

		// edge i * 2 + 1: b -> a
		next[i*2+1] = kick[b]
		dest[i*2+1] = a
		kick[b] = i*2 + 1
	}

	dfs(0, -1)
	dfs(0, -1)

	for e := range edge {
		if edge[e] == nil {
			panic("Edge can't be nil")
		}
	}

	var total int64
	for b := 0; b < bits; b++ {
		var single, double int64
		for i := 0; i < n; i++ {
			if original[i][b] {
				double += int64(node[i][b].ones)
			} else {
				double += int64(node[i][b].ones - 1)
				single++
			}
		}
		total += (int64(1) << uint32(b)) * int64(single+double/2)
	}
	fmt.Println(total)
}

package main

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

var stdReader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() (result int) {
	var negative, started bool
READER_LOOP:
	for {
		char, err := stdReader.ReadByte()
		switch {
		case err != nil:
			break READER_LOOP
		case char == '-':
			negative = true
		case unicode.IsDigit(rune(char)):
			started = true
			result = result*10 + int(char&0xf)
		case started:
			break READER_LOOP
		}
	}
	if negative {
		result = -result
	}
	return
}

const bits = 21

type value struct {
	zeros, ones int
}

var kick, next, dest []int

var adjacent, saturation []int

var original [][bits]bool

var node [][bits]value

var edge []*[bits]value

func maybePush(v, u, e int) {
	if edge[e] != nil {
		return
	}
	if adjacent[v] == saturation[v] {
		// substract and push
		edge[e] = new([bits]value)
		for b := 0; b < bits; b++ {
			push := node[v][b]
			if original[v][b] {
				push.zeros -= edge[e^1][b].zeros
				push.ones -= edge[e^1][b].ones
			} else {
				push.zeros -= edge[e^1][b].ones
				push.ones -= edge[e^1][b].zeros
			}
			edge[e][b] = push
			if original[u][b] {
				node[u][b].zeros += push.zeros
				node[u][b].ones += push.ones
			} else {
				node[u][b].zeros += push.ones
				node[u][b].ones += push.zeros
			}
		}
		saturation[u]++
	} else if adjacent[v] == saturation[v]+1 && edge[e^1] == nil {
		// push as is
		edge[e] = new([bits]value)
		for b := 0; b < bits; b++ {
			edge[e][b] = node[v][b]
			if original[u][b] {
				node[u][b].zeros += node[v][b].zeros
				node[u][b].ones += node[v][b].ones
			} else {
				node[u][b].zeros += node[v][b].ones
				node[u][b].ones += node[v][b].zeros
			}
		}
		saturation[u]++
	}
}

func dfs(v, p int) {
	var pe int
	for e := kick[v]; e >= 0; e = next[e] {
		u := dest[e]
		maybePush(v, u, e)
		if u == p {
			pe = e
		} else {
			dfs(u, v)
		}
	}
	if p >= 0 {
		maybePush(v, p, pe)
	}
}

func main() {
	n := readInt()
	node = make([][bits]value, n)
	edge = make([]*[bits]value, (n-1)*2)
	original = make([][bits]bool, n)
	for i := range node {
		a := readInt()
		for j := range node[i] {
			original[i][j] = a%2 == 0
			node[i][j] = value{
				zeros: 1 - a%2,
				ones:  a % 2,
			}
			a /= 2
		}
	}
	kick = make([]int, n)
	for i := range kick {
		kick[i] = -1
	}
	next = make([]int, (n-1)*2)
	dest = make([]int, (n-1)*2)
	adjacent = make([]int, n)
	saturation = make([]int, n)
	for i := 0; i < n-1; i++ {
		a, b := readInt()-1, readInt()-1
		adjacent[a]++
		adjacent[b]++

		// edge i * 2: a -> b
		next[i*2] = kick[a]
		dest[i*2] = b
		kick[a] = i * 2

		// edge i * 2 + 1: b -> a
		next[i*2+1] = kick[b]
		dest[i*2+1] = a
		kick[b] = i*2 + 1
	}

	dfs(0, -1)
	dfs(0, -1)

	var total int64
	for b := 0; b < bits; b++ {
		var single, double int64
		for i := 0; i < n; i++ {
			if original[i][b] {
				double += int64(node[i][b].ones)
			} else {
				double += int64(node[i][b].ones - 1)
				single++
			}
		}
		total += (int64(1) << uint32(b)) * int64(single+double/2)
	}
	fmt.Println(total)
}

package main

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

var stdReader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() (result int) {
	var negative, started bool
READER_LOOP:
	for {
		char, err := stdReader.ReadByte()
		switch {
		case err != nil:
			break READER_LOOP
		case char == '-':
			negative = true
		case unicode.IsDigit(rune(char)):
			started = true
			result = result*10 + int(char&0xf)
		case started:
			break READER_LOOP
		}
	}
	if negative {
		result = -result
	}
	return
}

const bits = 30

type value struct {
	zeros, ones int
}

var kick, next, dest []int

var adjacent, saturation []int

var original [][bits]bool

var node [][bits]value

var edge []*[bits]value

func maybePush(v, u, e int) {
	if edge[e] != nil {
		return
	}
	if adjacent[v] == saturation[v] {
		// substract and push
		edge[e] = new([bits]value)
		for b := 0; b < bits; b++ {
			push := node[v][b]
			if original[v][b] {
				push.zeros -= edge[e^1][b].zeros
				push.ones -= edge[e^1][b].ones
			} else {
				push.zeros -= edge[e^1][b].ones
				push.ones -= edge[e^1][b].zeros
			}
			edge[e][b] = push
			if original[u][b] {
				node[u][b].zeros += push.zeros
				node[u][b].ones += push.ones
			} else {
				node[u][b].zeros += push.ones
				node[u][b].ones += push.zeros
			}
		}
		saturation[u]++
	} else if adjacent[v] == saturation[v]+1 && edge[e^1] == nil {
		// push as is
		edge[e] = new([bits]value)
		for b := 0; b < bits; b++ {
			edge[e][b] = node[v][b]
			if original[u][b] {
				node[u][b].zeros += node[v][b].zeros
				node[u][b].ones += node[v][b].ones
			} else {
				node[u][b].zeros += node[v][b].ones
				node[u][b].ones += node[v][b].zeros
			}
		}
		saturation[u]++
	}
}

func dfs(v, p int) {
	var pe int
	for e := kick[v]; e >= 0; e = next[e] {
		u := dest[e]
		maybePush(v, u, e)
		if u == p {
			pe = e
		} else {
			dfs(u, v)
		}
	}
	if p >= 0 {
		maybePush(v, p, pe)
	}
}

func main() {
	n := readInt()
	node = make([][bits]value, n)
	edge = make([]*[bits]value, (n-1)*2)
	original = make([][bits]bool, n)
	for i := range node {
		a := readInt()
		for j := range node[i] {
			original[i][j] = a%2 == 0
			node[i][j] = value{
				zeros: 1 - a%2,
				ones:  a % 2,
			}
			a /= 2
		}
	}
	kick = make([]int, n)
	for i := range kick {
		kick[i] = -1
	}
	next = make([]int, (n-1)*2)
	dest = make([]int, (n-1)*2)
	adjacent = make([]int, n)
	saturation = make([]int, n)
	for i := 0; i < n-1; i++ {
		a, b := readInt()-1, readInt()-1
		adjacent[a]++
		adjacent[b]++

		// edge i * 2: a -> b
		next[i*2] = kick[a]
		dest[i*2] = b
		kick[a] = i * 2

		// edge i * 2 + 1: b -> a
		next[i*2+1] = kick[b]
		dest[i*2+1] = a
		kick[b] = i*2 + 1
	}

	dfs(0, -1)
	dfs(0, -1)

	var total int64
	for b := 0; b < bits; b++ {
		var single, double int
		for i := 0; i < n; i++ {
			if original[i][b] {
				double += node[i][b].ones
			} else {
				double += node[i][b].ones - 1
				single++
			}
		}
		total += (int64(1) << uint32(b)) * int64(single+double/2)
	}
	fmt.Println(total)
}

package main

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

var stdReader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() (result int) {
	var negative, started bool
READER_LOOP:
	for {
		char, err := stdReader.ReadByte()
		switch {
		case err != nil:
			break READER_LOOP
		case char == '-':
			negative = true
		case unicode.IsDigit(rune(char)):
			started = true
			result = result*10 + int(char&0xf)
		case started:
			break READER_LOOP
		}
	}
	if negative {
		result = -result
	}
	return
}

const bits = 30

type value struct {
	zeros, ones int
}

var kick, next, dest []int

var adjacent, saturation []int

var original [][bits]bool

var node [][bits]value

var edge []*[bits]value

func dfs(v, p int) {
	for e := kick[v]; e >= 0; e = next[e] {
		u := dest[e]
		if edge[e] == nil {
			if adjacent[v] == saturation[v] {
				// substract and push
				edge[e] = new([bits]value)
				for b := 0; b < bits; b++ {
					push := node[v][b]
					if original[v][b] {
						push.zeros -= edge[e^1][b].zeros
						push.ones -= edge[e^1][b].ones
					} else {
						push.zeros -= edge[e^1][b].ones
						push.ones -= edge[e^1][b].zeros
					}
					edge[e][b] = push
					if original[u][b] {
						node[u][b].zeros += push.zeros
						node[u][b].ones += push.ones
					} else {
						node[u][b].zeros += push.ones
						node[u][b].ones += push.zeros
					}
				}
				saturation[u]++
			} else if adjacent[v] == saturation[v]+1 && edge[e^1] == nil {
				// push as is
				edge[e] = new([bits]value)
				for b := 0; b < bits; b++ {
					push := node[v][b]
					edge[e][b] = push
					if original[u][b] {
						node[u][b].zeros += push.zeros
						node[u][b].ones += push.ones
					} else {
						node[u][b].zeros += push.ones
						node[u][b].ones += push.zeros
					}
				}
				saturation[u]++
			}
		}
		if u != p {
			dfs(u, v)
		}
	}
}

func main() {
	n := readInt()
	node = make([][bits]value, n)
	edge = make([]*[bits]value, (n-1)*2)
	original = make([][bits]bool, n)
	for i := range node {
		a := readInt()
		for j := range node[i] {
			original[i][j] = a%2 == 0
			node[i][j] = value{
				zeros: 1 - a%2,
				ones:  a % 2,
			}
			a /= 2
		}
	}
	kick = make([]int, n)
	for i := range kick {
		kick[i] = -1
	}
	next = make([]int, (n-1)*2)
	dest = make([]int, (n-1)*2)
	adjacent = make([]int, n)
	saturation = make([]int, n)
	for i := 0; i < n-1; i++ {
		a, b := readInt()-1, readInt()-1
		adjacent[a]++
		adjacent[b]++

		// edge i * 2: a -> b
		next[i*2] = kick[a]
		dest[i*2] = b
		kick[a] = i * 2

		// edge i * 2 + 1: b -> a
		next[i*2+1] = kick[b]
		dest[i*2+1] = a
		kick[b] = i*2 + 1
	}

	dfs(0, -1)
	dfs(0, -1)

	var total int64
	for b := 0; b < bits; b++ {
		var single, double int
		for i := 0; i < n; i++ {
			if original[i][b] {
				double += node[i][b].ones
			} else {
				double += node[i][b].ones - 1
				single++
			}
		}
		total += (int64(1) << uint32(b)) * int64(single+double/2)
	}
	fmt.Println(total)
}

package main

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

var stdReader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() (result int) {
	var negative, started bool
READER_LOOP:
	for {
		char, err := stdReader.ReadByte()
		switch {
		case err != nil:
			break READER_LOOP
		case char == '-':
			negative = true
		case unicode.IsDigit(rune(char)):
			started = true
			result = result*10 + int(char&0xf)
		case started:
			break READER_LOOP
		}
	}
	if negative {
		result = -result
	}
	return
}

const bits = 22

type value struct {
	zeros, ones int
}

var kick, next, dest []int

var adjacent, saturation []int

var original [][bits]bool

var node [][bits]value

var edge []*[bits]value

func dfs(v, p int) {
	for e := kick[v]; e >= 0; e = next[e] {
		u := dest[e]
		if edge[e] == nil {
			if adjacent[v] == saturation[v] {
				// substract and push
				edge[e] = new([bits]value)
				for b := 0; b < bits; b++ {
					push := node[v][b]
					if original[v][b] {
						push.zeros -= edge[e^1][b].zeros
						push.ones -= edge[e^1][b].ones
					} else {
						push.zeros -= edge[e^1][b].ones
						push.ones -= edge[e^1][b].zeros
					}
					edge[e][b] = push
					if original[u][b] {
						node[u][b].zeros += push.zeros
						node[u][b].ones += push.ones
					} else {
						node[u][b].zeros += push.ones
						node[u][b].ones += push.zeros
					}
				}
				saturation[u]++
			} else if adjacent[v] == saturation[v]+1 && edge[e^1] == nil {
				// push as is
				edge[e] = new([bits]value)
				for b := 0; b < bits; b++ {
					push := node[v][b]
					edge[e][b] = push
					if original[u][b] {
						node[u][b].zeros += push.zeros
						node[u][b].ones += push.ones
					} else {
						node[u][b].zeros += push.ones
						node[u][b].ones += push.zeros
					}
				}
				saturation[u]++
			}
		}
		if u != p {
			dfs(u, v)
		}
	}
}

func main() {
	n := readInt()
	node = make([][bits]value, n)
	edge = make([]*[bits]value, (n-1)*2)
	original = make([][bits]bool, n)
	for i := range node {
		a := readInt()
		for j := range node[i] {
			original[i][j] = a%2 == 0
			node[i][j] = value{
				zeros: 1 - a%2,
				ones:  a % 2,
			}
			a /= 2
		}
	}
	kick = make([]int, n)
	for i := range kick {
		kick[i] = -1
	}
	next = make([]int, (n-1)*2)
	dest = make([]int, (n-1)*2)
	adjacent = make([]int, n)
	saturation = make([]int, n)
	for i := 0; i < n-1; i++ {
		a, b := readInt()-1, readInt()-1
		adjacent[a]++
		adjacent[b]++

		// edge i * 2: a -> b
		next[i*2] = kick[a]
		dest[i*2] = b
		kick[a] = i * 2

		// edge i * 2 + 1: b -> a
		next[i*2+1] = kick[b]
		dest[i*2+1] = a
		kick[b] = i*2 + 1
	}

	dfs(0, -1)
	dfs(0, -1)

	var total int64
	for b := 0; b < bits; b++ {
		var single, double int
		for i := 0; i < n; i++ {
			if original[i][b] {
				double += node[i][b].ones
			} else {
				double += node[i][b].ones - 1
				single++
			}
		}
		total += (int64(1) << uint32(b)) * int64(single+double/2)
	}
	fmt.Println(total)
}

package main

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

var stdReader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() (result int) {
	var negative, started bool
READER_LOOP:
	for {
		char, err := stdReader.ReadByte()
		switch {
		case err != nil:
			break READER_LOOP
		case char == '-':
			negative = true
		case unicode.IsDigit(rune(char)):
			started = true
			result = result*10 + int(char&0xf)
		case started:
			break READER_LOOP
		}
	}
	if negative {
		result = -result
	}
	return
}

const bits = 30

type value struct {
	zeros, ones int
}

var kick, next, dest []int

var adjacent, saturation []int

var original [][bits]bool

var node [][bits]value

var edge []*[bits]value

func maybePush(v, u, e int) {
	if edge[e] != nil {
		return
	}
	if adjacent[v] == saturation[v] {
		// substract and push
		edge[e] = new([bits]value)
		for b := 0; b < bits; b++ {
			push := node[v][b]
			if original[v][b] {
				push.zeros -= edge[e^1][b].zeros
				push.ones -= edge[e^1][b].ones
			} else {
				push.zeros -= edge[e^1][b].ones
				push.ones -= edge[e^1][b].zeros
			}
			edge[e][b] = push
			if original[u][b] {
				node[u][b].zeros += push.zeros
				node[u][b].ones += push.ones
			} else {
				node[u][b].zeros += push.ones
				node[u][b].ones += push.zeros
			}
		}
		saturation[u]++
	} else if adjacent[v] == saturation[v]+1 && edge[e^1] == nil {
		// push as is
		edge[e] = new([bits]value)
		for b := 0; b < bits; b++ {
			edge[e][b] = node[v][b]
			if original[u][b] {
				node[u][b].zeros += node[v][b].zeros
				node[u][b].ones += node[v][b].ones
			} else {
				node[u][b].zeros += node[v][b].ones
				node[u][b].ones += node[v][b].zeros
			}
		}
		saturation[u]++
	}
}

func dfs(v, p int) {
	var pe int
	for e := kick[v]; e >= 0; e = next[e] {
		u := dest[e]
		maybePush(v, u, e)
		if u == p {
			pe = e
		} else {
			dfs(u, v)
		}
	}
	if p >= 0 {
		maybePush(v, p, pe)
	}
}

func main() {
	n := readInt()
	node = make([][bits]value, n)
	edge = make([]*[bits]value, (n-1)*2)
	original = make([][bits]bool, n)
	for i := range node {
		a := readInt()
		for j := range node[i] {
			original[i][j] = a%2 == 0
			node[i][j] = value{
				zeros: 1 - a%2,
				ones:  a % 2,
			}
			a /= 2
		}
	}
	kick = make([]int, n)
	for i := range kick {
		kick[i] = -1
	}
	next = make([]int, (n-1)*2)
	dest = make([]int, (n-1)*2)
	adjacent = make([]int, n)
	saturation = make([]int, n)
	for i := 0; i < n-1; i++ {
		a, b := readInt()-1, readInt()-1
		adjacent[a]++
		adjacent[b]++

		// edge i * 2: a -> b
		next[i*2] = kick[a]
		dest[i*2] = b
		kick[a] = i * 2

		// edge i * 2 + 1: b -> a
		next[i*2+1] = kick[b]
		dest[i*2+1] = a
		kick[b] = i*2 + 1
	}

	dfs(0, -1)
	dfs(0, -1)

	for e := range edge {
		if edge[e] == nil {
			panic("Edge can't be nil")
		}
	}

	var total int64
	for b := 0; b < bits; b++ {
		var single, double int
		for i := 0; i < n; i++ {
			if original[i][b] {
				double += node[i][b].ones
			} else {
				double += node[i][b].ones - 1
				single++
			}
		}
		total += (int64(1) << uint32(b)) * int64(single+double/2)
	}
	fmt.Println(total)
}


package main

import (
	"fmt"
	"sort"
)

type Pair struct {
	Key   int
	Value int
}

type Pairs []Pair

func (p Pairs) Len() int           { return len(p) }
func (p Pairs) Less(i, j int) bool { return p[i].Key < p[j].Key }
func (p Pairs) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }

func main() {

	var t, n, k int

	fmt.Scanf("%d\n", &t)

	for t > 0 {
		fmt.Scanf("%d %d\n", &n, &k)

		var a, b []int

		for i := 0; i < n; i++ {
			var a_i int
			fmt.Scanf("%d", &a_i)
			a = append(a, a_i)
		}

		fmt.Scanf("%d\n", nil)

		for i := 0; i < n; i++ {
			var b_i int
			fmt.Scanf("%d", &b_i)
			b = append(b, b_i)
		}

		fmt.Scanf("%d\n", nil)

		pairs := make(Pairs, len(a))

		for i := 0; i < len(a); i++ {
			p := Pair{
				Key:   a[i],
				Value: b[i],
			}
			pairs = append(pairs, p)
		}

		sort.Sort(pairs)

		for _, pair := range pairs {
			if k >= pair.Key {
				k += pair.Value
			}
		}

		fmt.Println(k)

		t--
	}
}

package main
import (
	"fmt"
	"sort"
)

type input struct {
	first int
	second int
}

func main(){
	var t int
	fmt.Scan(&t)
	for ; t>0;t-- {
		var n int
		var k int
		fmt.Scan(&n)
		fmt.Scan(&k)
		inp := make([]input, n)
		for i:=0;i<n;i++ {
			fmt.Scan(&inp[i].first)
		}
		for i:=0;i<n;i++ {
			fmt.Scan(&inp[i].second)
		}
		sort.SliceStable(inp, func(i, j int) bool {
			return inp[i].first < inp[j].first
		})
		for i:=0;i<n;i++ {
			if inp[i].first <= k {
				k += inp[i].second
			}
		}
		fmt.Println(k)
	}

}

package main

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

var reader = bufio.NewReader(os.Stdin)
var 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...) }

type pair struct {
	need int
	inc int
}

type pairs []pair
func (a pairs) Len() int           { return len(a) }
func (a pairs) Less(i, j int) bool { return a[i].need < a[j].need }
func (a pairs) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	t := 0
	scanf("%d\n", &t)
	for ti:=0; ti<t; ti++ {
		n := 0
		k := 0
		scanf("%d %d\n", &n, &k)
		//printf("n k %d %d\n", n, k)
		p := make(pairs, n)
		for i:=0; i<n; i++ {
			if i > 0 {
				scanf(" ")
			}
			scanf("%d", &p[i].need)
			//printf("i = %d p[i].need = %d\n", i, p[i].need)
		}
		scanf("\n%")
		for i:=0; i<n; i++ {
			if i > 0 {
				scanf(" ")
			}
			scanf("%d", &p[i].inc)
		}
		scanf("\n%")
		sort.Sort(p)
		ramNow := k
		for i:=0; i<n; i++ {
			//printf("%d %d %d\n", i, p[i].need, p[i].inc)
			if ramNow >= p[i].need {
				ramNow += p[i].inc
			}
		}
		printf("%d\n", ramNow)
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,current int
		fmt.Fscan(in,&n,&current)
		cost:= make([]int,n)
		additional:= make([]int,n)
		for j:=0;j<n;j++{
			fmt.Fscan(in,&cost[j])
		}
		for j:=0;j<n;j++{
			fmt.Fscan(in,&additional[j])
		}
		for j:=0;j<len(cost);j++{
			if cost[j] <= current {
				current+= additional[j]
				cost = append(cost[:j],cost[j+1:]...)
				additional = append(additional[:j],additional[j+1:]...)
				j=-1
			}
		}
		fmt.Fprintln(out,current)
	}
}

package main

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

type Soft struct {
	needed int
	inc    int
}

func solve(r *bufio.Reader) {
	var n, m int
	fmt.Fscan(r, &n, &m)

	ss := make([]Soft, n)
	for i := range ss {
		fmt.Fscan(r, &ss[i].needed)
	}

	for i := range ss {
		fmt.Fscan(r, &ss[i].inc)
	}

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

	for _, s := range ss {
		if s.needed <= m {
			m += s.inc
		} else {
			fmt.Println(m)
			return
		}
	}
	fmt.Println(m)
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		solve(r)
	}
}

package main

import (
	"bufio"
	"crypto/rand"
	"fmt"
	"math"
	"math/big"
	"os"
	"sort"
	"strconv"
)

func main() {

	reader := bufio.NewReader(os.Stdin)
	writter := bufio.NewWriter(os.Stdout)
	defer writter.Flush()

	t := 0
	fmt.Fscan(reader, &t)

	for t > 0 {
		n, k := 0, 0
		fmt.Fscan(reader, &n, &k)

		a := make([]int, n)
		for i := range a {
			fmt.Fscan(reader, &a[i])
		}

		b := make([]int, n)
		for i := range b {
			fmt.Fscan(reader, &b[i])
		}

		fmt.Fprintln(writter, solve(n, k, a, b))

		t--
	}

	// n, k := 5, 1
	// a := []int{1, 1, 5, 1, 1}
	// b := []int{1, 1, 1, 1, 1}

	// fmt.Println(solve(n, k, a, b))

}

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

	now := k

	for {
		maxV := 0
		maxP := -1

		for i := range a {
			if a[i] <= now {
				maxV = b[i]
				maxP = i
			}
		}

		if maxP == -1 {
			break
		}

		now += maxV
		a[maxP] = math.MaxInt

		//fmt.Println(now)
	}

	return now
}

func arraySum(array []int) int {
	sum := 0

	for i := range array {
		sum += array[i]
	}

	return sum
}

func numSum(num int) int {
	sum := 0

	for i := num; i > 0; i-- {
		sum += i
	}

	return sum
}

func strToint(str string) int {
	num, _ := strconv.Atoi(str)
	return num
}

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

	return b
}

func getFactor(num int) []int {
	result := []int{}

	for i := 1; i <= int(math.Sqrt(float64(num))); i++ {
		if num%i == 0 {
			result = append(result, i)
			result = append(result, num/i)
		}
	}

	return result
}

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

	return gcd(b%a, a)
}

func printMatrix(matrix [][]int) {

	for i := range matrix {

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

		fmt.Println()

	}

}

func checkPrime(num int) bool {

	if num < 2 {
		return false
	}

	for i := 2; i <= int(math.Sqrt(float64(num))); i++ {
		if num%i == 0 {
			return false
		}
	}

	return true
}

func getPower() {
	A := []int{}

	for i := 1; i <= 38; i++ {
		A = append(A, i)
	}

	for i := range A {
		target, _ := rand.Int(rand.Reader, big.NewInt(38))
		A[i], A[target.Int64()] = A[target.Int64()], A[i]
	}

	B, _ := rand.Int(rand.Reader, big.NewInt(8))

	result := A[:6]
	sort.Ints(result)
	result = append(result, int(B.Int64())+1)

	fmt.Println(result)
}

package main

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

type CF1629A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1629A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1629A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1629A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1629A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1629A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1629A
Date: 2/02/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1629/A
Problem: CF1629A
**/
func (in *CF1629A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, k := in.NextInt(), in.NextInt()
		m := make([][]int, n)
		for i := 0; i < n; i++ {
			m[i] = make([]int, 2)
			m[i][0] = in.NextInt()
		}
		for i := 0; i < n; i++ {
			m[i][1] = in.NextInt()
		}

		sort.Slice(m, func(i, j int) bool {
			if m[i][0]-m[j][0] == 0 {
				if m[i][1]-m[j][1] > 0 {
					return false
				}
				return true
			}
			if m[i][0]-m[j][0] > 0 {
				return false
			}
			return true
		})

		result := k
		for i := 0; i < n; i++ {
			if m[i][0] <= result {
				result += m[i][1]
			}
		}
		fmt.Println(result)
	}
}

func NewCF1629A(r *bufio.Reader) *CF1629A {
	return &CF1629A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1629A(bufio.NewReader(os.Stdin)).Run()
}

package main

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

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

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

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

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

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n, k int
	scan(&n, &k)
	var a = make([][2]int, n)
	for i := range a {
		scan(&a[i][0])
	}
	for i := range a {
		scan(&a[i][1])
	}
	sort.Slice(a, func(i, j int) bool {
		return a[i][0] < a[j][0]
	})
	for i := range a {
		if a[i][0] <= k {
			k += a[i][1]
		}
	}
	printf("%v\n", k)
}

package main

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

type Pair struct {
	First int
	Second int
}

func main() {
	var (
		reader = bufio.NewReader(os.Stdin)
		t, n, k int
	)
	fmt.Fscan(reader, &t);
	for i := 0; i < t; i++ {
		fmt.Fscan(reader, &n, &k);
		a := []int{}
		b := []int{}
		for j := 0; j < n; j++ {
			var x int;
			fmt.Fscan(reader, &x);
			a = append(a, x);
		}
		for j := 0; j < n; j++ {
			var x int;
			fmt.Fscan(reader, &x);
			b = append(b, x);
		}
		c := []Pair{}
		for j := 0; j < n; j++ {
			c = append(c, Pair{a[j], b[j]});
		}
		sort.SliceStable(c, func(x, y int) bool {
			if c[x].First < c[y].First {
				return true;
			} else if c[x].First == c[y].First {
				if c[x].Second < c[y].Second {
					return true;
				} else {
					return false;
				}
			} else {
				return false;
			}
		})
		for i := 0; i < n; i++ {
			if k >= c[i].First {
				k += c[i].Second
			} else {
				break;
			}
		}
		fmt.Println(k);
	}
}

package main

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

type P struct {
	a, b int
}

var (
	reader  = bufio.NewReader(os.Stdin)
	t, n, k int
)

func solve(n, k int, p []P) int {
	sort.Slice(p, func(i, j int) bool {
		return p[i].a < p[j].a || (p[i].a == p[j].a && p[i].b < p[j].b)
	})
	x := k
	for i := range p {
		if p[i].a > x {
			break
		}
		x += p[i].b
	}
	return x
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &k)
		p := make([]P, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &p[i].a)
		}
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &p[i].b)
		}
		fmt.Println(solve(n, k, p))
	}
}

package main

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

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

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

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

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

type Pair struct {
	a, b int
}

func customSort(arr []Pair) func(int, int) bool {
	return func(i, j int) bool {
		return arr[i].a < arr[j].a
	}
}

func main() {
	defer writer.Flush()
	var t, n, k int
	scan(&t)
	for i := 0; i < t; i++ {
		scan(&n, &k)
		arr := make([]Pair, n)
		for j := 0; j < n; j++ {
			scan(&arr[j].a)
		}
		for j := 0; j < n; j++ {
			scan(&arr[j].b)
		}
		sort.SliceStable(arr, customSort(arr))
		res := k
		for r := 0; r < n; r++ {
			if arr[r].a > res {
				break
			}
			res += arr[r].b
		}
		println(res)
	}
}

package main

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

type RAM struct {
	a, p int
}

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 := []RAM{}
		for j := 0; j < 2*n; j++ {
			p := 0
			fmt.Fscan(f, &p)
			if j >= n {
				o[j%n].p = p
			} else {
				o = append(o, RAM{a: p})
			}
		}
		sort.Slice(o, func(i, j int) bool {
			if o[i].a == o[j].a {
				return o[i].p > o[j].p
			}
			return o[i].a < o[j].a
		})
		for j := 0; j < n; j++ {
			if o[j].a <= k {
				k += o[j].p
			} else {
				break
			}
		}
		fmt.Fprintln(w, k)
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import "fmt"

type ram struct {
	a []int
	b []int
	cap int
	count int
}

func main() {
	var testCases int
	fmt.Scan(&testCases)

	rams := make([]ram, testCases)

	for i := 0; i < testCases; i++ {
		var r ram
		fmt.Scan(&r.count, &r.cap)

		a := make([]int, r.count)
		for j := 0; j < r.count; j++ {
			fmt.Scan(&a[j])
		}

		b := make([]int, r.count)
		for j := 0; j < r.count; j++ {
			fmt.Scan(&b[j])
		}

		r.a = a
		r.b = b
		rams[i] = r
	}

	for _, r := range rams {
		r.sort()
		r.result()

		fmt.Println(r.cap)
	}
}

func (r *ram) result() {
	cap := r.cap
	for i := 0; i < len(r.a); i++ {
		if cap >= r.a[i] {
			cap += r.b[i]
		} else {
			r.cap = cap
			return
		}
	}
	r.cap = cap
}

func (r *ram) sort() {
	for i := 0; i < len(r.a) - 1; i++ {
		for j := i + 1; j < len(r.a); j++ {
			if r.a[i] > r.a[j] {
				r.a[i], r.a[j] = r.a[j], r.a[i]
				r.b[i], r.b[j] = r.b[j], r.b[i]
			}
		}
	}
}

package main

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

const mod = 998244353
const mx = 3000

type pair struct{
	low int
	ram int
}

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n,cur int
	fmt.Fscan(in,&n,&cur)
	a := make([]int,n)
	ps := make([]pair,n)
	for i := 0;i < n;i++{
		fmt.Fscan(in,&a[i])
	}
	for i := 0;i < n;i++{
		ps[i] = pair{
			low : a[i],
		}
		fmt.Fscan(in,&ps[i].ram)
	}
	sort.Slice(ps, func(i, j int) bool {
		return ps[i].low < ps[j].low
	})
	for _,p := range ps{
		if cur >= p.low{
			cur += p.ram
		}else{
			break
		}
	}
	fmt.Fprintln(out,cur)
}
func sum(a,b int64)int64{
	return (b + a) * (b - a + 1) / 2
}

func max(a,b int64)int64{
	if a > b{
		return a
	}
	return b
}
func min(a,b int64)int64{
	if a > b{
		return b
	}
	return a
}
func gcd(a,b int64)int64{
	if a % b == 0{
		return b
	}
	return gcd(b,a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

func fn(rr *bufio.Reader) {
	nk := readLineNumbs(rr)

	n, _ := strconv.Atoi(nk[0])
	k, _ := strconv.Atoi(nk[1])

	a := readLineNumbs(rr)
	b := readLineNumbs(rr)

	mp := make(map[int][]int)

	for i := 0; i < n; i++ {
		nb, _ := strconv.Atoi(b[i])
		na, _ := strconv.Atoi(a[i])
		dif := nb - na
		_, ok := mp[dif]
		if !ok {
			mp[dif] = []int{i}
		} else {
			mp[dif] = append(mp[dif], i)
		}
	}

	// debug("mp", mp)
	keys := make([]int, 0, len(mp))
	for k, _ := range mp {
		keys = append(keys, k)
	}
	sort.Sort(sort.Reverse(sort.IntSlice(keys)))

	//debug("keys", keys)
	for i := 0; i < n; i++ {
		for _, x := range keys {
			// debug("x", x)
			// debug("mp[x]", mp[x])
			if len(mp[x]) > 0 {
				for j := 0; j < len(mp[x]); j++ {
					pos := (mp[x])[j]
					cur, _ := strconv.Atoi(a[pos])
					if cur <= k {
						sum, _ := strconv.Atoi(b[pos])
						k += sum
						if len(mp[x]) == 1 {
							delete(mp, x)
						} else {
							mp[x] = append(mp[x][:j], mp[x][j+1:]...)
						}
					}
				}
			}
		}
	}
	fmt.Println(k)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	t := readInt(reader)
	for i := 0; i < t; i++ {
		fn(reader)
	}
}

// Thanks to user: gealbermorales for the valuable guidance with processing input using Go
// https://codeforces.com/blog/entry/94245

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 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 debug(name string, a interface{}) {
	fmt.Printf("%s = %v \n", name, a)
}

package main

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

var arr []pair

type pair struct {
	a int
	b int
}

func solve(n int, k int) int {
	sort.Slice(arr[:n], func(i, j int) bool {
		if arr[i].a < arr[j].a {
			return true
		}
		if arr[i].a > arr[j].a {
			return false
		}
		return arr[i].b > arr[j].b
	})
	for i := 0; i < n; i++ {
		prevk := k
		k -= arr[i].a
		if k < 0 {
			return prevk
		}
		k += arr[i].a + arr[i].b
	}
	return k
}

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

	var T int
	fmt.Fscan(in, &T)

	arr = make([]pair, 105)

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

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

		fmt.Fprintln(out, solve(n, k))
	}
	out.Flush()
}

// generated by 1e9y at 22-01-2022
// template version: 2022-01-11

package main

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

type Ram []int

type SortBy []Ram

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

// 0000.A
func solve(n, k int, ram SortBy) int {
	sum := k
	sort.Sort(ram)
	// Println(ram)
	for i := 0; i < n; i++ {
		r := ram[i]
		if r[0] > sum {
			break
		}
		sum += r[1]
	}
	return sum
}

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

	t := ReadInt(in)
	for i := 0; i < t; i++ {
		slice := ReadIntSlice(in)
		n, k := slice[0], slice[1]
		ram := make([]Ram, n)
		aa := ReadIntSlice(in)
		bb := ReadIntSlice(in)
		for j := 0; j < n; j++ {
			ram[j] = []int{aa[j], bb[j]}
		}
		Output(solve(n, k, ram))
	}
}

// helpers for convenient input reading

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

func ReadLine(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	return line
}

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

func ReadIntSlice(in *bufio.Reader) []int {
	parts := ReadLineParts(in)
	slice := make([]int, len(parts))
	for i, n := range parts {
		slice[i] = MustAtoi(n)
	}
	return slice
}

func ReadInt64Slice(in *bufio.Reader) []int64 {
	parts := ReadLineParts(in)
	slice := make([]int64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseInt(n, 10, 64)
	}
	return slice
}

func ReadUint64Slice(in *bufio.Reader) []uint64 {
	parts := ReadLineParts(in)
	slice := make([]uint64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseUint(n, 10, 64)
	}
	return slice
}

func MustAtoi(s string) int {
	v, _ := strconv.Atoi(s)
	return v
}

func MustParseInt(s string, base, bitSize int) int64 {
	v, _ := strconv.ParseInt(s, base, bitSize)
	return v
}

func MustParseUint(s string, base, bitSize int) uint64 {
	v, _ := strconv.ParseUint(s, base, bitSize)
	return v
}

func SkipLine(in *bufio.Reader) {
	_, _ = in.ReadString('\n')
}

// helper for convenient answer output

func Output(v interface{}) {
	switch v.(type) {
	case bool:
		if v == true {
			Println("YES")
		} else {
			Println("NO")
		}
	default:
		Println(v)
	}
}

package main

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

type building struct {
	id   int
	v, d int64
}

type ram struct {
	pos, req, bonus int
}

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

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

		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)
			progs[i].bonus = v
		}

		sort.SliceStable(progs, func(i, j int) bool {
			if progs[i].req == progs[j].req {
				return progs[i].bonus > progs[j].bonus
			}
			return progs[i].req < progs[j].req
		})

		total := k
		for _, p := range progs {
			if total < p.req {
				break
			}

			total += p.bonus
		}
		fmt.Fprintln(out, total)
	}
}

package main

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

/*

 */

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

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

	for ; t > 0; t-- {
		var n, k int
		scanf("%d %d\n", &n, &k)

		type pair struct {
			a int
			b int
		}

		pairs := make([]pair, n)

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

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

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

		for _, p := range pairs {
			if p.a <= k {
				k += p.b
			}
		}

		fmt.Fprintln(writer, k)
	}
}

const maxUint = ^uint(0)

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

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

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

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

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

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 main() {
	defer out.Flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		var n, k int
		scan(&n, &k)
		var a []int = make([]int, n)
		var b []int = make([]int, n)
		for i := 0; i < n; i++ {
			scan(&a[i])
		}
		for i := 0; i < n; i++ {
			scan(&b[i])
		}
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				if a[j] <= k {
					k += b[j]
					a[j] = 0
					b[j] = 0
				}
			}
		}
		printf("%d\n", k)
	}
}

package main
import (
	"fmt"
	"sort"
)

type input struct {
	first int
	second int
}

func main(){
	var t int
	fmt.Scan(&t)
	for ; t>0;t-- {
		var n int
		var k int
		fmt.Scanf("%d %d",&n, &k)
		inp := make([]input, n)
		for i:=0;i<n;i++ {
			fmt.Scan(&inp[i].first)
		}
		for i:=0;i<n;i++ {
			fmt.Scan(&inp[i].second)
		}
		sort.SliceStable(inp, func(i, j int) bool {
			return inp[i].first < inp[j].first
		})
		for i:=0;i<n;i++ {
			if inp[i].first <= k {
				k += inp[i].second
			}
		}
		fmt.Println(k)
	}

}

package main

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

var reader = bufio.NewReader(os.Stdin)
var 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...) }

type pair struct {
	need int
	inc int
}

type pairs []pair
func (a pairs) Len() int           { return len(a) }
func (a pairs) Less(i, j int) bool { return a[i].need < a[j].need || a[i].inc > a[j].inc }
func (a pairs) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	t := 0
	n := 0
	k := 0
	scanf("%d\n", &t)
	for ti:=0; ti<t; ti++ {
		scanf("%d %d\n", &n, &k)
		//printf("n k %d %d\n", n, k)
		p := make(pairs, n)
		for i:=0; i<n; i++ {
			if i > 0 {
				scanf(" ")
			}
			scanf("%d", &p[i].need)
			//printf("i = %d p[i].need = %d\n", i, p[i].need)
		}
		scanf("\n%")
		for i:=0; i<n; i++ {
			if i > 0 {
				scanf(" ")
			}
			scanf("%d", &p[i].inc)
		}
		scanf("\n%")
		sort.Sort(p)
		ramNow := k
		for i:=0; i<n; i++ {
			//printf("%d %d %d\n", i, p[i].need, p[i].inc)
			if ramNow >= p[i].need {
				ramNow += p[i].inc
			}
		}
		printf("%d\n", ramNow)
	}
}


package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	const b int64 = 1e5
	const b1 = b - 1

	var n, t, y, m int
	var x int64
	Fscan(in, &n, &m)
	f := make([]int, m+1)
	for i := m; i > 0; i-- {
		f[i] = -1
	}
	for i := 1; i <= n; i++ {
		Fscan(in, &t, &x, &y)
		if t == 1 {
			x := int((x + b1) / b)
			for j := m; j >= 0; j-- {
				if f[j] >= 0 {
					for a, k := y, j; a > 0; a-- {
						k += x
						if k > m || f[k] >= 0 {
							break
						}
						f[k] = i
					}
				}
			}
		} else {
			for j := m; j >= 0; j-- {
				if f[j] >= 0 {
					for a, k := y, int64(j); a > 0; a-- {
						k = (k*x + b1) / b
						if k > int64(m) || f[k] >= 0 {
							break
						}
						f[k] = i
					}
				}
			}
		}
	}
	for _, v := range f[1:] {
		Print(v, " ")
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	const b int64 = 1e5
	const b1 = b - 1

	var n, t, y, m int
	var x int64
	Fscan(in, &n, &m)
	f := make([]int, m+1)
	for i := m; i > 0; i-- {
		f[i] = -1
	}
	for i := 1; i <= n; i++ {
		Fscan(in, &t, &x, &y)
		if t == 1 {
			x := int((x + b1) / b)
			for j := m; j >= 0; j-- {
				if f[j] >= 0 {
					for a, k := y, j; a > 0; a-- {
						k += x
						if k > m || f[k] >= 0 {
							break
						}
						f[k] = i
					}
				}
			}
		} else {
			for j := m; j >= 0; j-- {
				if f[j] >= 0 {
					for a, k := y, int64(j); a > 0; a-- {
						k = (k*x + b1) / b
						if k > int64(m) || f[k] >= 0 {
							break
						}
						f[k] = i
					}
				}
			}
		}
	}
	for _, v := range f[1:] {
		Fprint(out, v, " ")
	}
}

package main
import ."fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n, t, y int
	var m, x int64
	Scan(&n, &m)
	f := make([]int, m+1)
	for i := m; i > 0; i-- {
		f[i] = -1
	}
	for i := 1; i <= n; i++ {
		Scan(&t, &x, &y)
		for j := m; j >= 0; j-- {
			if f[j] >= 0 {
				for a, k := 0, j; a < y; a++ {
					if t == 1 {
						k += (x + 1e5 - 1) / 1e5
					} else {
						k = (k*x + 1e5 - 1) / 1e5
					}
					if k > m || f[k] >= 0 {
						break
					}
					f[k] = i
				}
			}
		}
	}
	for _, v := range f[1:] {
		Print(v, " ")
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func run(in io.Reader, out io.Writer) {
	var n, t, y int
	var m, x int64
	Fscan(in, &n, &m)
	f := make([]int, m+1)
	for i := m; i > 0; i-- {
		f[i] = -1
	}
	for i := 1; i <= n; i++ {
		Fscan(in, &t, &x, &y)
		for j := m; j >= 0; j-- {
			if f[j] >= 0 {
				for a, k := 0, j; a < y; a++ {
					if t == 1 {
						k += (x + 1e5 - 1) / 1e5
					} else {
						k = (k*x + 1e5 - 1) / 1e5
					}
					if k > m || f[k] >= 0 {
						break
					}
					f[k] = i
				}
			}
		}
	}
	for _, v := range f[1:] {
		Fprint(out, v, " ")
	}
}

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