You are given an array of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. You can make the following operation: choose an integer $$$x \geq 2$$$ and replace each number of the array by the remainder when dividing that number by $$$x$$$, that is, for all $$$1 \leq i \leq n$$$ set $$$a_i$$$ to $$$a_i \bmod x$$$.Determine if it is possible to make all the elements of the array equal by applying the operation zero or more times.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 10^9$$$) where $$$a_i$$$ is the $$$i$$$-th element of the array. The sum of $$$n$$$ for all test cases is at most $$$2 \cdot 10^5$$$.

For each test case, print a line with YES if you can make all elements of the list equal by applying the operation. Otherwise, print NO. You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as a positive answer).

NoteIn the first test case, one can apply the operation with $$$x = 3$$$ to obtain the array $$$[2, 2, 0, 2]$$$, and then apply the operation with $$$x = 2$$$ to obtain $$$[0, 0, 0, 0]$$$.In the second test case, all numbers are already equal.In the fourth test case, applying the operation with $$$x = 4$$$ results in the array $$$[1, 1, 1, 1]$$$.

package main

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

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

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

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

			if arr[i] == 1 {
				hasOne = true
			}
		}

		sort.Ints(arr)
		var f bool
		for i := 1; i < n; i++ {
			if arr[i]-arr[i-1] == 1 {
				f = true
				break
			}
		}

		if !hasOne || (hasOne && !f) {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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 readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func main() {
	ip := bufio.NewReader(os.Stdin)
	t := readInt(ip)
	for t > 0 {
		t--
		_ = readInt(ip)
		tmp := readArrInt(ip)
		sort.Ints(tmp)
		c1, c2 := 0, 0
		f := true
		for i := range tmp {
			if tmp[i] == 1 {
				c1++
			}
			if i < len(tmp)-1 && tmp[i]+1 == tmp[i+1] {
				c2++
			}
			if c1 > 0 && c2 > 0 {
				f = false
				break
			}
		}
		if f {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

// https://codeforces.com/problemset/problem/1656/C

// 1656C - Make Equal With Mod

// You are given an array of n non-negative integers a1,a2,…,an. You can make the following operation: choose an integer x≥2 and replace each number of the array by the remainder when dividing that number by x, that is, for all 1≤i≤n set ai to aimodx.
// Determine if it is possible to make all the elements of the array equal by applying the operation zero or more times.

// Input
// The input consists of multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. Description of the test cases follows.
// The first line of each test case contains an integer n (1≤n≤105) — the length of the array.
// The second line of each test case contains n integers a1,a2,…,an (0≤ai≤109) where ai is the i-th element of the array.
// The sum of n for all test cases is at most 2⋅105.

// Output
// For each test case, print a line with YES if you can make all elements of the list equal by applying the operation. Otherwise, print NO.
// You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as a positive answer).

// Example
// input
// 4
// 4
// 2 5 6 8
// 3
// 1 1 1
// 5
// 4 1 7 0 8
// 4
// 5 9 17 5
// output
// YES
// YES
// NO
// YES

// Note

// In the first test case, one can apply the operation with x=3 to obtain the array [2,2,0,2], and then apply the operation with x=2 to obtain [0,0,0,0].
// In the second test case, all numbers are already equal.
// In the fourth test case, applying the operation with x=4 results in the array [1,1,1,1].

// Tutorial

// Note that, if 1 is not present in the array, we can always make all elements equal to 0 by repeatedly applying the operation with x=max(ai) until all elements become 0, as this operation will set the elements equal to the maximum to 0, while maintaining the others intact. So the answer is YES.
// If 1 is present and there are no two consecutive numbers in the array, we can similarly apply repeatedly the operation with x=max(ai)−1 until all elements become 1, as this operation will set the elements equal to the maximum to 1, while maintaining the others intact. So the answer is again YES.
// If 1 is present in the array, and there are two consecutive numbers m,m+1 in the array, the answer is NO. Note that if we have a 0 and a 1 in the array, we won't be able to make them equal after any number of operations, and so we cannot have any operation with an x that divides one of the ai's. The rest of operations will cause that m,m+1 remain consecutive (and thus different), meaning that it is impossible to make all the array equal.

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c int
	var t, n, i uint
	var a []uint
	var one, consec bool

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			fmt.Fscan(reader, &n)
			a = make([]uint, n)
			one = false
			consec = false

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

				if a[i] == 1 {
					one = true
				}
			}

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

			for i = 1; i < n && !consec; i++ {
				if a[i] == a[i-1]+1 {
					consec = true
				}
			}

			if one && consec {
				fmt.Fprintln(writer, "NO")
			} else {
				fmt.Fprintln(writer, "YES")
			}
		}
	}

	writer.Flush()
}

// https://codeforces.com/problemset/problem/1656/C

// 1656C - Make Equal With Mod

// You are given an array of n non-negative integers a1,a2,…,an. You can make the following operation: choose an integer x≥2 and replace each number of the array by the remainder when dividing that number by x, that is, for all 1≤i≤n set ai to aimodx.
// Determine if it is possible to make all the elements of the array equal by applying the operation zero or more times.

// Input
// The input consists of multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. Description of the test cases follows.
// The first line of each test case contains an integer n (1≤n≤105) — the length of the array.
// The second line of each test case contains n integers a1,a2,…,an (0≤ai≤109) where ai is the i-th element of the array.
// The sum of n for all test cases is at most 2⋅105.

// Output
// For each test case, print a line with YES if you can make all elements of the list equal by applying the operation. Otherwise, print NO.
// You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as a positive answer).

// Example
// input
// 4
// 4
// 2 5 6 8
// 3
// 1 1 1
// 5
// 4 1 7 0 8
// 4
// 5 9 17 5
// output
// YES
// YES
// NO
// YES

// Note

// In the first test case, one can apply the operation with x=3 to obtain the array [2,2,0,2], and then apply the operation with x=2 to obtain [0,0,0,0].
// In the second test case, all numbers are already equal.
// In the fourth test case, applying the operation with x=4 results in the array [1,1,1,1].

// Tutorial

// Note that, if 1 is not present in the array, we can always make all elements equal to 0 by repeatedly applying the operation with x=max(ai) until all elements become 0, as this operation will set the elements equal to the maximum to 0, while maintaining the others intact. So the answer is YES.
// If 1 is present and there are no two consecutive numbers in the array, we can similarly apply repeatedly the operation with x=max(ai)−1 until all elements become 1, as this operation will set the elements equal to the maximum to 1, while maintaining the others intact. So the answer is again YES.
// If 1 is present in the array, and there are two consecutive numbers m,m+1 in the array, the answer is NO. Note that if we have a 0 and a 1 in the array, we won't be able to make them equal after any number of operations, and so we cannot have any operation with an x that divides one of the ai's. The rest of operations will cause that m,m+1 remain consecutive (and thus different), meaning that it is impossible to make all the array equal.

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c int
	var t, n, i uint
	var a []uint
	var one, consec bool

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			fmt.Fscan(reader, &n)
			a = make([]uint, n)
			one = false
			consec = false

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

				if a[i] == 1 {
					one = true
				}
			}

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

			for i = 1; i < n; i++ {
				if a[i] == a[i-1]+1 {
					consec = true
				}
			}

			if one && consec {
				fmt.Fprintln(writer, "NO")
			} else {
				fmt.Fprintln(writer, "YES")
			}
		}
	}

	writer.Flush()
}

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()

	var T, n, v int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		c := map[int]int{}
		for ; n > 0; n-- {
			Fscan(in, &v)
			c[v]++
		}
		if c[1] > 0 {
			for v := range c {
				if c[v-1] > 0 {
					Fprintln(out, "NO")
					continue o
				}
			}
		}
		Fprintln(out, "YES")
	}
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var n int
		fmt.Fscan(in, &n)
		nums := make([]int, n)
		one := false
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[i])
			if nums[i] == 1 {
				one = true
			}
		}
		sort.Ints(nums)
		min := nums[0]
		if min > 1 {
			fmt.Fprintln(out, "YES")
			continue
		}
		if min == 0 {
			if one {
				fmt.Fprintln(out, "NO")
			} else {
				fmt.Fprintln(out, "YES")
			}
			continue
		}
		find := true
		for i := n - 2; i >= 0; i-- {
			if nums[i]+1 == nums[i+1] {
				find = false
				break
			}
			if nums[i] == min {
				break
			}
		}
		if find {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

/*
3
1
0
1
1
2
0 1
---
YES
YES
NO
========

1
5
4 6 7 0 8
---
YES
---
4 6 7 0 8 mod 4
0 2 3 0 0 mod 3
0 2 0 0 0 mod 2
0 0 0 0 0
=======
1
7
2 1 3 2 1 4 3
---
NO
========
2
2
4 5
2
1 6
---
YES
YES
=======
1
7
4 9 3 5 1 4 3
---
NO?
4 9 3 5 1 4 3 mod 8
4 1 3 5 1 4 3 mod
======
1
3
1 7 8
---
NO
1 2 3

*/

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

	a := make([]int, n)

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

	sort.Ints(a)

	hasZero := false
	hasOne := false
	hasOneDiff := false

	for i, num := range a {
		if a[i] == 0 {
			hasZero = true
		} else if a[i] == 1 {
			hasOne = true
		}

		if i == 0 {
			continue
		}

		if num == a[i-1]+1 {
			hasOneDiff = true
		}
	}

	if hasOne && hasZero || hasOne && hasOneDiff {
		fmt.Fprintln(writer, "NO")
	} else {
		fmt.Fprintln(writer, "YES")
	}
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

	return minNumIdx
}

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

	return maxNumIdx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

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

func main(){
	read := bufio.NewReader(os.Stdin)
	write := bufio.NewWriter(os.Stdout)

	defer write.Flush()

	var tc int

	for Fscan (read, &tc); tc > 0; tc -- {
		var n int

		Fscan (read, &n)

		isOne := false

		vals := map[int]bool{}

		for i := 1; i <= n; i++ {
		    var val int
		    Fscan (read, &val)
		    if val == 1{
		        isOne = true
		    }
		    vals[val] = true
		}

		if !isOne {
		    Fprintln (write, "YES")
		} else{
		    ok := true
		    for key, _ := range vals {
		        if vals[key + 1] {
		            ok = false
		        }
		    }
		    if ok {
		        Fprintln (write, "YES")
		    } else {
		        Fprintln (write, "NO")
		    }
		}
	}
}

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

type IntSlice []int

func (s IntSlice) Len() int { return len(s) }
func (s IntSlice) Swap(i, j int){ s[i], s[j] = s[j], s[i] }

const N int =1e5+10
var a [N]int
func main(){
	in:=bufio.NewReader(os.Stdin)
	out:=bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T int
	Fscan(in,&T)
	for i:=1;i<=T;i++{
		var n int
		Fscan(in,&n)
		p := make([]int, n)
		var flag,is1 bool=false,false
		for i:=range p{
           var x int
		   Fscan(in,&x)

		   if x==1{
			   is1=true
		   }
		   p[i]=x
		}

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

		for i:=0;i<n-1;i++{
			if p[i]+1==p[i+1]{
				flag=true
			}
		}
		if is1 && flag{
			Println("NO")
		}else{
			Println("YES")
		}
	}
}

package main

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

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

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

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

			if v <= 2 {
				tally[v]++
			}
		}

		if tally[1] == n || (tally[1] > 0 && tally[0] == 0 && tally[2] == 0) || tally[1] == 0 {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}

	}
}

package main

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

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

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

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

			if v <= 2 {
				tally[v]++
			}
		}

		if tally[1] == n || (tally[1] > 0 && tally[0] == 0 && tally[2] == 0) || tally[1] == 0 {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}

	}
}

package main

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

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

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

		var odds, evens int
		var ones int
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			if v%3 == 1 {
				ones++
			}

			if v%2 == 0 {
				evens++
			} else {
				odds++
			}
		}

		if ones == 0 || ones == n || evens == n || odds == n {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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

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

		var ones int
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			if v%3 == 1 {
				ones++
			}
		}

		if ones == 0 || ones == n {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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 readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func main() {
	ip := bufio.NewReader(os.Stdin)
	t := readInt(ip)
	for t > 0 {
		t--
		_ = readInt(ip)
		tmp := readArrInt(ip)
		sort.Ints(tmp)
		c1, c2 := 0, 0
		f := true
		for i := range tmp {
			if tmp[i] == 1 {
				c1++
			}
			if i < len(tmp)-1 && tmp[i] == tmp[i+1] {
				c2++
			}
			if c1 > 0 && c2 > 0 {
				f = false
				break
			}
		}
		if f {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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 readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func main() {
	ip := bufio.NewReader(os.Stdin)
	t := readInt(ip)
	for t > 0 {
		t--
		_ = readInt(ip)
		tmp := readArrInt(ip)
		sort.Ints(tmp)
		c1, c2 := 0, 0
		f := true
		for i := range tmp {
			if tmp[i] == 1 {
				c1++
			}
			if i < len(tmp)-1 && tmp[i] == tmp[i+1] {
				c2++
			}
			if c1 > 0 && c2 > 0 {
				f = false
				break
			}
		}
		if f {
			fmt.Println("Yes")
		} else {
			fmt.Println("NO")
		}
	}
}

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()

	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		c := [3]int{}
		for i := 0; i < n; i++ {
			if Fscan(in, &v); v < 3 {
				c[v]++
			}
		}
		if 0 < c[1] && c[1] < n && c[0]+c[2] > 0 {
			Println("NO")
		} else {
			Println("YES")
		}
	}
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var n int
		fmt.Fscan(in, &n)
		var one, zero, two bool
		for i := 0; i < n; i++ {
			num := 0
			fmt.Fscan(in, &num)
			if num == 0 {
				zero = true
			}
			if num == 1 {
				one = true
			}
			if num == 2 {
				two = true
			}
		}
		if !one {
			fmt.Fprintln(out, "YES")
		} else if two || zero {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

/*
3
1
0
1
1
2
0 1
---
YES
YES
NO
========

1
5
4 6 7 0 8
---
YES
---
4 6 7 0 8 mod 4
0 2 3 0 0 mod 3
0 2 0 0 0 mod 2
0 0 0 0 0
=======
1
7
2 1 3 2 1 4 3
---
NO
========
2
2
4 5
2
1 6
---
YES
YES
*/

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

	a := make([]int64, n)

	hasZero := false
	hasOne := false
	hasTwo := false

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

		if a[i] == 0 {
			hasZero = true
		} else if a[i] == 1 {
			hasOne = true
		} else if a[i] == 2 {
			hasTwo = true
		}
	}
	scanf("\n")

	if hasOne && hasZero || hasOne && hasTwo {
		fmt.Fprintln(writer, "NO")
	} else {
		fmt.Fprintln(writer, "YES")
	}
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

	return minNumIdx
}

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

	return maxNumIdx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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


Nastia has an unweighted tree with $$$n$$$ vertices and wants to play with it!The girl will perform the following operation with her tree, as long as she needs:  Remove any existing edge.  Add an edge between any pair of vertices. What is the minimum number of operations Nastia needs to get a bamboo from a tree? A bamboo is a tree in which no node has a degree greater than $$$2$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of vertices in the tree. Next $$$n - 1$$$ lines of each test cases describe the edges of the tree in form $$$a_i$$$, $$$b_i$$$ ($$$1 \le a_i, b_i \le n$$$, $$$a_i \neq b_i$$$). It's guaranteed the given graph is a tree and the sum of $$$n$$$ in one test doesn't exceed $$$2 \cdot 10^5$$$.

For each test case in the first line print a single integer $$$k$$$ — the minimum number of operations required to obtain a bamboo from the initial tree. In the next $$$k$$$ lines print $$$4$$$ integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$ ($$$1 \le x_1, y_1, x_2, y_{2} \le n$$$, $$$x_1 \neq y_1$$$, $$$x_2 \neq y_2$$$) — this way you remove the edge $$$(x_1, y_1)$$$ and add an undirected edge $$$(x_2, y_2)$$$. Note that the edge $$$(x_1, y_1)$$$ must be present in the graph at the moment of removing.

NoteNote the graph can be unconnected after a certain operation.Consider the first test case of the example:    The red edges are removed, and the green ones are added.

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in:=bufio.NewReader(os.Stdin)
	out:=bufio.NewWriter(os.Stdout)
	var T,n,v,w int
	for Fscan(in,&T);T>0;T--{
		Fscan(in,&n)
		g:=make([][]int,n+1)
		for i:=1;i<n;i++{Fscan(in,&v,&w);g[v]=append(g[v],w);g[w]=append(g[w],v)}
		rt:=1
		for len(g[rt])>1{rt++}
		a:=[][4]int{}
		var f func(int,int)int
		f=func(v,p int)int{
			c,x:=0,v
			for _,w:=range g[v]{
				if w!=p{
					if y:=f(w,v);y>0{
						if c++;c==1{
							x=y
						}else if c==2{
							a=append(a,[4]int{p,v,x,y})
							x=0
						}else{
							a=append(a,[4]int{v,w,w,y})
						}
					}
				}
			}
			return x
		}
		x:=f(rt,0)
		Fprintln(out,len(a))
		for _,p:=range a{Fprintln(out,p[0],p[1],x,p[2]);x=p[3]}
	}
	out.Flush()
}


Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes.  They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.

The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.

After each round, print the current score of the bears.

package main

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

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

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

	n, m, q := nextInt()+1, nextInt()+1, nextInt()
	grid := make([][]int, n)
	rowScores := make([]int, n)
	maxScoreIndex := 0

	for i := 1; i < n; i++ {
		grid[i] = make([]int, m)

		for j := 1; j < m; j++ {
			grid[i][j] = nextInt()
		}

		rowScores[i] = scoreRow(grid[i])
		if rowScores[i] > rowScores[maxScoreIndex] {
			maxScoreIndex = i
		}
		// println(maxScoreIndex, rowScores)
	}

	for ; q > 0; q-- {
		n, m = nextInt(), nextInt()
		grid[n][m] = 1 - grid[n][m]
		rowScores[n] = scoreRow(grid[n])

		if maxScoreIndex == n {
			for i := range rowScores {
				if rowScores[i] > rowScores[maxScoreIndex] {
					maxScoreIndex = i
				}
			}
		} else if rowScores[n] >= rowScores[maxScoreIndex] {
			maxScoreIndex = n
		}

		// println(rowScores[maxScoreIndex], maxScoreIndex, rowScores)
		println(rowScores[maxScoreIndex])
	}
}

func scoreRow(a []int) int {
	cnt := 0
	score := 0

	for i := 0; i < len(a); i++ {
		if a[i] == 1 {
			cnt++
		} else if cnt > 0 {
			score = max(score, cnt)
			cnt = 0
		}
	}

	if cnt > 0 {
		score = max(score, cnt)
	}

	return score
}

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

	return b
}

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

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

var scanner *bufio.Scanner

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

type Row struct {
  Data []int
  Key int
}

func maxSpan(data []int) int {
  max := 0
  span := data[0]
  m := len(data)
  for c := 1; c < m; c++ {
    if data[c] == 1 {
      span++
    } else {
      if span > max {
        max = span
      }
      span = 0
    }
  }
  if span > max {
    max = span
  }
  return max
}

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

  n, m, q := getI(), getI(), getI()
  rows := make([]*Row, n)
  for r := range rows {
    row := &Row{ make([]int, m), 0 }
    for c := range row.Data {
      row.Data[c] = getI()
    }
    row.Key = maxSpan(row.Data)
    rows[r] = row
  }
  for qi := 0; qi < q; qi++ {
    r, c := getI()-1, getI()-1
    row := rows[r]
    row.Data[c] ^= 1
    row.Key = maxSpan(row.Data)
    best := 0
    for _, row := range rows {
      if row.Key > best {
        best = row.Key
      }
    }
    writer.WriteString(fmt.Sprintf("%d\n", best))
  }
}

package main

import (
  "fmt"
)

func main(){
  var n,m,q int
  var b [501][501]int
  var largest [501]int
  fmt.Scan(&n,&m,&q)
  for i:=0;i<n;i++ {
    t := 0
    for j:=0;j<m;j++ {
      fmt.Scan(&b[i][j])
      if b[i][j] == 1 {
        t++
      }else{
        t=0
      }
      if t > largest[i] {
        largest[i] = t
      }
    }
  }
  for i:=0;i<q;i++ {
    var x,y,t int
    fmt.Scan(&x,&y)
    x--;y--;
    b[x][y] = 1 - b[x][y]
    largest[x] = 0
    for j:=0;j<m;j++ {
      if b[x][j] == 1 {
        t++
      }else{
        t=0
      }
      if t>largest[x] {
        largest[x] = t
      }
    }
    t = 0
    for j:=0;j<n;j++ {
      if largest[j]>t {
        t=largest[j]
      }
    }
    fmt.Println(t)
  }
}

package main

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

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

func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func getLine2Int3() (a, b, c int) {
	scanf("%d %d %d\n", &a, &b, &c)
	return
}
func getLine2Ints(n int) []int {
	ans := make([]int, n)
	for i := 0; i < n-1; i++ {
		scanf("%d ", &ans[i])
	}
	scanf("%d\n", &ans[n-1])
	return ans
}
func getLines2Ints(n, m int) [][]int {
	ans := make([][]int, n)
	for i := 0; i < n; i++ {
		ans[i] = getLine2Ints(m)
	}
	return ans
}
func updateMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func getMaxC(a []int) int {
	max, now := 0, 0
	for i := 0; i < len(a); i++ {
		if a[i] == 1 {
			now++
		} else {
			max = updateMax(max, now)
			now = 0
		}
	}
	max = updateMax(max, now)
	return max
}
func getMax(a []int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		max = updateMax(max, a[i])
	}
	return max
}
func main() {
	defer writer.Flush()

	n, m, q := getLine2Int3()
	a := getLines2Ints(n, m)
	b := getLines2Ints(q, 2)
	cnt := make([]int, n)
	for i := 0; i < n; i++ {
		cnt[i] = getMaxC(a[i])
	}
	for i := 0; i < q; i++ {
		x, y := b[i][0]-1, b[i][1]-1
		a[x][y] = 1 - a[x][y]
		cnt[x] = getMaxC(a[x])
		printf("%d\n", getMax(cnt))
	}
}

package main

import (
	"fmt"
)

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

func main() {
	var n, m, q int
	fmt.Scan(&n, &m, &q)
	var bears = make([][]int, n)
	for i := range bears {
		bears[i] = make([]int, m)
	}
	var count = make([]int, n)
	for i := range bears {
		count[i] = 0
		total := 0
		for j := range bears[i] {
			fmt.Scan(&bears[i][j])
			if bears[i][j] == 1 {
				total++
			} else {
				count[i] = max(count[i], total)
				total = 0
			}
		}
		if total != 0 {
			count[i] = max(count[i], total)
		}
	}
	for i := 0; i < q; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		a = a - 1
		b = b - 1
		if bears[a][b] == 1 {
			bears[a][b] = 0
		} else {
			bears[a][b] = 1
		}
		kount := 0
		maxim := 0
		for j := 0; j < m; j++ {
			if bears[a][j] == 1 {
				maxim = maxim + 1
			} else {
				kount = max(maxim, kount)
				maxim = 0
			}
		}
		if maxim != 0 {
			kount = max(kount, maxim)
		}
		count[a] = kount
		x := 0
		for t := range count {
			x = max(x, count[t])
		}
		fmt.Println(x)
	}

}

package main

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

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

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

	n, m, q := nextInt()+1, nextInt()+1, nextInt()
	grid := make([][]int, n)
	rowScores := make([]int, n)
	maxScoreIndex := 0

	for i := 1; i < n; i++ {
		grid[i] = make([]int, m)

		for j := 1; j < m; j++ {
			grid[i][j] = nextInt()
		}

		rowScores[i] = scoreRow(grid[i])
		if rowScores[i] > rowScores[maxScoreIndex] {
			maxScoreIndex = i
		}
		// println(maxScoreIndex, rowScores)
	}

	for ; q > 0; q-- {
		n, m = nextInt(), nextInt()
		grid[n][m] = 1 - grid[n][m]
		rowScores[n] = scoreRow(grid[n])

		if rowScores[n] >= rowScores[maxScoreIndex] {
			maxScoreIndex = n
		} else if maxScoreIndex == n {
			for i := range rowScores {
				if rowScores[i] > rowScores[maxScoreIndex] {
					maxScoreIndex = i
				}
			}
		}

		// println(rowScores[maxScoreIndex], maxScoreIndex, rowScores)
		println(rowScores[maxScoreIndex])
	}
}

func scoreRow(a []int) int {
	cnt := 0
	score := 0

	for i := 0; i < len(a); i++ {
		if a[i] == 1 {
			cnt++
		} else if cnt > 0 {
			score = max(score, cnt)
			cnt = 0
		}
	}

	if cnt > 0 {
		score = max(score, cnt)
	}

	return score
}

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

	return b
}

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

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

var scanner *bufio.Scanner

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

type Mask struct {
  Values []int
  Count int
}

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

  n, m, q := getI(), getI(), getI()
  masks := make([]*Mask, n)
  for r := range masks {
    mask := &Mask{ make([]int, m), 0 }
    for c := range mask.Values {
      x := getI()
      if x == 1 {
        mask.Count++
      }
      mask.Values[c] = x
    }
    masks[r] = mask
  }
  for qi := 0; qi < q; qi++ {
    r, c := getI()-1, getI()-1
    x := masks[r].Values[c] ^ 1
    masks[r].Values[c] = x
    if x == 0 {
      masks[r].Count--
    } else {
      masks[r].Count++
    }
    best := 0
    for _, mask := range masks {
      if mask.Count > best {
        best = mask.Count
      }
    }
    writer.WriteString(fmt.Sprintf("%d\n", best))
  }
}

package main

import (
	"fmt"
)

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

func main() {
	var n, m, q int
	fmt.Scan(&n, &m, &q)
	var bears = make([][]int, n)
	for i := range bears {
		bears[i] = make([]int, m)
	}
	var count = make([]int, n)
	for i := range bears {
		count[i] = 0
		total := 0
		for j := range bears[i] {
			fmt.Scan(&bears[i][j])
			if bears[i][j] == 1 {
				total++
			} else {
				count[i] = max(count[i], total)
				total = 0
			}
		}
		if total != 0 {
			count[i] = max(count[i], total)
		}
	}
	for i := 0; i < q; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		a = a - 1
		b = b - 1
		if bears[a][b] == 1 {
			bears[a][b] = 0
		} else {
			bears[a][b] = 1
		}
		kount := 0
		maxim := 0
		for j := 0; j < m; j++ {
			if bears[a][j] == 1 {
				maxim = maxim + 1
			} else {
				kount = max(maxim, kount)
				maxim = 0
			}
		}
		if maxim != 0 {
			kount = maxim
		}
		count[a] = kount
		x := 0
		for t := range count {
			x = max(x, count[t])
		}
		fmt.Println(x)
	}

}


There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).

For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".

package main

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

/* solution */

func solve() {

	t := readInt()
	for i := 0; i < t; i++ {
		solveOne()
	}

}

func solveOne() {
	n := readInt()
	a := readInt()
	ok := true
	for i := 1; i < n; i++ {
		b := readInt()
		d := b - a
		ok = ok && (d == -1 || d == 1 || d == n-1 || d == 1-n)
		a = b
	}
	if ok {
		print("YES")
	} else {
		print("NO")
	}
}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)
	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

package main

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

func isValid(max, current, next int, clockwise bool) bool {
	if clockwise {
		switch current {
		case max:
			if next != 1 {
				return false
			}
		default:
			if next != current+1 {
				return false
			}
		}
	} else {
		switch current {
		case 1:
			if next != max {
				return false
			}
		default:
			if next != current-1 {
				return false
			}
		}
	}

	return true
}

func evaluatePermutation(studentCount int, students []int) bool {
	if studentCount == 1 {
		return true
	}

	var clockwise bool
	if students[0]+1 == students[1] ||
		(students[0] == studentCount && students[1] == 1) {
		clockwise = true
	}

	current := students[0]
	for _, v := range students[1:] {
		status := isValid(studentCount, current, v, clockwise)
		//fmt.Printf("students: %v previous ID: %d curr ID: %d clockwise: %t status: %t\n",
		//	students, current, v, clockwise, status)
		if !status {
			return false
		}
		current = v
	}

	return true
}

func main() {
	var queryCount int
	_, err := fmt.Scanf("%d\n", &queryCount)
	if err != nil {
		panic(fmt.Sprintf("failed to get query count input, err: %v", err))
	}

	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < queryCount; i++ {
		studentInp, _, err := reader.ReadLine()
		if err != nil {
			panic(fmt.Sprintf("failed to get student count input, err: %v", err))
		}

		studentCount, err := strconv.Atoi(string(studentInp))
		if err != nil {
			panic(fmt.Sprintf("strconv: failed to get student count input, err: %v", err))
		}

		studentList, _,err := reader.ReadLine()
		if err != nil {
			panic(fmt.Sprintf("failed to get student list input, err: %v", err))
		}

		students := strings.Split(string(studentList), " ")
		if len(students) != studentCount {
			panic("input student count doesn't align with student list")
		}

		var inputStudents []int
		for _, v:= range students {
			inp, _ := strconv.Atoi(v)
			inputStudents = append(inputStudents, inp)
		}

		result := evaluatePermutation(studentCount, inputStudents)
		//fmt.Printf("Query #: %d student count: %d student-list: %#v result: %t\n",
		//	i+1, studentCount, students, result)
		if result {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func isOrder(sts *[]int) bool {
	var g bool
	stsT := *sts

	if stsT[1] > stsT[0] {
		g = true
	} else {
		g = false
	}

	for i := 1; i < len(*sts); i += 1 {
		if g && stsT[i]-stsT[i-1] != 1 {
			return false
		}
		if !g && stsT[i-1]-stsT[i] != 1 {
			return false
		}
	}
	return true
}

func offset(sts *[]int) *[]int {
	stsT := *sts
	tmp := stsT[len(stsT)-1]
	for i := len(stsT) - 1; i > 0; i -= 1 {
		stsT[i] = stsT[i-1]
	}
	stsT[0] = tmp
	return &stsT
}

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

	var (
		total int
		n     int
	)

	_, _ = fmt.Fscan(input, &total)

	for t := 0; t < total; t += 1 {
		_, _ = fmt.Fscan(input, &n)

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

		if n < 2 {
			fmt.Println("YES")
			continue
		}

		isCW := false
		for i := 0; i < n; i += 1 {
			if isOrder(offset(&sts)) {
				isCW = true
				break
			}
		}
		if isCW {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}

}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var testCase int

	_, err := fmt.Fscanf(input, "%d\n", &testCase)
	if err != nil {
	}

	for testCase > 0 {
		testCase--

		var n int
		_, err := fmt.Fscanf(input, "%d\n", &n)
		if err != nil {
		}

		var p = make([]int, n)
		for i := 0; i < n; i++ {
			_, err := fmt.Fscanf(input, "%d", &p[i])
			if err != nil {
			}
		}
		_, err = fmt.Fscanf(input, "\n")
		if err != nil {
		}
		if checkClockwise(n, p) || checkCounterclockwise(n, p) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func checkClockwise(len int, positions []int) bool {
	reset := 0
	for i := 1; i < len; i++ {
		if positions[i] != positions[i - 1] + 1 {
			reset++
			if reset > 1 {
				return false
			}
		}
	}
	return true
}

func checkCounterclockwise(len int, positions []int) bool {
	reset := 0
	for i := 1; i < len; i++ {
		if positions[i] != positions[i - 1] - 1 {
			reset++
			if reset > 1 {
				return false
			}
		}
	}
	return true
}

package main

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

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

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

	var Q int
	fmt.Fscanf(input, "%d\n", &Q)
	for q := 0; q < Q; q++ {
		var N int
		fmt.Fscanf(input, "%d\n", &N)
		P := make([]int, N)
		for n := 0; n < N; n++ {
			fmt.Fscanf(input, "%d", &P[n])
		}
		fmt.Fscanf(input, "\n")

		cw := true
		ccw := true
		for n := 0; n < N; n++ {
			if (P[(n+1)%N]-P[n]+N)%N != 1 {
				cw = false
			}
			if (P[(n+1)%N]-P[n]+N)%N != N-1 {
				ccw = false
			}
		}
		if cw || ccw {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func roundDance(students []int, count int) string {
	if count == 1 {
		return "YES"
	}

	var iPos int
	for i, v := range students {
		if v == 1 {
			iPos = i
		}
	}
	okl := true
	okr := true
	for i := 1; i < count; i++ {
		okl = okl && students[(iPos-i+count)%count] == i+1
	}
	for i := 1; i < count; i++ {
		okr = okr && students[(iPos+i+count)%count] == i+1
	}
	if okl || okr {
		return "YES"
	} else {
		return "NO"
	}
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	var studentCount int
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &studentCount)
		students := make([]int, studentCount)
		for j := 0; j < studentCount; j++ {
			fmt.Fscan(r, &students[j])
		}
		fmt.Println(roundDance(students, studentCount))
	}
}

package main

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

func settest() (*os.File, *os.File) {
	f, err := os.Open("a.dat")
	if err != nil {
		panic(err)
	}

	oldStdin := os.Stdin
	os.Stdin = f

	return f, oldStdin
}

func main() {
	/*f, oldStdin := settest()
	defer f.Close()
	defer func() { os.Stdin = oldStdin }()*/

	q, i := 0, 0
	fmt.Scan(&q)

	for ;q > 0; q-- {
		fmt.Scan(&i)
		a := make([]int, i)
		for n := 0; n < i; n++ {
			fmt.Scan(&a[n])
		}

		ok := true
		for n := 1; n < i; n++ {
			k := math.Abs(float64(a[n] - a[n - 1]))
			if k != 1 && k != float64(i - 1) {
				ok = false
				fmt.Println("NO")
				break
			}
		}

		if ok {
			fmt.Println("YES")
		}
	}
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var testCase int

	_, err := fmt.Fscanf(input, "%d\n", &testCase)
	if err != nil {
	}

	for testCase > 0 {
		testCase--

		var n int
		_, err := fmt.Fscan(input, &n)
		if err != nil {
		}

		var p = make([]int, n)

		for i := 0; i < n; i++ {
			_, err := fmt.Fscan(input, &p[i])
			if err != nil {
			}
		}

		if n == 1 {
			fmt.Println("YES")
			continue
		}

		//fmt.Println(n)
		//var ins = -1
		//var result = true
		//if p[0] == p[1]-1 || (p[0] == n && p[1] == 1) {
		//	// 判断升序
		//	ins = 1
		//}
		//for i := 1; i < n; i++ {
		//	if p[i-1] == n && ins == 1 {
		//		if p[i] != 1 {
		//			result = false
		//			break
		//		}
		//		continue
		//	}
		//	if p[i-1] == 1 && ins == -1 {
		//		if p[i] != n {
		//			result = false
		//			break
		//		}
		//		continue
		//	}
		//	if p[i] != p[i-1]+ins {
		//		result = false
		//		break
		//	}
		//}
		var rresult = true
		var iresult = true
		for i := 1; i < n; i++ {
			if p[i-1] == n {
				if p[i] != 1 {
					rresult = false
					break
				}
				continue
			}
			if p[i] != p[i-1]+1 {
				rresult = false
				break
			}
		}
		for i := 1; i < n; i++ {
			if p[i-1] == 1 {
				if p[i] != n {
					iresult = false
					break
				}
				continue
			}
			if p[i] != p[i-1]-1 {
				iresult = false
				break
			}
		}
		if iresult == false && rresult == false {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}

	}

}

package main
import "fmt"

func check(x []int, n int, d int) bool {
	for i:=1; i<n; i++ {
		if x[i]==x[i-1]+d {
			continue
		}
		return false
	}
	return true
}

func solve() {
	var n int
	fmt.Scan(&n)
	arr := make([]int, 2*n+1)
	for i:=1; i<=n; i++ {
		fmt.Scan(&arr[i])
		arr[i+n]=arr[i]
	}
	for i:=1; i<=n; i++ {
		if check(arr[i:i+n], n, 1) || check(arr[i:i+n], n, -1) {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

func main(){

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

}

package main

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

func main() {

	//stdin, err := os.Open("in.txt")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("test.txt")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)

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

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

		a := make([]int, n, n)
		l, r := 0, 0
		for j := 0; j < n; j++ {
			fmt.Fscanf(reader, "%d", &a[j])
			if j > 0 {
				if a[j] > a[j-1] {
					r++
				} else {
					l++
				}
			}
			if j == n-1 {
				if a[j] < a[0] {
					r++
				} else {
					l++
				}
			}
		}
		if l <= 1 || r <= 1 {
			fmt.Fprintf(writer, "YES\n")
		} else {
			fmt.Fprintf(writer, "NO\n")
		}
		fmt.Fscanf(reader, "\n")
	}

	writer.Flush()
}

package main

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

/* solution */

func solve() {

	t := readInt()
	for i := 0; i < t; i++ {
		solveOne()
	}

}

func solveOne() {
	n := readInt()
	a := readInt()
	ok := true
	d := 0
	for i := 1; i < n; i++ {
		b := readInt()
		if d == 0 {
			d = b - a
			if d == n-1 || d == 1-n {
				d /= 1 - n
			}
			if d != 1 && d != -1 {
				ok = false
				break
			}
		}
		ok = ok && ((b-a == d) || (d == 1 && a == n && b == 1) || (d == -1 && a == 1 && b == n))
		a = b
	}
	if ok {
		print("YES")
	} else {
		print("NO")
	}
}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)
	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

package main

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

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

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

	var Q int
	fmt.Fscanf(input, "%d\n", &Q)
	for q := 0; q < Q; q++ {
		var N int
		fmt.Fscanf(input, "%d\n", &N)
		P := make([]int, N)
		for n := 0; n < N; n++ {
			fmt.Fscanf(input, "%d", &P[n])
		}
		fmt.Fscanf(input, "\n")

		diff := make(map[int]int)
		for n := 0; n < N; n++ {
			diff[abs(P[n%N]-P[(n+1)%N])]++
		}
		if diff[1] == N-1 && diff[N-1] == 1 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

func roundDance(students []int, count int) string {
	if count == 1 {
		return "YES"
	}

	var iPos int
	for i, v := range students {
		if v == 1 {
			iPos = i
		}
	}
	okl := true
	okr := true
	for i := 1; i < count; i++ {
		okl = okl && students[(iPos-i+count)%count] == i+1
	}
	for i := 1; i < count; i++ {
		okr = okr && students[(iPos+i+count)%count] == i+1
	}
	if okl || okr {
		return "YES"
	} else {
		return "NO"
	}
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	var studentCount int
	for i := 0; i < n; i++ {
		fmt.Scanf("%d\n", &studentCount)
		students := make([]int, studentCount)
		for j := 0; j < studentCount; j++ {
			fmt.Scanf("%d", &students[j])
		}
		fmt.Println(roundDance(students, studentCount))
	}
}

package main

import "fmt"

func roundDance(students []int, count int) string {
	if count == 1 {
		return "YES"
	}
	direction := students[0] - students[1]
	if direction == -2 {
		direction = 1

	}
	// decreasing, clockwise
	var diff int
	if direction < 0 {
		for i := 1; i < count; i++ {
			diff = students[i] - students[i-1]
			if diff > 0 && diff != 1 {
				return "NO"
			}
		}
	} else {
		for i := 1; i < count; i++ {
			diff = students[i] - students[i-1]
			if diff < 0 && diff != -1 {
				return "NO"
			}
		}
	}
	return "YES"
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	var studentCount int
	for i := 0; i < n; i++ {
		fmt.Scanf("%d\n", &studentCount)
		students := make([]int, studentCount)
		for j := 0; j < studentCount; j++ {
			fmt.Scanf("%d", &students[j])
		}
		fmt.Println(roundDance(students, studentCount))
	}
}

package main

import (
	"fmt"
	"os"
)

func settest() (*os.File, *os.File) {
	f, err := os.Open("a.dat")
	if err != nil {
		panic(err)
	}

	oldStdin := os.Stdin
	os.Stdin = f

	return f, oldStdin
}

func main() {
	/*f, oldStdin := settest()
	defer f.Close()
	defer func() { os.Stdin = oldStdin }()*/

	q, i := 0, 0
	fmt.Scan(&q)

	for ;q > 0; q-- {
		fmt.Scan(&i)
		a := make([]int, i)
		for n := 0; n < i; n++ {
			fmt.Scan(&a[n])
		}

		ar := true
		br := true

		for n := 0; n < i - 1; n++ {
			if ar && a[n] > a[n + 1] {
				ar = false
			}

			if br && a[n] < a[n + 1] {
				if !(a[n] == 1 && a[n + 1] == i) {
					br = false
				}
			}

			if !ar && !br {
				break
			}
		}

		if ar || br {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
	"os"
)

func settest() (*os.File, *os.File) {
	f, err := os.Open("a.dat")
	if err != nil {
		panic(err)
	}

	oldStdin := os.Stdin
	os.Stdin = f

	return f, oldStdin
}

func main() {
	/*f, oldStdin := settest()
	defer f.Close()
	defer func() { os.Stdin = oldStdin }()*/

	q, i := 0, 0
	fmt.Scan(&q)

	for ;q > 0; q-- {
		fmt.Scan(&i)
		a := make([]int, i)
		for n := 0; n < i; n++ {
			fmt.Scan(&a[n])
		}

		ar := true
		br := true

		for n := 1; n < i; n++ {
			if ar && !(a[n] != a[n - 1] + 1) {
				ar = false
			}

			if br {
				if !((n == 1 && a[n] == 1) || (a[n] != a[n - 1] - 1)) {
					br = false
				}
			}

			if !ar && !br {
				break
			}
		}

		if ar || br {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
	"os"
)

func settest() (*os.File, *os.File) {
	f, err := os.Open("a.dat")
	if err != nil {
		panic(err)
	}

	oldStdin := os.Stdin
	os.Stdin = f

	return f, oldStdin
}

func main() {
	/*f, oldStdin := settest()
	defer f.Close()
	defer func() { os.Stdin = oldStdin }()*/

	q, i := 0, 0
	fmt.Scan(&q)

	for ;q > 0; q-- {
		fmt.Scan(&i)
		a := make([]int, i)
		for n := 0; n < i; n++ {
			fmt.Scan(&a[n])
		}

		ar := true
		br := true

		for n := 1; n < i; n++ {
			if ar && a[n] < a[n - 1] {
				ar = false
			}

			if br {
				if n != 2 && a[n - 1] > a[n] {
					br = false
				}
			}

			if !ar && !br {
				break
			}
		}

		if ar || br {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}


Let $$$s$$$ be a string of lowercase Latin letters. Its price is the sum of the indices of letters (an integer between 1 and 26) that are included in it. For example, the price of the string abca is $$$1+2+3+1=7$$$.The string $$$w$$$ and the integer $$$p$$$ are given. Remove the minimal number of letters from $$$w$$$ so that its price becomes less than or equal to $$$p$$$ and print the resulting string. Note that the resulting string may be empty. You can delete arbitrary letters, they do not have to go in a row. If the price of a given string $$$w$$$ is less than or equal to $$$p$$$, then nothing needs to be deleted and $$$w$$$ must be output.Note that when you delete a letter from $$$w$$$, the order of the remaining letters is preserved. For example, if you delete the letter e from the string test, you get tst.

The first line of input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The following are descriptions of $$$t$$$ test cases. Each case consists of two lines. The first of them is the string $$$w$$$, it is non-empty and consists of lowercase Latin letters. Its length does not exceed $$$2\cdot10^5$$$. The second line contains an integer $$$p$$$ ($$$1 \le p \le 5\,200\,000$$$). It is guaranteed that the sum of string lengths $$$w$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

Output exactly $$$t$$$ rows, the $$$i$$$-th of them should contain the answer to the $$$i$$$-th set of input data. Print the longest string that is obtained from $$$w$$$ by deleting letters such that its price is less or equal to $$$p$$$. If there are several answers, then output any of them. Note that the empty string  — is one of the possible answers. In this case, just output an empty string.

5

abca

2

abca

6

codeforces

1

codeforces

10

codeforces

100

package main

import (
	"fmt"
	"sort"
)

const (
	totalLetters      = 24
	startVal     rune = 97
	endVal       rune = startVal + 24
)

func cost(v rune) int {
	return int(v-startVal) + 1
}

func main() {
	var (
		t int
		w string
		p int
	)

	fmt.Scanln(&t)

	for i := 0; i < t; i++ {
		fmt.Scanln(&w)
		fmt.Scanln(&p)

		solve(w, p)
	}
}

func solve(w string, p int) {
	currentCost := 0

	s := []rune(w)
	sort.Slice(s, func(i, j int) bool {
		return s[i] > s[j]
	})

	for _, l := range w {
		currentCost += cost(l)
	}

	if currentCost <= p {
		fmt.Println(w)
		return
	}

	del := make(map[rune]int)
	for _, r := range s {
		if currentCost <= p {
			break
		}

		del[r]++
		currentCost -= cost(r)
	}

	for _, r := range w {
		if del[r] > 0 {
			del[r]--
			continue
		}
		fmt.Print(string(r))
	}

	fmt.Println()
}

// 1702D. Not a Cheap String
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var s string
		fmt.Fscan(reader, &s)
		// s = strings.TrimSpace(s)
		var p int
		fmt.Fscan(reader, &p)
		total := 0
		m := make(map[int]int)
		for i := 0; i < len(s); i++ {
			val := int(s[i] - 'a' + 1)
			m[val]++
			total += val
		}

		if total > p {
			for i := 26; i > 0; i-- {
				if m[i] > 0 {
					if m[i]*i <= total-p {
						total -= m[i] * i
						m[i] = 0
					} else {
						rm := (total - p) / i
						if (total-p)%i != 0 {
							rm++
						}
						m[i] -= rm
						total -= rm * i
					}
					if total <= p {
						break
					}
				}
			}
		}

		l := make([]byte, 0)
		for i := 0; i < len(s); i++ {
			val := int(s[i] - 'a' + 1)
			if m[val] > 0 {
				l = append(l, s[i])
				m[val]--
			}
		}
		fmt.Println(string(l))
	}
}

package main

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

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

	numCases := 0
	fmt.Fscan(in, &numCases)

	for ; numCases > 0; numCases-- {
		w := ""
		fmt.Fscan(in, &w)

		p := 0
		fmt.Fscan(in, &p)

		strCost := 0
		for _, r := range w {
			strCost += int(r - 'a' + 1)
		}

		sorted := []rune(w)
		sort.Slice(sorted, func(i, j int) bool {
			return sorted[i] > sorted[j]
		})

		runesToRemove := make(map[rune]int)
		for _, s := range sorted {
			if strCost > p {
				strCost -= int(s - 'a' + 1)
				runesToRemove[s]++
			} else {
				break
			}
		}

		runes := []rune(w)
		for i, r := range runes {
			if cnt, ok := runesToRemove[r]; ok && cnt > 0 {
				runes[i] = 0
				runesToRemove[r]--
			}
		}

		for _, r := range runes {
			if r == 0 {
				continue
			}
			fmt.Fprintf(out, "%c", r)
		}
		fmt.Fprint(out, "\n")

	}
}

package main

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

const firstLetter = 'a' - 1

//1
//zzcd
//52
func main() {
	var in = bufio.NewReader(os.Stdin)

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

	for ; testNum > 0; testNum-- {
		var s string
		fmt.Fscan(in, &s)

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

		var w int
		for _, l := range s {
			v := int(l - firstLetter)
			w += v
		}

		d := p - w
		if d >= 0 {
			fmt.Println(s)
			continue
		}

		ss := []rune(s)
		sort.Slice(ss, func(i, j int) bool {
			return ss[i] > ss[j]
		})

		del := make(map[rune]int, 10)
		for _, sss := range ss {
			if w > p {
				w -= int(sss - firstLetter)
				del[sss]++
			} else {
				break
			}
		}

		se := []rune(s)
		for i, v := range se {
			if vv, ok := del[v]; ok && vv > 0 {
				del[v]--
				se[i] = 0
			}
		}

		res := make([]rune, 0, len(se))
		for _, ss := range se {
			if ss != 0 {
				res = append(res, ss)
			}
		}

		fmt.Println(string(res))
	}
}

package main

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

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

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

		aa := make([]int, 26)
		var tot int
		for _, ch := range s {
			aa[ch-'a']++
			tot += int(ch-'a') + 1
		}

		for i := 25; i >= 0; i-- {
			if tot <= n {
				break
			}

			d := min(aa[i], (tot-n+(i+1)-1)/(i+1))
			aa[i] -= d
			tot -= d * (i + 1)
		}

		var buf bytes.Buffer
		for _, ch := range s {
			if aa[ch-'a'] > 0 {
				aa[ch-'a']--
				buf.WriteRune(ch)
			}
		}
		fmt.Fprintln(out, buf.String())
	}
}

package main

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

func solve(in io.Reader, out io.Writer) {
	var str string
	var point, sum int
	fmt.Fscan(in, &str, &point)
	var cnts [26]int
	for i := 0; i < len(str); i++ {
		sum += int(str[i]-'a') + 1
		cnts[int(str[i]-'a')]++
	}
	index := 25
	for sum > point {
		if cnts[index] == 0 {
			index--
		} else {
			sum -= index + 1
			cnts[index]--
		}
	}
	ans := []byte{}
	for i := 0; i < len(str); i++ {
		if cnts[int(str[i])-'a'] > 0 {
			ans = append(ans, str[i])
			cnts[int(str[i])-'a']--
		}
	}
	fmt.Fprintln(out, string(ans))
}

func main() {
	in := bufio.NewReader(os.Stdin)
	// in, _ := os.Open("in.txt")
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		solve(in, os.Stdout)
		t--
	}
}

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
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var s string
	var n int
	fmt.Fscan(rr, &s, &n)
	cnt := make([]int, 26)
	sum := 0
	minus := make([]int, 26)
	for i := range s {
		sum += int(s[i]-'a') + 1
		cnt[s[i]-'a']++
	}
	i := 25
	for sum > n {
		for cnt[i] == 0 {
			i--
		}
		cnt[i]--
		sum -= i+1
		minus[i]++
	}
	ans := make([]byte, 0)
	for i := range s {
		if minus[s[i]-'a'] > 0 {
			minus[s[i]-'a']--
			continue
		} else {
			ans = append(ans, s[i])
		}
	}
	fmt.Fprintln(ww, string(ans))

}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

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

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

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var s string
		var m int
		fmt.Fscan(r, &s, &m)
		w1 := do(s, m)
		fmt.Fprintln(w, w1)
	}
}

func do(s string, p int) string {
	m := [27]int{}
	q := 0
	for _, c := range s {
		v := int(c-'a') + 1
		m[v]++
		q += v
	}
	for i := 26; i >= 1; i-- {
		d := q - p
		x := d / i
		y := d % i
		if y > 0 {
			x++
		}
		if x > m[i] {
			x = m[i]
		}
		q -= x * i
		m[i] -= x
	}
	sb := strings.Builder{}
	for _, c := range s {
		v := int(c-'a') + 1
		if m[v] > 0 {
			sb.WriteRune(c)
			m[v]--
		}
	}
	return sb.String()
}

package main

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

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

type Tint interface {
	int | int32 | int64
}

func min[T Tint](x, y T) T {
	if x <= y {
		return x
	}
	return y
}
func max[T Tint](x, y T) T {
	if x >= y {
		return x
	}
	return y
}
func main() {
	defer _w.Flush()

	var _t int
	// n = 1
	fmt.Fscan(_r, &_t)
	for ; _t > 0; _t-- {
		s, p := "", 1
		fmt.Fscan(_r, &s, &p)
		a := make([]int, 0)
		for i := range s {
			a = append(a, int(s[i]-'a'+1))
		}
		for i := range a {
			a[i] = -a[i]
		}
		sort.Ints(a)
		for i := range a {
			a[i] = -a[i]
		}
		pre := make([]int, len(a)+1)
		for i := 1; i < len(pre); i++ {
			pre[i] = pre[i-1] + a[i-1]
		}
		l, r := 0, len(pre)-1
		pos := len(pre) - 1
		for l <= r {
			mid := (l + r) >> 1
			if ck(mid, pre, p) {
				pos = mid
				r = mid - 1
			} else {
				l = mid + 1
			}
		}
		if pos <= 0 {
			fmt.Fprintln(_w, s)
			continue
		}
		mp := make(map[int]int)
		for i := 1; i <= pos; i++ {
			v := a[i-1] + 'a' - 1
			if _, ok := mp[v]; !ok {
				mp[v] = 0
			}
			mp[v]++
		}
		//fmt.Println(mp, pre[len(pre)-1]-pre[0])
		res := ""
		for _, v := range s {
			if _, ok := mp[int(v)]; !ok {
				res += string(v)
				continue
			}
			if mp[int(v)] <= 0 {
				res += string(v)
				continue
			}
			mp[int(v)]--
		}
		fmt.Fprintln(_w, res)
	}
}
func ck(mid int, pre []int, p int) bool {
	return pre[len(pre)-1]-pre[mid] <= p
}

package main

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

type Struct struct {
	index int
	value int
}

func solve(str string, p int) string {
	totalSum := 0
	mapping := make([]*Struct, len(str))
	for i, ch := range str {
		value := int(ch - 'a' + 1)
		totalSum += value
		mapping[i] = &Struct{index: i, value: value}
	}

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

	i := 0
	mark := map[int]bool{}
	for totalSum > p {
		if i == len(str) {
			break
		}
		totalSum -= mapping[i].value
		mark[mapping[i].index] = true
		i++
	}

	res := []rune{}
	for i, ch := range str {
		if _, ok := mark[i]; ok {
			continue
		}
		res = append(res, ch)
	}

	return string(res)
}

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

	var test int
	fmt.Fscanln(inp, &test)

	for test > 0 {
		test--

		var str string
		fmt.Fscanln(inp, &str)
		var p int
		fmt.Fscanln(inp, &p)

		res := solve(str, p)
		fmt.Fprintln(out, res)
	}

	out.Flush()
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t int
	fmt.Scanln(&t)

	for i := 0; i < t; i++ {
		var w string
		fmt.Scanln(&w)

		var p int
		fmt.Scanln(&p)

		fmt.Println(Soln(w, p))
	}
}

func Soln(w string, p int) string {
	s := []rune(w)
	sort.Slice(s, func(i int, j int) bool { return s[i] > s[j] })

	priceOf := func(c rune) int {
		return int(c-'a') + 1
	}

	cost := 0
	for _, c := range s {
		cost += priceOf(c)
	}

	m := map[rune]int{}
	for _, c := range s {
		if cost > p {
			m[c]++
			cost -= priceOf(c)
		}
	}

	res := []rune{}
	for _, c := range w {
		if m[c] > 0 {
			m[c]--
			continue
		}
		res = append(res, c)
	}

	return string(res)
}

package main

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

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

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

func main() {

	defer writer.Flush()
	var tc int
	var s string
	var p int

	scanws(&tc)
	for t := 1; t <= tc; t++ {
		scanws(&s)
		scanws(&p)
		n := len(s)
		var cnt [27]int
		for i := 0; i < 27; i++ {
			cnt[i] = 0
		}
		val := 0
		for i := 0; i < n; i++ {
			temp := int(s[i] - 'a' + 1)
			cnt[temp]++
			val += temp
		}
		for i := 26; i >= 1; i-- {
			for cnt[i] > 0 {
				if val > p {
					val -= i
					cnt[i]--
				}
				if val <= p {
					break
				}
			}
			if val <= p {
				break
			}
		}
		var ans string = ""
		for i := 0; i < n; i++ {
			temp := int(s[i] - 'a' + 1)
			if cnt[temp] > 0 {
				ans = ans + string(s[i])
				cnt[temp]--
			}
		}
		printf("%s\n", ans)
	}
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		w := readString(reader)
		p := readNum(reader)
		res := solve(w, p)
		buf.WriteString(fmt.Sprintf("%s\n", res))
	}

	fmt.Print(buf.String())
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' || s[i] == '\r' {
			return s[:i]
		}
	}
	return s
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

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

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

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

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

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

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

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

	return i
}

func solve(w string, p int) string {
	cnt := make([]int, 27)
	for i := 0; i < len(w); i++ {
		cnt[int(w[i]-'a'+1)]++
	}

	var sum int
	for i := 1; i <= 26; i++ {
		left := p - sum
		x := min(left/i, cnt[i])
		cnt[i] = x
		sum += i * x
	}

	var buf bytes.Buffer

	for i := 0; i < len(w); i++ {
		x := int(w[i] - 'a' + 1)
		if cnt[x] > 0 {
			buf.WriteByte(w[i])
			cnt[x]--
		}
	}

	return buf.String()
}

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

package main

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

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

func (in *CF1702D) 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 *CF1702D) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1702D
Date: 27/07/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1702/D
Problem: CF1702D
**/
func (in *CF1702D) Run() {
	for t := in.NextInt(); t > 0; t-- {
		str := in.NextString()
		p := in.NextInt()
		m := make([][]int, 27)

		totalSum := 0
		for i := 0; i < len(str); i++ {
			val := int(str[i] - 'a')
			arr := m[val]
			if arr == nil {
				arr = make([]int, 0)
			}
			arr = append(arr, i+1)
			m[val] = arr
			totalSum += val + 1
		}

		if totalSum <= p {
			fmt.Println(str)
		} else {
			for i := len(m) - 1; i >= 0; i-- {
				if m[i] != nil {
					letter := i + 1
					ws := false
					for j := 0; j < len(m[i]); j++ {
						totalSum -= letter
						m[i][j] = -1

						if totalSum <= p {
							ws = true
							break
						}
					}
					if ws {
						break
					}
				}
			}

			ans := make([]uint8, len(str))
			for i := 0; i < len(m); i++ {
				if m[i] != nil {
					for j := 0; j < len(m[i]); j++ {
						if m[i][j] > 0 {
							ans[m[i][j]-1] = uint8(i + 'a')
						}
					}
				}
			}

			var solve strings.Builder
			for i := 0; i < len(ans); i++ {
				if ans[i] != 0 {
					solve.WriteString(string(ans[i]))
				}
			}
			fmt.Println(solve.String())
		}

	}
}

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

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

package main

import "fmt"

func solve() {
	var s string
	var p int

	fmt.Scan(&s)
	fmt.Scan(&p)

	var sum int
	for _, x := range s { sum += int(x-'a'+1) }

	var char_count map[rune]int = map[rune]int{}
	for _, x := range s { char_count[x]++ }

	var char_remove map[rune]int = map[rune]int{}
	for i:='z'; sum > p && i >='a'; {
		if char_count[i] > 0 {
			char_remove[i]++
			char_count[i]--
			sum -= int(i-'a'+1)
		} else { i-- }
	}

	for _, x := range s {
		if char_remove[x] > 0 { char_remove[x]-- } else { fmt.Printf("%c", x) }
	}

	fmt.Println()

	// fmt.Println(char_count)
	// fmt.Println(char_remove)

}

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

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

}

package main

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

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

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

	var T int
	var s string
	var p int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &s)
		Fscan(in, &p)

		c := [27]int{}
		sum := 0
		for _, v := range s {
			c[v-'a'+1]++
			sum += int(v - 'a' + 1)
		}
		for sum > p {
			for i := 26; i > 0; i-- {
				if c[i] == 0 {
					continue
				}
				if sum-c[i]*i > p {
					sum -= c[i] * i
					c[i] = 0
				} else {
					c[i] -= (sum - p) / i
					if (sum-p)%i != 0 {
						c[i]--
					}
					sum = -1
					break
				}
			}
		}

		sb := []byte(s)
		ans := []byte{}
		for _, v := range sb {
			if c[v-'a'+1] > 0 {
				c[v-'a'+1]--
				ans = append(ans, v)
			}
		}

		Fprintln(out, string(ans))
	}
}

package main

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

type index struct{
  v, i int64
}

type indexSlice []index

func (a indexSlice) Len() int {
  return len(a)
}

func (a indexSlice) Less(i, j int) bool {
  return a[i].v > a[j].v
}

func (a indexSlice) Swap(i, j int) {
  a[i], a[j] = a[j], a[i]
}

func solve(sc *bufio.Scanner, wr *bufio.Writer) {
  w := []rune(str(sc))
  p := get(sc)
  a := make(indexSlice, len(w))
  for i, v := range w {
    a[i] = index{int64(v) - int64(rune('a')) + 1, int64(i)}
  }
  sort.Sort(a)
  sum := int64(0)
  for _, x := range a {
    sum += x.v
  }

  used := make([]bool, len(w))
  for _, x := range a {
    if sum <= p {
      break
    }
    used[x.i] = true
    sum -= x.v
  }

  for i, r := range w {
    if !used[i] {
      wr.WriteRune(r)
    }
  }
  line(wr)
}

const (
  once = false
  maxBufSize = 10000000
)

func main() {
  sc := bufio.NewScanner(bufio.NewReader(os.Stdin))
  sc.Split(bufio.ScanWords)
  sc.Buffer(make([]byte, maxBufSize), maxBufSize)

  wr := bufio.NewWriter(os.Stdout)
  defer wr.Flush()

  if once {
    solve(sc, wr)
  } else {
    times := get(sc)
    for times > 0 {
      solve(sc, wr)
      times--
    }
  }
}

func get(sc *bufio.Scanner) int64 {
  x, _ := strconv.ParseInt(str(sc), 10, 64)
  return x
}

func str(sc *bufio.Scanner) string {
  sc.Scan()
  return sc.Text()
}

func put(wr *bufio.Writer, i int64) {
  wr.WriteString(strconv.FormatInt(i, 10))
}

func line(wr *bufio.Writer) {
  wr.WriteRune('\n')
}

func space(wr *bufio.Writer) {
  wr.WriteRune(' ')
}

package main

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

func A2() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var p int
		var s string
		Fscan(in, &s)
		Fscan(in, &p)
		pos := make([][]int, 26)
		var cur int
		for i := 0; i < len(s); i++ {
			cur += int(s[i] - 97 + 1)
			pos[s[i]-97] = append(pos[s[i]-97], i)
		}
		vis := map[int]bool{}

		for i := 0; i < 26; i++ {
			var j int
			for cur > p && j < len(pos[25-i]) {
				vis[pos[25-i][j]] = true
				j++
				cur -= (26 - i)
			}
			if cur <= p {
				break
			}
		}
		ans := []byte{}
		for i := 0; i < len(s); i++ {
			if !vis[i] {
				ans = append(ans, s[i])
			}
		}
		Fprintln(out, string(ans))
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A2() }

package main

import (
	"fmt"
)

const (
	totalLetters      = 24
	startVal     rune = 97
	endVal       rune = startVal + 24
)

func cost(v rune) int {
	return int(v-startVal) + 1
}

func main() {
	var (
		t int
		w string
		p int
	)

	fmt.Scanln(&t)

	for i := 0; i < t; i++ {
		fmt.Scanln(&w)
		fmt.Scanln(&p)

		solve(w, p)
	}
}

func solve(w string, p int) {
	currentCost := 0

	countedLetters := make(map[rune]int, totalLetters)
	for _, l := range w {
		currentCost += cost(l)
		countedLetters[l]++
	}

	if currentCost <= p {
		fmt.Println(w)
	}

	latest := endVal
	skipMap := make(map[rune]int)
	for currentCost > p {
		left, ok := countedLetters[latest]
		if !ok || left == 0 {
			latest--
			continue
		}

		skipMap[latest]++
		countedLetters[latest]--

		currentCost -= cost(latest)
	}

	for _, l := range w {
		if left, ok := skipMap[l]; !ok || left == 0 {
			fmt.Print(string(l))
		} else {
			skipMap[l]--
		}
	}
	fmt.Println()
}

// 1702D. Not a Cheap String
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var s string
		fmt.Fscan(reader, &s)
		s = strings.TrimSpace(s)
		var p int
		fmt.Fscan(reader, &p)
		total := 0
		m := make(map[int]int)
		for i := 0; i < len(s); i++ {
			val := int(s[i] - 'a' + 1)
			m[val]++
			total += val
		}

		if total > p {
			for i := 26; i > 0; i-- {
				if m[i] > 0 {
					if m[i]*i <= total-p {
						total -= m[i] * i
						m[i] = 0
					} else {
						rm := (total - p) / i
						m[i] -= rm
						total -= rm * i
					}
					if total <= p {
						break
					}
				}
			}
		}
		if total > p {
			for i := 1; i <= 26; i++ {
				if m[i] > 0 {
					m[i]--
					break
				}
			}
		}
		l := make([]byte, 0)
		for i := 0; i < len(s); i++ {
			val := int(s[i] - 'a' + 1)
			if m[val] > 0 {
				l = append(l, s[i])
				m[val]--
			}
		}
		fmt.Println(string(l))
	}
}

// 1702D. Not a Cheap String
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var s string
		fmt.Fscan(reader, &s)
		var p int
		fmt.Fscan(reader, &p)
		total := 0
		m := make(map[int]int)
		for i := 0; i < len(s); i++ {
			val := int(s[i] - 'a' + 1)
			m[val]++
			total += val
		}

		if total > p {
			for i := 26; i > 0; i-- {
				if m[i] > 0 {
					if m[i]*i <= total-p {
						total -= m[i] * i
						m[i] = 0
					} else {
						rm := (total - p) / i
						m[i] -= rm
						total -= rm * i
					}
					if total <= p {
						break
					}
				}
			}
		}
		if total > p {
			for i := 1; i <= 26; i++ {
				if m[i] > 0 {
					m[i]--
					break
				}
			}
		}
		l := make([]byte, 0)
		for i := 0; i < len(s); i++ {
			val := int(s[i] - 'a' + 1)
			if m[val] > 0 {
				l = append(l, s[i])
				m[val]--
			}
		}
		fmt.Println(string(l))
	}
}

// 1702D. Not a Cheap String
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var s string
		fmt.Fscan(reader, &s)
		var p int
		fmt.Fscan(reader, &p)
		total := 0
		m := make(map[int]int)
		for i := 0; i < len(s); i++ {
			val := int(s[i] - 'a' + 1)
			m[val]++
			total += val
		}

		if total > p {
			for i := 26; i > 0; i-- {
				if m[i] > 0 {
					if m[i]*i <= total-p {
						total -= m[i] * i
						m[i] = 0
					} else {
						rm := (total - p) / i
						m[i] -= rm
						total -= rm * i
					}
					if total <= p {
						break
					}
				}
			}
		}
		if total > p {
			fmt.Println()
		} else {
			l := make([]byte, 0)
			for i := 0; i < len(s); i++ {
				val := int(s[i] - 'a' + 1)
				if m[val] > 0 {
					l = append(l, s[i])
					m[val]--
				}
			}
			fmt.Println(string(l))
		}

	}
}

package main

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

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

	numCases := 0
	fmt.Fscan(in, &numCases)

	for ; numCases > 0; numCases-- {
		w := ""
		fmt.Fscan(in, &w)

		p := 0
		fmt.Fscan(in, &p)

		strCost := 0
		lettersMap := make(map[rune][]int, 26)
		for i, r := range w {
			strCost += int(r - 'a' + 1)
			lettersMap[r] = append(lettersMap[r], i)
		}

		runes := []rune(w)
		for l := 26; l > 0; l-- {
			if strCost <= p {
				for _, r := range runes {
					if r == 0 {
						continue
					}
					fmt.Fprintf(out, "%c", r)
				}
				fmt.Fprint(out, "\n")
				break
			}
			r := rune('a' + l - 1)
			if idx, ok := lettersMap[r]; ok {
				for i := 0; i < len(idx); i++ {
					strCost -= l
					runes[idx[i]] = 0
					if strCost <= p {
						break
					}
				}
			}
		}
	}
}

package main

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

const firstLetter = 'a' - 1

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

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

	for ; testNum > 0; testNum-- {
		var s string
		fmt.Fscan(in, &s)

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

		var w int
		for _, l := range s {
			v := int(l - firstLetter)
			w += v
		}

		d := p - w
		if d >= 0 {
			fmt.Println(s)
			continue
		}

		ss := []rune(s)
		sort.Slice(ss, func(i, j int) bool {
			return ss[i] > ss[j]
		})

		del := make(map[rune]int, 10)
		for _, sss := range ss {
			if w > p {
				w -= int(sss - firstLetter)
				del[sss]++
			} else {
				break
			}
		}

		se := []rune(s)
		for i, v := range se {
			if _, ok := del[v]; ok {
				del[v]--
				se[i] = 0
			}
		}

		res := make([]rune, 0, len(se))
		for _, ss := range se {
			if ss != 0 {
				res = append(res, ss)
			}
		}

		fmt.Println(string(res))
	}
}

package main

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

const firstLetter = 'a' - 1

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

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

	for ; testNum > 0; testNum-- {
		var s string
		fmt.Fscan(in, &s)

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

		var w int
		for _, l := range s {
			v := int(l - firstLetter)
			w += v
		}

		d := p - w
		if d >= 0 {
			fmt.Println(s)
			continue
		}

		ss := []rune(s)
		sort.Slice(ss, func(i, j int) bool {
			return ss[i] > ss[j]
		})

		del := make(map[rune]int, 10)
		for _, sss := range ss {
			if w > p {
				w -= int(sss - firstLetter)
				del[sss]++
			} else {
                break
            }
		}

        se := []rune(s)
		for i, v := range se {
			if _, ok := del[v]; ok {
				del[v]--
				se[i] = 0
			}
		}

		fmt.Println(string(se))
	}
}

package main

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

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

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

		aa := make([]int, 26)
		var tot int
		for _, ch := range s {
			aa[ch-'a']++
			tot += int(ch-'a') + 1
		}

		idx := 25
		for tot > n && idx >= 0 {
			if aa[idx] > 0 {
				req := (tot - n) / (idx + 1)
				d := min(aa[idx], req)
				tot -= d * (idx + 1)
				aa[idx] -= d
			}
			idx--
		}

		var buf bytes.Buffer
		for _, ch := range s {
			if aa[ch-'a'] > 0 {
				aa[ch-'a']--
				buf.WriteRune(ch)
			}
		}
		var f bool
		if tot > n {
			f = true
		}
		s2 := buf.String()
		if f && len(s2) > 0 {
			fmt.Fprintln(out, s2[1:])
		} else {
			fmt.Fprintln(out, s2)
		}
	}
}

package main

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

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

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

		aa := make([]int, 26)
		var tot int
		for _, ch := range s {
			aa[ch-'a']++
			tot += int(ch-'a') + 1
		}

		idx := 25
		for tot > n && idx >= 0 {
			if aa[idx] > 0 {
				req := (tot - n) / (idx + 1)
				if req%(idx+1) != 0 {
					req++
				}
				d := min(aa[idx], req)
				tot -= d * (idx + 1)
				aa[idx] -= d
			}
			idx--
		}

		var buf bytes.Buffer
		for _, ch := range s {
			if aa[ch-'a'] > 0 {
				aa[ch-'a']--
				buf.WriteRune(ch)
			}
		}
		fmt.Fprintln(out, buf.String())
	}
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var s string
	var n int
	fmt.Fscan(rr, &s, &n)
	cnt := make([]int, 26)
	sum := 0
	minus := make([]int, 26)
	for i := range s {
		sum += int(s[i]-'a') + 1
		cnt[s[i]-'a']++
	}
	i := 25
	for sum > n {
		for cnt[i] == 0 {
			i--
		}
		cnt[i]--
		sum -= i+1
		minus[i]++
	}
	ans := make([]byte, 0)
	for i := range s {
		if minus[s[i]-'a'] > 0 {
			continue
		} else {
			ans = append(ans, s[i])
		}
	}
	fmt.Fprintln(ww, string(ans))

}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

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

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

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var s string
		var m int
		fmt.Fscan(r, &s, &m)
		w1 := do(s, m)
		fmt.Fprintln(w, w1)
	}
}

func do(s string, p int) string {
	m := [27]int{}
	q := 0
	for _, c := range s {
		v := int(c-'a') + 1
		m[v]++
		q += v
	}
	for i := 26; i >= 1; i-- {
		j := (q - p) / i
		if j > m[i] {
			j = m[i]
		}
		q -= j * i
		m[i] -= j
	}
	if q > p {
		for i := 1; i <= 26; i++ {
			if m[i] > 0 {
				q -= i
				m[i]--
			}
		}
	}
	sb := strings.Builder{}
	for _, c := range s {
		v := int(c-'a') + 1
		if m[v] > 0 {
			sb.WriteRune(c)
			m[v]--
		}
	}
	return sb.String()
}

package main

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

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

type Tint interface {
	int | int32 | int64
}

func min[T Tint](x, y T) T {
	if x <= y {
		return x
	}
	return y
}
func max[T Tint](x, y T) T {
	if x >= y {
		return x
	}
	return y
}
func main() {
	defer _w.Flush()

	var _t int
	// n = 1
	fmt.Fscan(_r, &_t)
	for ; _t > 0; _t-- {
		s, p := "", 1
		fmt.Fscan(_r, &s, &p)
		a := make([]int, 0)
		for i := range s {
			a = append(a, int(s[i]-'a'+1))
		}
		for i := range a {
			a[i] = -a[i]
		}
		sort.Ints(a)
		for i := range a {
			a[i] = -a[i]
		}
		pre := make([]int, len(a)+1)
		for i := 1; i < len(pre); i++ {
			pre[i] = pre[i-1] + a[i-1]
		}
		l, r := 1, len(pre)-1
		pos := len(pre) - 1
		for l <= r {
			mid := (l + r) >> 1
			if ck(mid, pre, p) {
				pos = mid
				r = mid - 1
			} else {
				l = mid + 1
			}
		}
		if pos <= 0 {
			fmt.Fprintln(_w, s)
			continue
		}
		mp := make(map[int]int)
		for i := 1; i <= pos; i++ {
			v := a[i-1] + 'a' - 1
			if _, ok := mp[v]; !ok {
				mp[v] = 0
			}
			mp[v]++
		}
		//fmt.Println(mp, pre[len(pre)-1]-pre[0])
		res := ""
		for _, v := range s {
			if _, ok := mp[int(v)]; !ok {
				res += string(v)
				continue
			}
			if mp[int(v)] <= 0 {
				res += string(v)
				continue
			}
			mp[int(v)]--
		}
		fmt.Fprintln(_w, res)
	}
}
func ck(mid int, pre []int, p int) bool {
	return pre[len(pre)-1]-pre[mid] <= p
}


A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art.First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string.Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer.

First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100.

The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t.

NoteIn the first sample string "cbaabc" = "cba" + "abc".In the second sample: "ayrat" = "a" + "yr" + "at".

package main

// Solution for https://codeforces.com/problemset/problem/615/C

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

const impossible = int16(0)
const forward = 1
const backward = -1

type location struct {
	pos, dir int16
}

func loc2int(l location) int16 {
	return (l.pos << 1) | (l.dir+1)>>1
}

func int2loc(i int16) location {
	return location{
		pos: i >> 1,
		dir: ((i & 1) << 1) - 1,
	}
}

var dirs = []int16{forward, backward}

type cell struct {
	score  int16
	parent int16 // loc2int
}

type slice struct {
	start, stop int16
	dir         int16
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	s := scanner.Text()
	scanner.Scan()
	t := scanner.Text()
	var index [26][]int16 // Where I can find a letter in s.
	for i, c0 := range s {
		c := int(c0) - int('a')
		index[c] = append(index[c], int16(i))
	}
	size := 2 * len(s)
	current := make([]cell, size)
	var history [][]cell
	minScore := int16(1)
	var minLoc location
	for _, c0 := range t {
		c := int(c0) - int('a')
		if len(index[c]) == 0 {
			fmt.Println(-1)
			return
		}
		next := make([]cell, size)
		nextMinScore := impossible
		var nextMinLoc location
		for _, pos := range index[c] {
			for _, dir := range dirs {
				loc := location{pos, dir}
				best := cell{score: minScore + 1, parent: loc2int(minLoc)}
				if pos-dir >= 0 && pos-dir < int16(len(s)) {
					prevLoc := location{pos - dir, dir}
					prevSs := current[loc2int(prevLoc)]
					if prevSs.score != impossible && prevSs.score < best.score {
						best = cell{score: prevSs.score, parent: loc2int(prevLoc)}
					}
				}
				next[loc2int(loc)] = best
				if nextMinScore == impossible || best.score < nextMinScore {
					nextMinScore = best.score
					nextMinLoc = loc
				}
			}
		}
		history = append(history, next)
		minScore = nextMinScore
		minLoc = nextMinLoc
		current = next
	}
	fmt.Println(minScore - 1)
	steps := make([]location, len(history))
	for j := len(history) - 1; j >= 0; j-- {
		steps[j] = minLoc
		minLoc = int2loc(history[j][loc2int(minLoc)].parent)
	}
	var slices []slice
	for _, step := range steps {
		if len(slices) == 0 {
			slices = append(slices, slice{start: step.pos, stop: step.pos, dir: step.dir})
			continue
		}
		growing := slices[len(slices)-1]
		if growing.dir == step.dir && step.pos == growing.stop+growing.dir {
			growing.stop = step.pos
			slices[len(slices)-1] = growing
			continue
		}
		slices = append(slices, slice{start: step.pos, stop: step.pos, dir: step.dir})
	}
	for _, slice := range slices {
		fmt.Println(slice.start+1, slice.stop+1)
	}
}

package main

import (
    "fmt"
)

type Match struct {
    Begin, End int
}

var (
    ret = []Match{}
    s   string
    t   string
)

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

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

func revStr(s string) string {
    runes := []rune(s)
    for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
        runes[i], runes[j] = runes[j], runes[i]
    }
    return string(runes)
}

func main() {
    fmt.Scanf("%s\n", &s)
    fmt.Scanf("%s\n", &t)

    lenS := len(s)
    lenT := len(t)

    ti := 0
    for ti < lenT {
        maxSubI := -1
        maxSubLen := -1
        reverse := false

        for si := 0; si < lenS; si++ {
            for lenSub, maxLenSub := 1, min(lenT-ti, lenS-si); lenSub <= maxLenSub; lenSub++ {
                if !(s[si:si+lenSub] == t[ti:ti+lenSub]) {
                    break
                }
                if lenSub > maxSubLen {
                    maxSubI = si
                    maxSubLen = lenSub
                    reverse = false
                }
            }
        }

        for si := 0; si < lenS; si++ {
            for lenSub, maxLenSub := max(1, maxSubLen+1), min(lenT-ti, si+1); lenSub <= maxLenSub; lenSub++ {
                if !(revStr(s[si+1-lenSub:si+1]) == t[ti:ti+lenSub]) {
                    break
                }
                if lenSub > maxSubLen {
                    maxSubI = si
                    maxSubLen = lenSub
                    reverse = true
                }
            }
        }

        if maxSubI == -1 {
            fmt.Println(-1)
            return
        }
        if reverse {
            ret = append(ret, Match{maxSubI + 1, maxSubI + 2 - maxSubLen})
        } else {
            ret = append(ret, Match{maxSubI + 1, maxSubI + maxSubLen})
        }
        ti = ti + maxSubLen
    }

    fmt.Println(len(ret))
    for _, m := range ret {
        fmt.Printf("%d %d\n", m.Begin, m.End)
    }
}

package main

import (
    "fmt"
)

type Match struct {
    Begin, End int
}

var (
    ret = []Match{}
    s   string
    t   string
)

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

func revStr(s string) string {
    runes := []rune(s)
    for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
        runes[i], runes[j] = runes[j], runes[i]
    }
    return string(runes)
}

func main() {
    fmt.Scanf("%s\n", &s)
    fmt.Scanf("%s\n", &t)

    lenS := len(s)
    lenT := len(t)

    ti := 0
    for ti < lenT {
        maxSubI := -1
        maxSubLen := -1
        reverse := false

        for si := 0; si < lenS; si++ {
            for lenSub, maxLenSub := 1, min(lenT-ti, lenS-si); lenSub <= maxLenSub; lenSub++ {
                if !(s[si:si+lenSub] == t[ti:ti+lenSub]) {
                    break
                }
                if lenSub > maxSubLen {
                    maxSubI = si
                    maxSubLen = lenSub
                    reverse = false
                }
            }
        }

        for si := 0; si < lenS; si++ {
            for lenSub, maxLenSub := 1, min(lenT-ti, si+1); lenSub <= maxLenSub; lenSub++ {
                if lenSub < maxSubLen {
                    break
                }
                if !(revStr(s[si+1-lenSub:si+1]) == t[ti:ti+lenSub]) {
                    break
                }
                maxSubI = si
                maxSubLen = lenSub
                reverse = true
            }
        }

        if maxSubI == -1 {
            fmt.Println(-1)
            return
        }
        if reverse {
            ret = append(ret, Match{maxSubI + 1, maxSubI + 2 - maxSubLen})
        } else {
            ret = append(ret, Match{maxSubI + 1, maxSubI + maxSubLen})
        }
        ti = ti + maxSubLen
    }

    fmt.Println(len(ret))
    for _, m := range ret {
        fmt.Printf("%d %d\n", m.Begin, m.End)
    }
}