You are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values of all subsegments of this array.For example, the imbalance value of array [1, 4, 1] is 9, because there are 6 different subsegments of this array:   [1] (from index 1 to index 1), imbalance value is 0;  [1, 4] (from index 1 to index 2), imbalance value is 3;  [1, 4, 1] (from index 1 to index 3), imbalance value is 3;  [4] (from index 2 to index 2), imbalance value is 0;  [4, 1] (from index 2 to index 3), imbalance value is 3;  [1] (from index 3 to index 3), imbalance value is 0; You have to determine the imbalance value of the array a.

The first line contains one integer n (1 ≤ n ≤ 106) — size of the array a. The second line contains n integers a1, a2... an (1 ≤ ai ≤ 106) — elements of the array.

Print one integer — the imbalance value of a.

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

type Node struct {
	value                      int
	lbig, rbig, lsmall, rsmall int
	index                      int
}

func main() {
	var pointer int
	stack := make([]*Node, 1000000, 1000000)
	seq := make([]*Node, 0, 1000000)

	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0; i < n; i++ {
		var a int
		fmt.Fscanf(reader, "%d ", &a)
		seq = append(seq, &Node{value: a, index: i})
	}

	pointer = 0
	for i := 0; i < n; i++ {
		for pointer != 0 && stack[pointer-1].value <= seq[i].value {
			pointer--
			stack[pointer].rbig = i
		}
		stack[pointer] = seq[i]
		pointer++
	}
	for pointer != 0 {
		pointer--
		stack[pointer].rbig = n
	}

	pointer = 0
	for i := n - 1; i >= 0; i-- {
		for pointer != 0 && stack[pointer-1].value < seq[i].value {
			pointer--
			stack[pointer].lbig = i
		}
		stack[pointer] = seq[i]
		pointer++
	}
	for pointer != 0 {
		pointer--
		stack[pointer].lbig = -1
	}

	pointer = 0
	for i := 0; i < n; i++ {
		for pointer != 0 && stack[pointer-1].value >= seq[i].value {
			pointer--
			stack[pointer].rsmall = i
		}
		stack[pointer] = seq[i]
		pointer++
	}
	for pointer != 0 {
		pointer--
		stack[pointer].rsmall = n
	}

	pointer = 0
	for i := n - 1; i >= 0; i-- {
		for pointer != 0 && stack[pointer-1].value > seq[i].value {
			pointer--
			stack[pointer].lsmall = i
		}
		stack[pointer] = seq[i]
		pointer++
	}
	for pointer != 0 {
		pointer--
		stack[pointer].lsmall = -1
	}

	var result int64
	for i := 0; i < n; i++ {
		result = result + int64(seq[i].rbig-i)*int64(i-seq[i].lbig)*int64(seq[i].value) - int64(seq[i].rsmall-i)*int64(i-seq[i].lsmall)*int64(seq[i].value)
	}
	fmt.Printf("%d\n", result)

}


A binary string is a string consisting only of the characters 0 and 1. You are given a binary string $$$s$$$.For some non-empty substring$$$^\dagger$$$ $$$t$$$ of string $$$s$$$ containing $$$x$$$ characters 0 and $$$y$$$ characters 1, define its cost as:  $$$x \cdot y$$$, if $$$x > 0$$$ and $$$y > 0$$$;  $$$x^2$$$, if $$$x > 0$$$ and $$$y = 0$$$;  $$$y^2$$$, if $$$x = 0$$$ and $$$y > 0$$$. Given a binary string $$$s$$$ of length $$$n$$$, find the maximum cost across all its non-empty substrings.$$$^\dagger$$$ A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the string $$$s$$$. The second line of each test case contains a binary string $$$s$$$ of length $$$n$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print a single integer — the maximum cost across all substrings.

NoteIn the first test case, we can take a substring $$$111$$$. It contains $$$3$$$ characters 1 and $$$0$$$ characters 0. So $$$a = 3$$$, $$$b = 0$$$ and its cost is $$$3^2 = 9$$$.In the second test case, we can take the whole string. It contains $$$4$$$ characters 1 and $$$3$$$ characters 0. So $$$a = 4$$$, $$$b = 3$$$ and its cost is $$$4 \cdot 3 = 12$$$.In the third test case, we can can take a substring $$$1111$$$ and its cost is $$$4^2 = 16$$$.In the fourth test case, we can take the whole string and cost is $$$4 \cdot 3 = 12$$$.In the fifth test case, we can take a substring $$$000$$$ and its cost is $$$3 \cdot 3 = 9$$$.In the sixth test case, we can only take the substring $$$0$$$ and its cost is $$$1 \cdot 1 = 1$$$.

package main

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

func mymax(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

const cf = true

func main() {
	defer out.Flush()

	t := 0
	fmt.Scan(&t)
	for ; t > 0; t-- {
		n := 0
		fmt.Fscan(in, &n)
		a := make([]int64, n)
		s := ""
		fmt.Fscan(in, &s)
		for i := 0; i < n; i++ {
			a[i] = int64(s[i]) - int64('0')
		}

		var nowz, maxz, nowo, maxo, ones, zeros int64
		for i := 0; i < n; i++ {
			if a[i] == 0 {
				zeros++
				nowo = 0
				nowz++
				maxz = mymax(maxz, nowz)
			} else {
				ones++
				nowz = 0
				nowo++
				maxo = mymax(maxo, nowo)
			}
		}
		fmt.Fprintln(out, mymax(mymax(maxo*maxo, maxz*maxz), ones*zeros))
	}
}

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

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

func mymax(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

const cf = true

func main() {
	defer out.Flush()

	t := 0
	fmt.Scan(&t)
	for ; t > 0; t-- {
		n := 0
		fmt.Fscan(in, &n)
		a := make([]int64, n)
		s := ""
		fmt.Fscan(in, &s)
		for i := 0; i < n; i++ {
			a[i] = int64(s[i]) - int64('0')
		}

		var nowz, maxz, nowo, maxo, ones, zeros int64
		for i := 0; i < n; i++ {
			if a[i] == 0 {
				zeros++
				nowo = 0
				nowz++
				maxz = mymax(maxz, nowz)
			} else {
				ones++
				nowz = 0
				nowo++
				maxo = mymax(maxo, nowo)
			}
		}
		fmt.Fprintln(out, mymax(mymax(maxo*maxo, maxz*maxz), ones*zeros))
	}
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

func mult(a []int) int {
	max := 0
	for i := 0; i < len(a); i++ {
		sq := a[i] * a[i]
		if sq > max {
			max = sq
		}
	}
	return max
}

func SortString(w string) string {
	s := strings.Split(w, "")
	sort.Strings(s)
	return strings.Join(s, "")
}

func solve(s string, n int) int {
	var x []int
	//fmt.Println(s)
	var c, unos, ceros int
	c = 1
	if s[0] == '1' {
		unos++
	} else {
		ceros++
	}
	for i := 1; i < n; i++ {
		if s[i] == s[i-1] {
			c++
		} else {
			x = append(x, c)
			c = 1
		}
		if s[i] == '1' {
			unos++
		} else {
			ceros++
		}
	}
	x = append(x, c)
	//fmt.Println(x, unos, ceros)
	msq := mult(x)
	m := unos * ceros
	if m > msq {
		return m
	}
	return msq
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for c := 0; c < t; c++ {
		var n int
		var s string
		fmt.Fscan(in, &n, &s)
		//s2 := SortString(s)
		x := solve(s, n)
		fmt.Println(x)
	}
}

package main

import . "fmt"
import "bufio"
import "os"

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

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

func ans() {
	var n int
	var s string
	Fscan(in, &n, &s)
	var cnt0 int = 0
	var cnt1 int = 0
	var cnt0Max int = 0
	var cnt1Max int = 0
	var cnt0Cur int = 0
	var cnt1Cur int = 0
	if s[0] == '0' {
		cnt0 = 1
		cnt0Max = 1
		cnt0Cur = 1
	} else {
		cnt1 = 1
		cnt1Max = 1
		cnt1Cur = 1
	}
	for i := 1; i < n; i++ {
		if s[i] == '0' {
			cnt0++
			if s[i - 1] == '0' {
				cnt0Cur++
			} else {
				cnt1Max = max(cnt1Max, cnt1Cur)
				cnt1Cur = 0
				cnt0Cur = 1
			}
		} else {
			cnt1++
			if s[i - 1] == '1' {
				cnt1Cur++
			} else {
				cnt0Max = max(cnt0Max, cnt0Cur)
				cnt0Cur = 0
				cnt1Cur = 1
			}
		}
	}
	cnt0Max = max(cnt0Max, cnt0Cur)
	cnt1Max = max(cnt1Max, cnt1Cur)
	var xy int = cnt0 * cnt1
	var xx int = cnt0Max * cnt0Max
	var yy int = cnt1Max * cnt1Max
	var res int = max(xy, max(xx, yy))
	Fprintln(out, res)
}

func main() {
	defer out.Flush()
	var t int
	Fscan(in, &t)
	for i := 0; i < t; i++ {
		ans()
	}
}

package main

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

func solve(reader *bufio.Reader, writer *bufio.Writer) {
	n := readInt(reader)
	s := readString(reader)
	var cnt1, cnt0, ans int64
	for _, r := range s {
		if r == '1' {
			cnt1++
		} else {
			cnt0++
		}
	}
	ans = cnt1 * cnt0

	var cnt int64 = 1
	for i := 1; i < n; i++ {
		if s[i] == s[i-1] {
			cnt++
		} else {
			ans = max(cnt*cnt, ans)
			cnt = 1
		}
	}
	ans = max(cnt*cnt, ans)

	fmt.Fprintln(writer, ans)
}

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		solve(reader, writer)
		t--
	}

	writer.Flush()
}

func min[T int | int64](a, b T) T {
	if a < b {
		return a
	}

	return b
}

func max[T int | int64](a, b T) T {
	if a > b {
		return a
	}

	return b
}

func abs[T int | int64](a T) T {
	if a < 0 {
		return a * -1
	} else {
		return a
	}
}

func gcd[T int | int64](x, y T) T {
	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func lcm[T int | int64](x, y T) T {
	return x * y / gcd(x, y)
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

const (
	DEBUG = false
)

func debug(a ...interface{}) {
	if !DEBUG {
		return
	}
	for _, e := range a {
		printf("%v ", e)
	}
	printf("\n")
	writer.Flush()
}

func debugCondn(condn bool, a ...interface{}) {
	if !DEBUG || !condn {
		return
	}
	for _, e := range a {
		printf("%v ", e)
	}
	printf("\n")
	writer.Flush()
}

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

func solve(tt int) {
	var n int
	var s string
	scanf("%d\n%s\n", &n, &s)

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

	x := int64(0)
	y := int64(0)
	consecutiveOne := int64(0)
	consecutiveZero := int64(0)
	res := int64(0)
	for i:=0; i<n; i++ {
		if s[i] == '0' {
			x++
			res = max(res, consecutiveOne * consecutiveOne)
			consecutiveOne = 0
			consecutiveZero++
			continue
		}
		y++
		res = max(res, consecutiveZero * consecutiveZero)
		consecutiveZero = 0
		consecutiveOne++
	}
	res = max(res, consecutiveOne * consecutiveOne)
	res = max(res, consecutiveZero * consecutiveZero)
	res = max(res, x*y)
	printf("%d\n", res)
}

func main() {
	defer writer.Flush()

	var T int
	scanf("%d\n", &T)
	for tt:=1; tt<=T; tt++ {
		// printf("Case #%d: ", tt)
		solve(tt)
	}
}

package main

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

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n int
		fmt.Fscan(r, &n)

		var a []byte
		fmt.Fscan(r, &a)

		var cnt1, cnt, mcnt int

		cnt1 = int(a[0] - '0')
		cnt = 1
		mcnt = cnt
		for i := 1; i < n; i++ {
			if a[i] != a[i-1] {
				mcnt = max(mcnt, cnt)
				cnt = 1
			} else {
				cnt++
				mcnt = max(mcnt, cnt)
			}
			cnt1 += int(a[i] - '0')
		}

		fmt.Fprintln(w, max(cnt1*(n-cnt1), mcnt*mcnt))
	}

}

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	var str string
	fmt.Fscan(in, &str)
	cnt0, cnt1 := 0, 0
	curOne := -1
	mx := 1
	curLen := 0
	for _, chr := range str {
		if chr == '0' {
			if curOne != 0 {
				mx = max(mx, curLen)
				curOne = 0
				curLen = 1
			} else {
				curLen++
			}
			cnt0++
		} else {
			if curOne != 1 {
				mx = max(mx, curLen)
				curOne = 1
				curLen = 1
			} else {
				curLen++
			}
			cnt1++
		}
	}
	mx = max(mx, curLen)
	fmt.Fprintln(out, max(mx*mx, cnt0*cnt1))
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

func GCD(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []byte(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

import (
	"fmt"
)

func mymax(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func main() {
	t := 0
	fmt.Scan(&t)
	for ; t > 0; t-- {
		n := 0
		var zeros, ones int64 = 0, 0
		fmt.Scan(&n)
		a := make([]int64, n)
		s := ""
		fmt.Scan(&s)
		for i := 0; i < n; i++ {
			a[i] = int64(s[i]) - int64('0')
			zeros += a[i] ^ 1
			ones += a[i]
		}
		zz, oo, zo := zeros*zeros, ones*ones, zeros*ones
		fmt.Println(mymax(mymax(zz, oo), zo))
	}
}

package main

import (
	"fmt"
)

var eps float64 = 1e-4

func sq_root(n float64) float64 {
	var l, r float64 = 0, n
	m := (r + l) / 2

	for (r - l) > eps {
		m = (r + l) / 2
		if m*m > n {
			r = m
		} else {
			l = m
		}
	}
	return l
}

func mymax(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func main() {
	t := 0
	fmt.Scan(&t)
	for ; t > 0; t-- {
		n := 0
		var zeros, ones int64 = 0, 0
		fmt.Scan(&n)
		a := make([]int64, n)
		s := ""
		fmt.Scan(&s)
		for i := 0; i < n; i++ {
			a[i] = int64(s[i]) - int64('0')
			zeros += a[i] ^ 1
			ones += a[i]
		}
		fmt.Println(a, zeros, ones)
		zz, oo, zo := zeros*zeros, ones*ones, zeros*ones
		fmt.Println(mymax(mymax(zz, oo), zo))
	}
}

package main

import (
	"fmt"
)

var eps float64 = 1e-4

func sq_root(n float64) float64 {
	var l, r float64 = 0, n
	m := (r + l) / 2

	for (r - l) > eps {
		m = (r + l) / 2
		if m*m > n {
			r = m
		} else {
			l = m
		}
	}
	return l
}

func mymax(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func main() {
	t := 0
	fmt.Scan(&t)
	for ; t > 0; t-- {
		n := 0
		var zeros, ones int64 = 0, 0
		fmt.Scan(&n)
		a := make([]int64, n)
		s := ""
		fmt.Scan(&s)
		for i := 0; i < n; i++ {
			a[i] = int64(s[i]) - int64('0')
			zeros += a[i] ^ 1
			ones += a[i]
		}
// 		fmt.Println(a, zeros, ones)
		fmt.Println(mymax(mymax(zeros*zeros, ones*ones), zeros*ones))
	}
}

package main

import (
	"fmt"
	"math"
)

var eps float64 = 1e-4

func sq_root(n float64) float64 {
	var l, r float64 = 0, n
	m := (r + l) / 2

	for (r - l) > eps {
		m = (r + l) / 2
		if m*m > n {
			r = m
		} else {
			l = m
		}
	}
	return l
}

func main() {
	t := 0
	fmt.Scan(&t)
	for ; t > 0; t-- {
		n := 0
		zeros, ones := 0.0, 0.0
		fmt.Scan(&n)
		a := make([]int, n)
		s := ""
		fmt.Scan(&s)
		for i := 0; i < n; i++ {
			a[i] = int(s[i]) - int('0')
			zeros += float64(a[i] ^ 1)
			ones += float64(a[i])
		}
		fmt.Println(zeros*zeros,ones*ones,zeros*ones)
		fmt.Println(int64(math.Max(math.Max(zeros*zeros, ones*ones), zeros*ones)))
	}
}

package main

import (
	"fmt"
	"math"
)

var eps float64 = 1e-4

func sq_root(n float64) float64 {
	var l, r float64 = 0, n
	m := (r + l) / 2

	for (r - l) > eps {
		m = (r + l) / 2
		if m*m > n {
			r = m
		} else {
			l = m
		}
	}
	return l
}

func main() {
	t := 0
	fmt.Scan(&t)
	for ; t > 0; t-- {
		n := 0
		zeros, ones := 0.0, 0.0
		fmt.Scan(&n)
		a := make([]int, n)
		s := ""
		fmt.Scan(&s)
		for i := 0; i < n; i++ {
			a[i] = int(s[i]) - int('0')
			zeros += float64(a[i] ^ 1)
			ones += float64(a[i])
		}
// 		fmt.Println(a, zeros, ones)
		fmt.Println(int64(math.Max(math.Max(zeros*zeros, ones*ones), zeros*ones)))
	}
}

package main

import (
	"fmt"
	"math"
)

var eps float64 = 1e-4

func sq_root(n float64) float64 {
	var l, r float64 = 0, n
	m := (r + l) / 2

	for (r - l) > eps {
		m = (r + l) / 2
		if m*m > n {
			r = m
		} else {
			l = m
		}
	}
	return l
}

func main() {
	t := 0
	fmt.Scan(&t)
	for ; t > 0; t-- {
		n := 0
		zeros, ones := 0.0, 0.0
		fmt.Scan(&n)
		a := make([]int, n)
		s := ""
		fmt.Scan(&s)
		for i := 0; i < n; i++ {
			a[i] = int(s[i]) - int('0')
			zeros += float64(a[i] ^ 1)
			ones += float64(a[i])
		}
		fmt.Println(a, zeros, ones)
		fmt.Println(int64(math.Max(math.Max(zeros*zeros, ones*ones), zeros*ones)))
	}
}

package main

import (
	"fmt"
	"math"
)

var eps float64 = 1e-4

func sq_root(n float64) float64 {
	var l, r float64 = 0, n
	m := (r + l) / 2

	for (r - l) > eps {
		m = (r + l) / 2
		if m*m > n {
			r = m
		} else {
			l = m
		}
	}
	return l
}

func main() {
	t := 0
	fmt.Scan(&t)
	for ; t > 0; t-- {
		n := 0
		zeros, ones := 0, 0
		fmt.Scan(&n)
		a := make([]int, n)
		s := ""
		fmt.Scan(&s)
		for i := 0; i < n; i++ {
			a[i] = int(s[i]) - int('0')
			zeros += a[i] ^ 1
			ones += a[i]
		}
// 		fmt.Println(a, zeros, ones)
		fmt.Println(int64(math.Max(math.Max(float64(zeros*zeros), float64(ones*ones)), float64(zeros*ones))))
	}
}

package main

import (
	"fmt"
	"math"
)

var eps float64 = 1e-4

func sq_root(n float64) float64 {
	var l, r float64 = 0, n
	m := (r + l) / 2

	for (r - l) > eps {
		m = (r + l) / 2
		if m*m > n {
			r = m
		} else {
			l = m
		}
	}
	return l
}

func main() {
	t := 0
	fmt.Scan(&t)
	for ; t > 0; t-- {
		n := 0
		zeros, ones := 0, 0
		fmt.Scan(&n)
		a := make([]int, n)
		s := ""
		fmt.Scan(&s)
		for i := 0; i < n; i++ {
			a[i] = int(s[i]) - int('0')
			zeros += a[i] ^ 1
			ones += a[i]
		}
		// fmt.Println(a)
		fmt.Println(int64(math.Max(math.Max(float64(zeros*zeros), float64(ones*ones)), float64(zeros*ones))))
	}
}


You are given two arrays $$$a$$$ and $$$b$$$, each consisting of $$$n$$$ positive integers, and an integer $$$x$$$. Please determine if one can rearrange the elements of $$$b$$$ so that $$$a_i + b_i \leq x$$$ holds for each $$$i$$$ ($$$1 \le i \le n$$$).

The first line of input contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. $$$t$$$ blocks follow, each describing an individual test case. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \leq n \leq 50$$$; $$$1 \leq x \leq 1000$$$) — the length of arrays $$$a$$$ and $$$b$$$, and the parameter $$$x$$$, described in the problem statement. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_1 \le a_2 \le \dots \le a_n \leq x$$$) — the elements of array $$$a$$$ in non-descending order. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \leq b_1 \le b_2 \le \dots \le b_n \leq x$$$) — the elements of array $$$b$$$ in non-descending order. Test cases are separated by a blank line.

For each test case print Yes if one can rearrange the corresponding array $$$b$$$ so that $$$a_i + b_i \leq x$$$ holds for each $$$i$$$ ($$$1 \le i \le n$$$) or No otherwise. Each character can be printed in any case.

NoteIn the first test case, one can rearrange $$$b$$$ so it'll look like $$$[1, 2, 1]$$$. In this case, $$$1 + 1 \leq 4$$$; $$$2 + 2 \leq 4$$$; $$$3 + 1 \leq 4$$$.In the second test case, one can set $$$b$$$ to $$$[5, 2]$$$, then $$$1 + 5 \leq 6$$$; $$$4 + 2 \leq 6$$$.In the third test case, no matter how one shuffles array $$$b$$$, $$$a_4 + b_4 = 4 + b_4 > 4$$$.In the fourth test case, there is only one rearrangement of array $$$b$$$ and it doesn't satisfy the condition since $$$5 + 5 > 5$$$.

package main

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

func main() {
	var t, n, x int
	scanf(&t)
	for ; t > 0; t-- {
		scanf(&n, &x)
		a := make([]int, n)
		b := make([]int, n)
		for i := 0; i < n; i++ {
			scanf(&a[i])
		}
		for i := 0; i < n; i++ {
			scanf(&b[i])
		}
		sort.Ints(a)
		sort.Ints(b)
		f := "Yes"
		for i := 0; i < n; i++ {
			if a[i]+b[n-i-1] > x {
				f = "No"
			}
		}
		printf(f)
	}
}

var sc *bufio.Scanner

func init() {
	file, err := os.Open("in.txt")
	if err != nil {
		file = os.Stdin
	}
	sc = bufio.NewScanner(file)
	maxLen := int(1e6 + 5)
	sc.Buffer(make([]byte, maxLen), maxLen)
	sc.Split(bufio.ScanWords)
}
func nextInfo() string {
	sc.Scan()
	return sc.Text()
}
func scanf(ioval ...interface{}) (err error) {
	for _, val := range ioval {
		s := nextInfo()
		switch v := val.(type) {
		case *int:
			*v, err = strconv.Atoi(s)
		case *int64:
			*v, err = strconv.ParseInt(s, 10, 64)
		case *string:
			*v, err = s, nil
		case *float64:
			*v, err = strconv.ParseFloat(s, 64)
		}
	}
	return
}
func printf(ioval ...interface{}) (n int, err error) {
	return fmt.Fprintln(os.Stdout, ioval...)
}
func sprintf(format string, ioval ...interface{}) (n int, err error) {
	return fmt.Fprintf(os.Stdout, format, ioval...)
}

package main

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

func main() {
	var t int

	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &t)

	for ; t > 0; t-- {
		var n, x int

		fmt.Fscan(reader, &n, &x)

		arr1, arr2 := make([]int, n), make([]int, n)

		for i := range arr1 {
			fmt.Fscan(reader, &arr1[i])
		}

		for i := range arr2 {
			fmt.Fscan(reader, &arr2[i])
		}

		sort.Ints(arr1)
		sort.Sort(sort.Reverse(sort.IntSlice(arr2)))

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

			fmt.Printf("\n")

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

			fmt.Printf("\n")

		*/

		var flag = true

		for i := range arr1 {
			if arr1[i]+arr2[i] > x {
				flag = false
				break
			}
		}

		if flag {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}

}

package main

import (
	"bufio"
	"fmt"
	"math"
	_ "net/http/pprof"
	"os"
	"sort"
	"strconv"
	"strings"
	"sync"
)

const (
	maxn = int(1e5 + 50)
	mod  = int(1e9 + 7)
	eps  = 1e-8
	inf  = int(0x3f3f3f3f)
)

func main() {
	var T int
	scanInt(&T)
	for i := 0; i < T; i++ {
		var n, x int
		scanInts(&n, &x)
		a := make([]int, n)
		b := make([]int, n)
		for i := 0; i < n; i++ {
			scanInt(&a[i])
		}
		for i := 0; i < n; i++ {
			scanInt(&b[i])
		}
		sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
		sort.Slice(b, func(i, j int) bool { return b[i] > b[j] })
		flag := 1
		for i := 0; i < n; i++ {
			if a[i]+b[i] > x {
				flag = 0
				break
			}
		}
		if flag == 1 {
			printString("Yes")
		} else {
			printString("No")
		}
	}
	close(channelType)
	oWg.Wait()
	out.Flush()
}

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

var channelType chan string
var in *bufio.Scanner
var out = bufio.NewWriter(os.Stdout)
var oWg *sync.WaitGroup

// string and slice are the return value
func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	channelType = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)
	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range channelType {
			writer.WriteString(line + "\n")
		}
	}()
}
func scanString() string { in.Scan(); return in.Text() }
func scanInt(a *int)     { *a, _ = strconv.Atoi(scanString()) }
func scanInts(a ...*int) {
	for i := range a {
		*a[i], _ = strconv.Atoi(scanString())
	}
}
func scanInt64(a *int64) { *a, _ = strconv.ParseInt(scanString(), 10, 64) }
func scanInt64s(a ...*int64) {
	for i := range a {
		*a[i], _ = strconv.ParseInt(scanString(), 10, 64)
	}
}
func scanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = scanString()
	}
	return s
}
func scanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		scanInt(&arr[i])
	}
	return arr
}
func scanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		scanInt64(&arr[i])
	}
	return arr
}
func printlnInts(args ...int) {
	for _, x := range args {
		fmt.Fprint(out, x, " ")
	}
	fmt.Fprintln(out)
}
func printlnInt64s(args ...int64) {
	for _, x := range args {
		fmt.Fprint(out, x, " ")
	}
	fmt.Fprintln(out)
}
func printIntSlice(a []int, flag bool) {
	for _, x := range a {
		fmt.Fprint(out, x, " ")
	}
	if flag { fmt.Fprintln(out) }
}
func printRuneSlice(a []rune, flag bool) {
	for _, x := range a {
		fmt.Fprintf(out, "%c", x)
	}
	if flag { fmt.Fprintln(out) }
}
func printInt64Slice(a []int64, flag bool) {
	for _, x := range a {
		fmt.Fprint(out, x, " ")
	}
	if flag { fmt.Fprintln(out) }
}
func putchar(a ...rune) {
	for _, x := range a {
		fmt.Fprintf(out, "%c", x)
	}
}
func printString(s string) { fmt.Fprintln(out, s) }

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

func stringEquivalent(v interface{}) string { return fmt.Sprintf("%v", v) }
func spaceSeperatedStringFromArray(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func spaceSeperatedStringFromArray64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func minMaxFromArray(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func minElementFromArray(args ...int64) int64 { mn, _ := minMaxFromArray(args...); return mn }
func maxElementFromArray(args ...int64) int64 { _, mx := minMaxFromArray(args...); return mx }
func lcmCalculation(a, b int64) int64         { return a / gcdCalculation(a, b) * b }
func gcdCalculation(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return gcdCalculation(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func absoluteValue(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}
func min(args ...int) int { mn, _ := minMaxFinder(args...); return mn }
func max(args ...int) int { _, mx := minMaxFinder(args...); return mx }
func minMaxFinder(args ...int) (int, int) {
	minVal, maxVal := int(math.MaxInt32), int(math.MinInt32)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func same(x, y double) bool { return math.Abs(float64(x-y)) < eps }
func popcount(x int) (res int) {
	for i := 0; i < 32; i++ {
		if 1 == (1 & (x >> uint(i))) {
			res++
		}
	}
	return
}
func qp(a, n int64) (res int64) {
	for ; n > 0; n >>= 1 {
		if (n & 1) == 1 {
			res = res * a % int64(mod)
		}
		a = a * a % int64(mod)
	}
	return
}
func divUp(a, b int64) int64 {
	if a % b == 0 { return a / b } else { return a / b + 1 }
}
// [l, r)
func reverse(a *[]rune, l, r int) {
	for i, j := l, r - 1; i < j; i, j = i + 1, j - 1 {
		(*a)[i], (*a)[j] = (*a)[j], (*a)[i]
	}
}

/*********************** Structs ***********************/
type pair struct{ X, Y int }
type double float64
type pairSlice []pair

func (p pairSlice) Len() int { return len(p) }
func (p pairSlice) Less(i, j int) bool {
	if p[i].X != p[j].X {
		return p[i].X < p[j].X
	} else {
		return p[i].Y < p[j].Y
	}
}
func (p pairSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }

package main

import (
	"fmt"
	_ "net/http/pprof"
	"sort"
)

func main() {
	var(
		t,n,x int
	)
	fmt.Scan(&t)
Loop:
	for ;t>0;t--{
		fmt.Scan(&n,&x)
		a,b:=make([]int,n),make([]int,n)
		for i:=0;i<n;i++{
			fmt.Scan(&a[i])
		}
		for i:=0;i<n;i++{
			fmt.Scan(&b[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i]<a[j]
		})
		sort.Slice(b, func(i, j int) bool {
			return b[i]>b[j]
		})

		for i:=0;i<n;i++{
			if a[i]+b[i]>x{
				fmt.Println("No")
				continue Loop
			}
		}
		fmt.Println("Yes")
	}
}

package main

import (
	"fmt"
)

func main () {

	var t, n, x, v int
	var a, b [] int

	fmt.Scan(&t)

	for i := 1; i <= t; i++{

		fmt.Scan(&n, &x)

		for j := 1; j <= n; j++ {
			fmt.Scan(&v)
			a = append(a, v)
		}

		for k := 1; k <= n; k++ {
			fmt.Scan(&v)
			b = append(b, v)
		}

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

			if a[l] + b[n - l - 1] <= x {

				if l == n - 1 {
					fmt.Println("Yes")
				}

				continue

			}	else {
				fmt.Println("No")
				break
			}
		}

		a = [] int {}
		b = [] int {}

	}

}

// You can edit this code!
// Click here and start typing.
package main

import (
	"fmt"
	"sort"
)

var a [55]int
var b [55]int

func main() {
		var t, n, x int
    fmt.Scan(&t)
    for i := 0; i < t; i++ {
				fmt.Scan(&n, &x)
				for i := 1; i <= n; i++ {
					fmt.Scan(&a[i])
				}
				for i := 1; i <= n; i++ {
					fmt.Scan(&b[i])
				}

				sort.Ints(a[1:n+1])
				sort.Sort(sort.Reverse(sort.IntSlice(b[1:n+1])))

				var t = "Yes"
				for i := 1; i <= n; i++ {
					if a[i] + b[i] > x {
						t = "No"
						break
					}
				}
				fmt.Println(t)
    }
}

package main
import (
	"bufio"
	"fmt"
	"os"
	"sort"
)
func main() {
	rd := bufio.NewReader(os.Stdin)
	q := 0
	fmt.Fscan(rd, &q)
	for t := 0; t < q; t++ {
		n, x := 0, 0
		fmt.Fscan(rd, &n, &x)
		a, b := make([]int, n), make([]int, n)
		for i := range a {
			fmt.Fscan(rd, &a[i])
		}
		for i := range b {
			fmt.Fscan(rd, &b[i])
		}
		sort.Ints(a)
		sort.Sort(sort.Reverse(sort.IntSlice(b)))
		ok := true
		for i := range a {
			ok = ok && a[i] + b[i] <= x
		}
		if ok {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for tt := 0; tt < t; tt++ {
		var n, x int
		fmt.Scan(&n, &x)
		a := make([]int, n)
		b := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
		}
		for i := 0; i < n; i++ {
			fmt.Scan(&b[i])
		}
		if check(a, b, x) {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

func check(a, b []int, x int) bool {
	n := len(a)
	for i := 0; i < n; i++ {
		j := n - i - 1
		if a[i]+b[j] > x {
			return false
		}
	}
	return true
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t int
	fmt.Scan(&t)
	for tt := 0; tt < t; tt++ {
		var n, x int
		fmt.Scan(&n, &x)
		a := make([]int, n)
		b := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
		}
		for i := 0; i < n; i++ {
			fmt.Scan(&b[i])
		}
		if check(a, b, x) {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

func check(a, b []int, x int) bool {
	n := len(a)
	a = sort.IntSlice(a)
	b = sort.IntSlice(b)
	for i := 0; i < n; i++ {
		j := n - i - 1
		if a[i]+b[j] > x {
			return false
		}
	}
	return true
}

package main

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

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

func print(str string) {
	writer.WriteString(str)
}

func nextInt() int {
	scanner.Scan()
	str := scanner.Text()
	val, _ := strconv.Atoi(str)
	return val
}

func nextFloat() float64 {
	scanner.Scan()
	str := scanner.Text()
	val, _ := strconv.ParseFloat(str, 64)
	return val
}

func nextString() string {
	scanner.Scan()
	str := scanner.Text()
	return str
}

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

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

	t := nextInt()
	for t != 0 {
		n := nextInt()
		x := nextInt()
		a := make([]int, n)
		for i := range a {
			a[i] = nextInt()
		}
		b := make([]int, n)
		for i := range b {
			b[i] = nextInt()
		}

		sort.Ints(a)
		sort.Sort(sort.Reverse(sort.IntSlice(b)))
		ok := true
		for i := range a {
			if a[i]+b[i] > x {
				ok = false
				break
			}
		}
		if ok {
			print("Yes\n")
		} else {
			print("No\n")
		}
		t--
	}
}

package main

import (
    "fmt"
    "sort"
)

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

    for i := 0; i < testCases; i++ {
        var sze int
        fmt.Scan(&sze)
        var x int
        fmt.Scan(&x)

        arr1 := make([]int, sze)
        arr2 := make([]int, sze)

        for i := 0; i < sze; i++ {
            fmt.Scan(&arr1[i])
        }

        for i := 0; i < sze; i++ {
            fmt.Scan(&arr2[i])
        }
        sort.Ints(arr1)
        sort.Ints(arr2)

        flag := 0

        for i:= 0 ; i < sze ; i++ {
            if(arr1[i] + arr2[sze-i-1] > x) {
                flag = 1
                break;
            }
        }
        if(flag == 0){
            fmt.Println("Yes")
            } else {
                fmt.Println("No")
            }
        }
    }

package main

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

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

	in := bufio.NewReader(os.Stdin)

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

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

		a := make(sort.IntSlice, n)
		b := make(sort.IntSlice, n)

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

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

		sort.Sort(a)
		sort.Sort(sort.Reverse(b))

		for j := 0; j < n; j++ {
			if a[j]+b[j] > x {
				fmt.Fprint(out, "No\n")
				continue LOOP
			}
		}
		fmt.Fprint(out, "Yes\n")
	}
}

package main

import (
	"fmt"
	_ "net/http/pprof"
)

func main() {
	var(
		t,n,x,v int
	)
	fmt.Scanf("%d",&t)
	for ;t>0;t--{
		fmt.Scanf("%d%d",&n,&x)
		maxx,minn:=0,1001
		for i:=0;i<n;i++{
			fmt.Scanf("%d",&v)
			if maxx<v{
				maxx=v
			}
			if minn>v{
				minn=v
			}
		}
		if maxx+minn<=x{
			fmt.Println("Yes")
		}else{
			fmt.Println("No")
		}
	}
}

package main

import (
	"fmt"
	_ "net/http/pprof"
)

func main() {
	var(
		t,n,x,v int
	)
	fmt.Scan(&t)
	for ;t>0;t--{
		fmt.Scan(&n,&x)
		fmt.Println(n,x)
		maxx,minn:=0,1001
		for i:=0;i<n;i++{
			fmt.Scan(&v)
			if maxx<v{
				maxx=v
			}
		}
		for i:=0;i<n;i++{
			fmt.Scan(&v)
			if minn>v{
				minn=v
			}
		}
		if maxx+minn<=x{
			fmt.Println("Yes")
		}else{
			fmt.Println("No")
		}
	}
}

package main

import (
	"fmt"
	_ "net/http/pprof"
)

func main() {
	var(
		t,n,x,v int
	)
	fmt.Scan(&t)
	for ;t>0;t--{
		fmt.Scan(&n,&x)
		maxx,minn:=0,1001
		for i:=0;i<n;i++{
			fmt.Scan(&v)
			if maxx<v{
				maxx=v
			}
		}
		for i:=0;i<n;i++{
			fmt.Scan(&v)
			if minn>v{
				minn=v
			}
		}
		if maxx+minn<=x{
			fmt.Println("Yes")
		}else{
			fmt.Println("No")
		}
	}
}

package main

import (
	"fmt"
)

func main () {

	var t, n, x, v int
	var a, b [] int

	fmt.Scan(&t)

	for i := 1; i <= t; i++{

		fmt.Scan(&n, &x)

		for j := 1; j <= n; j++ {
			fmt.Scan(&v)
			a = append(a, v)
		}

		for k := 1; k <= n; k++ {
			fmt.Scan(&v)
			b = append(b, v)
		}

		fmt.Println(a,b)

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

			if a[l] + b[n - l - 1] <= x {

				if l == n - 1 {
					fmt.Println("Yes")
				}

				continue

			}	else {
				fmt.Println("No")
				break
			}
		}

		a = [] int {}
		b = [] int {}

	}

}

// You can edit this code!
// Click here and start typing.
package main

import (
	"fmt"
	"sort"
)

var a [55]int
var b [55]int

func main() {
		var t, n, x int
    fmt.Scanf("%d", &t)
    for i := 0; i < t; i++ {
				fmt.Scanf("%d%d", &n, &x)
				for i := 1; i <= n; i++ {
					fmt.Scanf("%d", &a[i])
				}
				for i := 1; i <= n; i++ {
					fmt.Scanf("%d", &b[i])
				}

				sort.Ints(a[:n])
				sort.Sort(sort.Reverse(sort.IntSlice(b[:n])))

				var t = "Yes"
				for i, _ := range b {
					if a[i] + b[i] > x {
						t = "No"
						break
					}
				}
				fmt.Println(t)
    }
}

// You can edit this code!
// Click here and start typing.
package main

import (
	"fmt"
	"sort"
)

var a [55]int
var b [55]int

func main() {
		var t, n, x int
    fmt.Scan(&t)
    for i := 0; i < t; i++ {
				fmt.Scan(&n, &x)
				fmt.Println(n, x)
				for i := 1; i <= n; i++ {
					fmt.Scan(&a[i])
				}
				for i := 1; i <= n; i++ {
					fmt.Scan(&b[i])
				}

				sort.Ints(a[1:n+1])
				sort.Sort(sort.Reverse(sort.IntSlice(b[1:n+1])))

				var t = "Yes"
				for i := 1; i <= n; i++ {
					if a[i] + b[i] > x {
						t = "No"
						break
					}
				}
				fmt.Println(t)
    }
}

// You can edit this code!
// Click here and start typing.
package main

import (
	"fmt"
	"sort"
)

var a [55]int
var b [55]int

func main() {
		var t, n, x int
    fmt.Scanf("%d", &t)
    for i := 0; i < t; i++ {
				fmt.Scanf("%d%d", &n, &x)
				for i := 1; i <= n; i++ {
					fmt.Scanf("%d", &a[i])
				}
				for i := 1; i <= n; i++ {
					fmt.Scanf("%d", &b[i])
				}

				sort.Ints(a[:n])
				sort.Sort(sort.Reverse(sort.IntSlice(b[:n])))

				var t = "Yes"
				for i := 1; i <= n; i++ {
					if a[i] + b[i] > x {
						t = "No"
						break
					}
				}
				fmt.Println(t)
    }
}

// You can edit this code!
// Click here and start typing.
package main

import (
	"fmt"
	"sort"
)

var a [55]int
var _b [55]int

func main() {
		var t, n, x int
    fmt.Scanf("%d", &t)
    for i := 0; i < t; i++ {
				fmt.Scanf("%d%d", &n, &x)
				for i := 1; i <= n; i++ {
					fmt.Scanf("%d", &a[i])
				}
				for i := 1; i <= n; i++ {
					fmt.Scanf("%d", &_b[i])
				}

				var b = _b[:]
				sort.Sort(sort.Reverse(sort.IntSlice(b)))

				var t = "Yes"
				for i, _ := range b {
					if a[i] + b[i] > x {
						t = "No"
						break
					}
				}
				fmt.Println(t)
    }
}

package main

import (
    "fmt"
)

func FindMinAndMax(arr []int) (int, int) {
    sze := len(arr)

    min_e := arr[0]
    max_e := arr[0]

    for i := 0; i < sze; i++ {
        if arr[i] < min_e {
            min_e = arr[i]
        }
        if arr[i] > max_e {
            max_e = arr[i]
        }
    }

    return min_e, max_e
}

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

    for i := 0; i < testCases; i++ {
        var sze int
        fmt.Scan(&sze)
        var x int
        fmt.Scan(&x)

        arr1 := make([]int, sze)
        arr2 := make([]int, sze)

        for i := 0; i < sze; i++ {
            fmt.Scan(&arr1[i])
        }

        for i := 0; i < sze; i++ {
            fmt.Scan(&arr2[i])
        }
        arr1Min, arr1Max := FindMinAndMax(arr1)
        arr2Min, arr2Max := FindMinAndMax(arr2)

        if arr1Min+arr2Max <= x && arr2Min+arr1Max <= x {
            fmt.Println("Yes")
        } else {
            fmt.Println("No")
        }
    }
}


The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates (xi, yi), a maximum brightness c, equal for all stars, and an initial brightness si (0 ≤ si ≤ c).Over time the stars twinkle. At moment 0 the i-th star has brightness si. Let at moment t some star has brightness x. Then at moment (t + 1) this star will have brightness x + 1, if x + 1 ≤ c, and 0, otherwise.You want to look at the sky q times. In the i-th time you will look at the moment ti and you will see a rectangle with sides parallel to the coordinate axes, the lower left corner has coordinates (x1i, y1i) and the upper right — (x2i, y2i). For each view, you want to know the total brightness of the stars lying in the viewed rectangle.A star lies in a rectangle if it lies on its border or lies strictly inside it.

The first line contains three integers n, q, c (1 ≤ n, q ≤ 105, 1 ≤ c ≤ 10) — the number of the stars, the number of the views and the maximum brightness of the stars. The next n lines contain the stars description. The i-th from these lines contains three integers xi, yi, si (1 ≤ xi, yi ≤ 100, 0 ≤ si ≤ c ≤ 10) — the coordinates of i-th star and its initial brightness. The next q lines contain the views description. The i-th from these lines contains five integers ti, x1i, y1i, x2i, y2i (0 ≤ ti ≤ 109, 1 ≤ x1i < x2i ≤ 100, 1 ≤ y1i < y2i ≤ 100) — the moment of the i-th view and the coordinates of the viewed rectangle.

For each view print the total brightness of the viewed stars.

NoteLet's consider the first example.At the first view, you can see only the first star. At moment 2 its brightness is 3, so the answer is 3.At the second view, you can see only the second star. At moment 0 its brightness is 0, so the answer is 0.At the third view, you can see both stars. At moment 5 brightness of the first is 2, and brightness of the second is 1, so the answer is 3.

package main

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

const SKY_SIZE int = 101

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	Q := io.NextInt()
	C := io.NextInt()

	sky := make([][][]int, C + 1)
	for t := 0; t <= C; t++ {
		sky[t] = MakeIntMatrix(SKY_SIZE, SKY_SIZE)
	}

	for i := 0; i < N; i++ {
		X := io.NextInt()
		Y := io.NextInt()
		S := io.NextInt()

		for t := 0; t <= C; t++ {
			sky[t][X][Y] += S
			S = (S + 1) % (C + 1)
		}
	}

	sums := make([][][]int, C + 1)
	for t := 0; t <= C; t++ {
		sums[t] = MakeIntMatrix(SKY_SIZE + 1, SKY_SIZE + 1)
	}

	for t := 0; t <= C; t++ {
		for r := 1; r <= SKY_SIZE; r++ {
			for c := 1; c <= SKY_SIZE; c++ {
				sums[t][r][c] = sky[t][r - 1][c - 1] + sums[t][r][c - 1] + sums[t][r - 1][c] - sums[t][r - 1][c - 1]
			}
		}
	}

	for q := 0; q < Q; q++ {
		T := io.NextInt()
		X1 := io.NextInt()
		Y1 := io.NextInt()
		X2 := io.NextInt()
		Y2 := io.NextInt()

		t := T % (C + 1)
		io.Println(sums[t][X2 + 1][Y2 + 1] - sums[t][X1][Y2 + 1] - sums[t][X2 + 1][Y1] + sums[t][X1][Y1])
	}
}

func MakeIntMatrix(rows, cols int) [][]int {
	mat := make([][]int, rows)
	for i := range mat {
		mat[i] = make([]int, cols)
	}
	return mat
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

const MAXN = 100
const MAXC = 10

func main() {
	var n, q, c int
	var pre [MAXN + 1][MAXN + 1][MAXC + 1]int

	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d %d %d\n", &n, &q, &c)

	for i := 0; i < n; i++ {
		var starx, stary, brightness int
		fmt.Fscanf(stdin, "%d %d %d\n", &starx, &stary, &brightness)
		pre[starx][stary][brightness] += 1
	}

	for i := 1; i <= MAXN; i++ {
		for j := 1; j <= MAXN; j++ {
			for b := 0; b <= c; b++ {
				pre[i][j][b] += pre[i-1][j][b] + pre[i][j-1][b] - pre[i-1][j-1][b]
			}
		}
	}

	stdout := bufio.NewWriter(os.Stdout)
	for i := 0; i < q; i++ {
		var t, x1, y1, x2, y2 int
		var ans = 0
		fmt.Fscanf(stdin,"%d %d %d %d %d\n", &t, &x1, &y1, &x2, &y2)

		for b := 0; b <= c; b++ {
			ans += (pre[x2][y2][b] - pre[x1-1][y2][b] -
				pre[x2][y1-1][b] + pre[x1-1][y1-1][b]) * ((b + t) % (c + 1))
		}
		fmt.Fprintf(stdout,"%d\n", ans)
	}

	stdout.Flush()

}

package main

import (
	"fmt"
)

const MAXN = 100

func main() {
	var n, q, c int
	var input [101][101]int
	var pre [101][101][11]int

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

	for i := 0; i < n; i++ {
		var starx, stary, brightness int
		fmt.Scanf("%d %d %d\n", &starx, &stary, &brightness)
		input[starx][stary] = brightness + 1
	}

	var included = 0
	for i := 1; i <= MAXN; i++ {
		for j := 1; j <= MAXN; j++ {
			for b := 0; b <= c; b++ {
				included = 0
				if b == input[i][j]-1 {
					included = 1
				}
				pre[i][j][b] = pre[i-1][j][b] + pre[i][j-1][b] + included - pre[i-1][j-1][b]
				//if included == 1 {
				//	fmt.Printf("included: %d %d %d %d\n", i, j, b, pre[i][j][b])
				//}
			}
		}
	}

	for i := 0; i < q; i++ {
		var t, x1, y1, x2, y2 int
		var ans = 0
		fmt.Scanf("%d %d %d %d %d\n", &t, &x1, &y1, &x2, &y2)

		for b := 0; b <= c; b++ {
			ans += (pre[x2][y2][b] - pre[x1-1][y2][b] -
				pre[x2][y1-1][b] + pre[x1-1][y1-1][b]) * ((b + t) % (c + 1))
		}
		fmt.Println(ans)
	}

}

package main

import (
	"fmt"
)

const MAXN  = 100

func main() {
	var n, q, c int
	var input [101][101]int
	var pre [101][101][11]int

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

	for i := 0; i < n; i++ {
		var starx, stary, brightness int
		fmt.Scanf("%d %d %d\n", &starx, &stary, &brightness)
		input[starx][stary] = brightness + 1
	}

	for i := 1; i <= MAXN; i++ {
		for j := 1; j <= MAXN; j++ {
			for b := 0; b <= c; b++ {
				var included = 0
				if b == input[i][j] - 1 {
					included = 1
				}
				pre[i][j][b] = pre[i-1][j][b] + pre[i][j-1][b] + included - pre[i-1][j-1][b]
			}
		}
	}

	for i := 0; i < q; i++ {
		var t, x1, y1, x2, y2 int
		var ans = 0
		fmt.Scanf("%d %d %d %d %d\n", &t, &x1, &y1, &x2, &y2)

		for b := 0; b <= c; b++ {
			included := 0
			if input[x1][y1] - 1 == b {
				included = 1
			}
			ans += (pre[x2][y2][b] - pre[x1][y1][b] + included) * ((b + t) % (c + 1))
		}
		fmt.Println(ans)
	}

}

package main

import (
	"fmt"
)

const MAXN = 100

func main() {
	var n, q, c int
	var input [101][101]int
	var pre [101][101][11]int

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

	for i := 0; i < n; i++ {
		var starx, stary, brightness int
		fmt.Scanf("%d %d %d\n", &starx, &stary, &brightness)
		input[starx][stary] = brightness + 1
	}

	for i := 1; i <= MAXN; i++ {
		for j := 1; j <= MAXN; j++ {
			for b := 0; b <= c; b++ {
				var included = 0
				if b == input[i][j]-1 {
					included = 1
				}
				pre[i][j][b] = pre[i-1][j][b] + pre[i][j-1][b] + included - pre[i-1][j-1][b]
			}
		}
	}

	for i := 0; i < q; i++ {
		var t, x1, y1, x2, y2 int
		var ans = 0
		fmt.Scanf("%d %d %d %d %d\n", &t, &x1, &y1, &x2, &y2)

		for b := 0; b <= c; b++ {
			ans += (pre[x2][y2][b] - pre[x1-1][y2][b] -
				pre[x2][y1-1][b] + pre[x1-1][y1-1][b]) * ((b + t) % (c + 1))
		}
		fmt.Println(ans)
	}

}

package main

import (
	"fmt"
)

const MAXN = 100

func main() {
	var n, q, c int64
	var input [101][101]int64
	var pre [101][101][11]int64

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

	for i := int64(0); i < n; i++ {
		var starx, stary, brightness int64
		fmt.Scanf("%d %d %d\n", &starx, &stary, &brightness)
		input[starx][stary] = brightness + 1
	}

	for i := 1; i <= MAXN; i++ {
		for j := 1; j <= MAXN; j++ {
			for b := int64(0); b <= c; b++ {
				var included = int64(0)
				if b == input[i][j]-1 {
					included = 1
				}
				pre[i][j][b] = pre[i-1][j][b] + pre[i][j-1][b] + included - pre[i-1][j-1][b]
			}
		}
	}

	for i := int64(0); i < q; i++ {
		var t, x1, y1, x2, y2 int64
		var ans = int64(0)
		fmt.Scanf("%d %d %d %d %d\n", &t, &x1, &y1, &x2, &y2)

		for b := int64(0); b <= c; b++ {
			ans += (pre[x2][y2][b] - pre[x1-1][y2][b] -
				pre[x2][y1-1][b] + pre[x1-1][y1-1][b]) * ((b + t) % (c + 1))
		}
		fmt.Println(ans)
	}

}

package main

import (
	"fmt"
)

const MAXN  = 100

func main() {
	var n, q, c int
	var input [101][101]int
	var pre [101][101][11]int

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

	for i := 0; i < n; i++ {
		var starx, stary, brightness int
		fmt.Scanf("%d %d %d\n", &starx, &stary, &brightness)
		input[starx][stary] = brightness + 1
	}

	for i := 1; i <= MAXN; i++ {
		for j := 1; j <= MAXN; j++ {
			for b := 0; b <= c; b++ {
				var counted = 0
				if b == input[i][j] - 1 {
					counted = 1
				}
				pre[i][j][b] = pre[i-1][j][b] + pre[i][j-1][b] + counted - pre[i-1][j-1][b]
			}
		}
	}

	for i := 0; i < q; i++ {
		var t, x1, y1, x2, y2 int
		var ans int
		fmt.Scanf("%d %d %d %d %d\n", &t, &x1, &y1, &x2, &y2)

		for c1 := 0; c1 <= c; c1++ {
			included := 0
			if input[x1][y1] - 1 == c1 {
				included = 1
			}
			ans += (pre[x2][y2][c1] - pre[x1][y1][c1] + included) * ((c1 + t) % (c + 1))
		}
		fmt.Println(ans)
	}

}

package main

import (
	"fmt"
)

const MAXN  = 100

func main() {
	var n, q, c int
	var input [101][101]int
	var pre [101][101][11]int

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

	for i := 0; i < n; i++ {
		var starx, stary, brightness int
		fmt.Scanf("%d %d %d\n", &starx, &stary, &brightness)
		input[starx][stary] = brightness + 1
	}

	for i := 1; i <= MAXN; i++ {
		for j := 1; j <= MAXN; j++ {
			for b := 0; b <= c; b++ {
				var counted = 0
				if b == input[i][j] - 1 {
					counted = 1
				}
				pre[i][j][b] = pre[i-1][j][b] + pre[i][j-1][b] + counted - pre[i-1][j-1][b]
			}
		}
	}

	for i := 0; i < q; i++ {
		var t, x1, y1, x2, y2 int
		var ans int
		fmt.Scanf("%d %d %d %d %d\n", &t, &x1, &y1, &x2, &y2)

		for c1 := 0; c1 <= 10; c1++ {
			included := 0
			if input[x1][y1] - 1 == c1 {
				included = 1
			}
			ans += (pre[x2][y2][c1] - pre[x1][y1][c1] + included) * ((c1 + t) % (c + 1))
		}
		fmt.Println(ans)
	}

}


Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.It is guaranteed that such a sequence always exists.

The first line contains a single integer number n (1 ≤ n ≤ 300). Next n lines contain integer numbers b1, ..., bn  — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.

Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.  If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.

package main

import "os"
import "fmt"
import "bufio"

var (
    reader = bufio.NewReader(os.Stdin)
)

const MAXLEN = 90000

var number [2][MAXLEN]byte
var pre, now *[MAXLEN]byte

func output(data [MAXLEN]byte) {
    for i, flag := 0, false; i < MAXLEN; i++ {
        if(data[i] != 0) { flag = true }
        if(flag) {
            fmt.Print(data[i])
        }
    }
    fmt.Println()
}

func work(presum, data uint64) {
    for i := 0; i < MAXLEN; i++ {
        now[i] = 0
    }
    if(data > presum) {
        data -= presum
        for i := MAXLEN-1; i >= 0; i-- {
            if(data > uint64(9-pre[i])) {
                data -= uint64(9-pre[i])
                now[i] = 9
            } else {
                now[i] = pre[i] + byte(data)
                data = 0;
            }
        }
    } else {
        data = presum - data + 1
        add := 0
        for i, flag, sum := MAXLEN-1, false, uint64(0); i >= 0; i-- {
            if(data > sum) {
                sum += uint64(pre[i])
            } else if(flag == false) {
                if(pre[i] < 9) {
                    now[i] = pre[i] + byte(1)
                    flag = true
                    add = i
                } else {
                    sum += uint64(pre[i])
                    now[i] = pre[i]
                }
            } else {
                if(sum + data > 0) {
                    sum -= data
                    for j := MAXLEN-1; j > add; j-- {
                        if(sum > 9) {
                            now[j] = 9
                            sum -= 9
                        } else {
                            now[j] = byte(sum)
                            sum = 0
                        }
                    }
                    data = 0
                }
                now[i] = pre[i]
            }
        }
    }
    output(*now)
    now, pre = pre, now
}

func main() {
    var n uint64
    fmt.Fscan(reader, &n)
    pre, now = &number[0], &number[1]
    for i, presum := uint64(0), uint64(0); i < n; i++ {
        var data uint64
        fmt.Fscan(reader, &data)
        work(presum, data)
        presum = data
    }
}

package main

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

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 getLine() string {
	s, _ := reader.ReadString('\n')
	if strings.HasSuffix(s, "\r\n") {
		s = s[:len(s)-2]
	} else if strings.HasSuffix(s, "\n") {
		s = s[:len(s)-1]
	}
	return s
}
func getLine2Int() (n int) {
	scanf("%d\n", &n)
	return
}
func getLine2Int2() (a, b int) {
	scanf("%d %d\n", &a, &b)
	return
}
func getLine2Ints(n int) []int {
	ans := make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d ", &ans[i])
	}
	scanf("%d\n", &ans[n-1])
	return ans
}

func pcheck(i bool) {
	if i {
		printf("YES\n")
	} else {
		printf("NO\n")
	}
}

var debug = true

func see(a interface{}) {
	if debug {
		printf("DEBUG:%v\n", a)
	}
}

var now = make([]int, 1000)
var nowsum = 0

func fixDiff(diff int) int {
	if diff > 0 {
		return diff
	}
	status := 0
	for i := 0; ; i++ {
		switch status {
		case 0:
			now[i], diff = 0, diff+now[i]
			if diff > 0 {
				status = 1
			}
		case 1:
			if now[i] != 9 {
				diff, now[i] = diff-1, now[i]+1
				return diff
			}
			now[i], diff = 0, diff+now[i]
		}
	}
}

func addDiff(diff int) {
	for i := 0; diff > 0; i++ {
		now[i], diff = now[i]+diff, 0
		if now[i] > 9 {
			now[i], diff = 9, now[i]-9
		}
	}
}

func put() {
	status := 0
	for i := 999; i >= 0; i-- {
		switch status {
		case 0:
			if now[i] != 0 { // first item not equals zero
				printf("%d", now[i])
				status = 1
			}
		case 1:
			printf("%d", now[i])
		}
	}
	printf("\n")
}

func main() {
	defer writer.Flush()

	n := getLine2Int()
	for in := 0; in < n; in++ {
		tmp := getLine2Int()
		addDiff(fixDiff(tmp - nowsum))
		nowsum = tmp
		put()
	}
}

package main

import "os"
import "fmt"
import "bufio"

var (
    reader = bufio.NewReader(os.Stdin)
)

const MAXLEN = 90000

var number [2][MAXLEN]byte
var pre, now *[MAXLEN]byte

func output(data [MAXLEN]byte) {
    for i, flag := 0, false; i < MAXLEN; i++ {
        if(data[i] != 0) { flag = true }
        if(flag) {
            fmt.Print(data[i])
        }
    }
    fmt.Println()
}

func work(presum, data uint64) {
    for i := 0; i < MAXLEN; i++ {
        now[i] = 0
    }
    if(data > presum) {
        data -= presum
        for i := MAXLEN-1; i >= 0; i-- {
            if(data > uint64(9-pre[i])) {
                data -= uint64(9-pre[i])
                now[i] = 9
            } else {
                now[i] = pre[i] + byte(data)
                data = 0;
            }
        }
    } else {
        data = presum - data + 1
        add := 0
        for i, flag, sum := MAXLEN-1, false, uint64(0); i >= 0; i-- {
            if(data > sum) {
                sum += uint64(pre[i])
            } else if(flag == false) {
                if(pre[i] < 9) {
                    now[i] = pre[i] + byte(1)
                    flag = true
                    add = i
                } else {
                    sum += uint64(pre[i])
                    now[i] = pre[i]
                }
            } else {
                if(sum + data > 0) {
                    sum -= data
                    for j := MAXLEN-1; j > add; j-- {
                        if(sum > 9) {
                            now[j] = 9
                            sum -= 9
                        } else {
                            now[j] = byte(sum)
                            sum = 0
                        }
                    }
                }
                now[i] = pre[i]
            }
        }
    }
    output(*now)
    now, pre = pre, now
}

func main() {
    var n uint64
    fmt.Fscan(reader, &n)
    pre, now = &number[0], &number[1]
    for i, presum := uint64(0), uint64(0); i < n; i++ {
        var data uint64
        fmt.Fscan(reader, &data)
        work(presum, data)
        presum = data
    }
}

package main

import "os"
import "fmt"
import "bufio"

var (
    reader = bufio.NewReader(os.Stdin)
)

const MAXLEN = 90000

var number [2][MAXLEN]byte
var pre, now *[MAXLEN]byte

func output(data [MAXLEN]byte) {
    for i, flag := 0, false; i < MAXLEN; i++ {
        if(data[i] != 0) { flag = true }
        if(flag) {
            fmt.Print(data[i])
        }
    }
    fmt.Println()
}

func work(presum, data uint64) {
    for i := 0; i < MAXLEN; i++ {
        now[i] = 0
    }
    if(data > presum) {
        data -= presum
        for i := MAXLEN-1; i >= 0; i-- {
            if(data > uint64(9-pre[i])) {
                data -= uint64(9-pre[i])
                now[i] = 9
            } else {
                now[i] = pre[i] + byte(data)
                data = 0;
            }
        }
    } else {
        data = presum - data + 1
        for i, flag := MAXLEN-1, false; i >= 0; i-- {
            if(data > 0) {
                if(data > uint64(pre[i])) {
                    data -= uint64(pre[i])
                    now[i] = 0
                } else {
                    now[i] = pre[i] - byte(data)
                    data = 0
                }
            } else if(flag == false) {
                if(pre[i] < 9) {
                    now[i] = pre[i] + byte(1)
                    flag = true
                } else {
                    now[i] = pre[i]
                }
            } else {
                now[i] = pre[i]
            }
        }
    }
    output(*now)
    now, pre = pre, now
}

func main() {
    var n uint64
    fmt.Fscan(reader, &n)
    pre, now = &number[0], &number[1]
    for i, presum := uint64(0), uint64(0); i < n; i++ {
        var data uint64
        fmt.Fscan(reader, &data)
        work(presum, data)
        presum = data
    }
}

package main

import "os"
import "fmt"
import "bufio"

var (
    reader = bufio.NewReader(os.Stdin)
)

func work(pre *uint64, presum, data uint64) {
    if(data > presum) {
        data -= presum
        var now uint64 = 0
        var tmp uint64 = *pre
        var s uint64 = 1
        for ; tmp > 0 || data > 0; {
            v := tmp%10
            tmp /= 10
            if(data > 9-v) {
                data -= 9-v
                v = 9
            } else {
                v += data
                data = 0
            }
            now += v*s
            s *= 10
        }
        *pre = now
        fmt.Println(now)
    } else {
        data = presum - data + 1
        var now uint64 = 0
        var tmp uint64 = *pre
        var s uint64 = 1
        for ; data > 0; {
            v := tmp%10
            tmp /= 10
            if(data > v) {
                data -= v
                v = 0
            } else {
                v -= data
                data = 0
            }
            now += v*s
            s *= 10
        }
        flag := false
        for ; flag == false || tmp > 0; {
            v := tmp%10
            tmp /= 10
            if(flag == false && v < 9) {
                v += 1
                flag = true
            }
            now += v*s
            s *= 10
        }
        *pre = now
        fmt.Println(now)
    }
}

func main() {
    var n uint64
    fmt.Fscan(reader, &n)
    for i, pre, presum := uint64(0), uint64(0), uint64(0); i < n; i++ {
        var data uint64
        fmt.Fscan(reader, &data)
        work(&pre, presum, data)
        presum = data
    }
}

package main

import "os"
import "fmt"
import "bufio"

var (
    reader = bufio.NewReader(os.Stdin)
)

func work(pre *uint64, presum, data uint64) {
    if(data > presum) {
        data -= presum
        var now uint64 = 0
        var tmp uint64 = *pre
        var s uint64 = 1
        for ; tmp > 0 || data > 0; {
            v := tmp%10
            tmp /= 10
            if(data > 9-v) {
                data -= 9-v
                v = 9
            } else {
                v += data
                data = 0
            }
            now += v*s
            s *= 10
        }
        *pre = now
        fmt.Println(now)
    } else {
        data = presum - data + 1
        var now uint64 = 0
        var tmp uint64 = *pre
        var s uint64 = 1
        for ; data > 0; {
            v := tmp%10
            tmp /= 10
            if(data > v) {
                data -= v
                v = 0
            } else {
                v -= data
                data = 0
            }
            now += v*s
            s *= 10
        }
        for ; true; {
            v := tmp%10
            tmp /= 10
            flag := false
            if(v < 9) {
                v += 1
                flag = true
            }
            now += v*s
            s *= 10
            if(flag == true) {
                break
            }
        }
        *pre = now
        fmt.Println(now)
    }
}

func main() {
    var n uint64
    fmt.Fscan(reader, &n)
    for i, pre, presum := uint64(0), uint64(0), uint64(0); i < n; i++ {
        var data uint64
        fmt.Fscan(reader, &data)
        work(&pre, presum, data)
        presum = data
    }
}


Denis was very sad after Nastya rejected him. So he decided to walk through the gateways to have some fun. And luck smiled at him! When he entered the first courtyard, he met a strange man who was selling something. Denis bought a mysterious item and it was... Random permutation generator! Denis could not believed his luck.When he arrived home, he began to study how his generator works and learned the algorithm. The process of generating a permutation consists of $$$n$$$ steps. At the $$$i$$$-th step, a place is chosen for the number $$$i$$$ $$$(1 \leq i \leq n)$$$. The position for the number $$$i$$$ is defined as follows:  For all $$$j$$$ from $$$1$$$ to $$$n$$$, we calculate $$$r_j$$$  — the minimum index such that $$$j \leq r_j \leq n$$$, and the position $$$r_j$$$ is not yet occupied in the permutation. If there are no such positions, then we assume that the value of $$$r_j$$$ is not defined.  For all $$$t$$$ from $$$1$$$ to $$$n$$$, we calculate $$$count_t$$$  — the number of positions $$$1 \leq j \leq n$$$ such that $$$r_j$$$ is defined and $$$r_j = t$$$.  Consider the positions that are still not occupied by permutation and among those we consider the positions for which the value in the $$$count$$$ array is maximum.  The generator selects one of these positions for the number $$$i$$$. The generator can choose any position. Let's have a look at the operation of the algorithm in the following example:  Let $$$n = 5$$$ and the algorithm has already arranged the numbers $$$1, 2, 3$$$ in the permutation. Consider how the generator will choose a position for the number $$$4$$$:  The values of $$$r$$$ will be $$$r = [3, 3, 3, 4, \times]$$$, where $$$\times$$$ means an indefinite value.  Then the $$$count$$$ values will be $$$count = [0, 0, 3, 1, 0]$$$.  There are only two unoccupied positions in the permutation: $$$3$$$ and $$$4$$$. The value in the $$$count$$$ array for position $$$3$$$ is $$$3$$$, for position $$$4$$$ it is $$$1$$$.  The maximum value is reached only for position $$$3$$$, so the algorithm will uniquely select this position for number $$$4$$$. Satisfied with his purchase, Denis went home. For several days without a break, he generated permutations. He believes that he can come up with random permutations no worse than a generator. After that, he wrote out the first permutation that came to mind $$$p_1, p_2, \ldots, p_n$$$ and decided to find out if it could be obtained as a result of the generator.Unfortunately, this task was too difficult for him, and he asked you for help. It is necessary to define whether the written permutation could be obtained using the described algorithm if the generator always selects the position Denis needs.

The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^5)$$$  — the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 10^5)$$$  — the size of the permutation. The second line of the test case contains $$$n$$$ different integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \leq p_i \leq n$$$)  — the permutation written by Denis. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.

Print "Yes" if this permutation could be obtained as a result of the generator. Otherwise, print "No". All letters can be displayed in any case.

NoteLet's simulate the operation of the generator in the first test.At the $$$1$$$ step, $$$r = [1, 2, 3, 4, 5], count = [1, 1, 1, 1, 1]$$$. The maximum value is reached in any free position, so the generator can choose a random position from $$$1$$$ to $$$5$$$. In our example, it chose $$$5$$$.At the $$$2$$$ step, $$$r = [1, 2, 3, 4, \times], count = [1, 1, 1, 1, 0]$$$. The maximum value is reached in positions from $$$1$$$ to $$$4$$$, so the generator can choose a random position among them. In our example, it chose $$$1$$$.At the $$$3$$$ step, $$$r = [2, 2, 3, 4, \times], count = [0, 2, 1, 1, 0]$$$. The maximum value is $$$2$$$ and is reached only at the $$$2$$$ position, so the generator will choose this position.At the $$$4$$$ step, $$$r = [3, 3, 3, 4, \times], count = [0, 0, 3, 1, 0]$$$. The maximum value is $$$3$$$ and is reached only at the $$$3$$$ position, so the generator will choose this position.At the $$$5$$$ step, $$$r = [4, 4, 4, 4, \times], count = [0, 0, 0, 4, 0]$$$. The maximum value is $$$4$$$ and is reached only at the $$$4$$$ position, so the generator will choose this position.In total, we got a permutation of $$$2, 3, 4, 5, 1$$$, that is, a generator could generate it.

/*
URL:
https://codeforces.com/problemset/problem/1340/A
*/

package main

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

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

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

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

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

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

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

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

var (
	t int

	n int
	P []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n = ReadInt()
		P = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	for i := 0; i < n-1; i++ {
		if P[i+1]-P[i] > 1 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}

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

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

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

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

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

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

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

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

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

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

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

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

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

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

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

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

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

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

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

// Author: sighduck
// URL: https://codeforces.com/contest/1340/problem/A

package main

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

func _Solve(n int, p []int, index []int, visited []bool, value int, valueIndex int) string {
	if value == n+1 {
		return "Yes"
	}
	vI := valueIndex
	if valueIndex == -1 {
		vI = index[value]
	}
	if p[vI] == value {
		visited[vI] = true
		if vI+1 < n && !visited[vI+1] {
			return _Solve(n, p, index, visited, value+1, vI+1)
		}
		return _Solve(n, p, index, visited, value+1, -1)
	}
	return "No"
}

func Solve(n int, p []int) string {
	index := make([]int, n+1)
	for i, elem := range p {
		index[elem] = i
	}
	visited := make([]bool, n)
	return _Solve(n, p, index, visited, 1, index[1])
}

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

	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		p := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &p[i])
		}
		fmt.Fscanf(reader, "\n")
		fmt.Fprintf(writer, "%s\n", Solve(n, p))
	}
}

package main

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

func main() {
	s := NewScanner()
	t := s.NextInt()

Next:
	for i := 0; i < t; i++ {
		n := s.NextInt()

		ar := make([]int, n)
		m := map[int]int{}
		for k := 0; k < n; k++ {
			ar[k] = s.NextInt()
			m[ar[k]] = k
		}

		for j := 1; j <= n-1; j++ {
			idx := m[j]
			if idx != n-1 && ar[idx] < ar[idx+1] && ar[idx+1]-ar[idx] != 1 {
				fmt.Println("No")
				continue Next
			}
		}

		fmt.Println("Yes")
	}
}

type scanner struct {
	*bufio.Scanner
}

func NewScanner() *scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &scanner{s}
}

func (s *scanner) NextInt() int {
	s.Scan()
	i, _ := strconv.Atoi(s.Text())
	return i
}

func (s *scanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *scanner) NextString() string {
	s.Scan()
	return s.Text()
}

package main

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

func main() {
	rd := bufio.NewReader(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)

	var t, n, i, j, k, l int
	var bo bool
	fmt.Fscanf(rd, "%d\n", &t)
	for i = 0; i < t; i++ {
		fmt.Fscanf(rd, "%d\n", &n)
		bo = true
		for j = 0; j < n; j++ {
			fmt.Fscanf(rd, "%d", &k)
			if j > 0 && bo {
				if k > l {
					if k != l+1 {
						fmt.Fprintf(wr, "No\n")
						bo = false
					}
				}
			}
			l = k
		}
		if bo {
			fmt.Fprintf(wr, "Yes\n")
		}
		fmt.Fscanf(rd, "\n")
	}

	wr.Flush()
}

package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

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

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

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

var sc = newScanner()

func solve(a []int) bool {
	min, max := 1, 1
	var prev int
	for i := len(a) - 1; i >= 0; i-- {
		if prev != 0 {
			if a[i] == prev-1 {
				if a[i] == min {
					min = max + 1
					prev = 0
				} else {
					prev--
				}
			} else {
				return false
			}
		} else {
			if a[i] == min {
				min++
			} else {
				prev, max = a[i], a[i]
			}
		}
	}
	return true
}

func main() {
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	for t := scanInt(); t > 0; t-- {
		n := scanInt()
		a := scanInts(n)
		if solve(a) {
			fmt.Fprintln(w, "Yes")
		} else {
			fmt.Fprintln(w, "No")
		}
	}
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n := reader.NextInt64()
		pp := make([]int64, n)
		for i := int64(0); i < n; i++ {
			pp[i] = reader.NextInt64()
		}
		writer.Printf("%s\n", sol(pp))
	}
}

func sol(pp []int64) string {
	for i := 1; i < len(pp); i++ {
		if pp[i] > pp[i-1] && pp[i] != pp[i-1]+1 {
			return "No"
		}
	}
	return "Yes"
}

package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

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

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

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

var sc = newScanner()

func solve(a []int) bool {
	min, max := 1, 1
	var prev int
	for i := len(a) - 1; i >= 0; i-- {
		if prev != 0 {
			if a[i] == prev-1 {
				if a[i] == min {
					min = max + 1
					prev = 0
				} else {
					prev--
				}
			} else {
				return false
			}
		} else {
			if a[i] == min {
				min = max + 1
				prev = 0
			} else {
				prev, max = a[i], a[i]
			}
		}
	}
	return true
}

func main() {
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	for t := scanInt(); t > 0; t-- {
		n := scanInt()
		a := scanInts(n)
		if solve(a) {
			fmt.Fprintln(w, "Yes")
		} else {
			fmt.Fprintln(w, "No")
		}
	}
}

package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

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

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

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

var sc = newScanner()

func solve(a []int) bool {
	min := 1
	var max, prev int
	for i := len(a) - 1; i >= 0; i-- {
		if a[i] == min {
			min++
			prev = 0
			continue
		}
		if prev == 0 {
			prev, max = a[i], a[i]
			continue
		}
		if a[i] == prev-1 {
			prev--
			if prev == min {
				min = max + 1
				prev = 0
			}
		} else {
			return false
		}
	}
	return true
}

func main() {
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	for t := scanInt(); t > 0; t-- {
		n := scanInt()
		a := scanInts(n)
		if solve(a) {
			fmt.Fprintln(w, "Yes")
		} else {
			fmt.Fprintln(w, "No")
		}
	}
}

package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

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

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

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

var sc = newScanner()

func solve(a []int) bool {
	min := 1
	var prev int
	for i := len(a) - 1; i >= 0; i-- {
		if a[i] == min {
			min++
			prev = 0
			continue
		}
		if prev == 0 {
			prev = a[i]
		} else {
			if a[i] == prev-1 {
				prev--
				if prev == min {
					prev = 0
				}
			} else {
				return false
			}
		}
	}
	return true
}

func main() {
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	for t := scanInt(); t > 0; t-- {
		n := scanInt()
		a := scanInts(n)
		if solve(a) {
			fmt.Fprintln(w, "Yes")
		} else {
			fmt.Fprintln(w, "No")
		}
	}
}


Let's denote a $$$k$$$-step ladder as the following structure: exactly $$$k + 2$$$ wooden planks, of which  two planks of length at least $$$k+1$$$ — the base of the ladder;  $$$k$$$ planks of length at least $$$1$$$ — the steps of the ladder; Note that neither the base planks, nor the steps planks are required to be equal.For example, ladders $$$1$$$ and $$$3$$$ are correct $$$2$$$-step ladders and ladder $$$2$$$ is a correct $$$1$$$-step ladder. On the first picture the lengths of planks are $$$[3, 3]$$$ for the base and $$$[1]$$$ for the step. On the second picture lengths are $$$[3, 3]$$$ for the base and $$$[2]$$$ for the step. On the third picture lengths are $$$[3, 4]$$$ for the base and $$$[2, 3]$$$ for the steps.   You have $$$n$$$ planks. The length of the $$$i$$$-th planks is $$$a_i$$$. You don't have a saw, so you can't cut the planks you have. Though you have a hammer and nails, so you can assemble the improvised "ladder" from the planks.The question is: what is the maximum number $$$k$$$ such that you can choose some subset of the given planks and assemble a $$$k$$$-step ladder using them?

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. The queries are independent. Each query consists of two lines. The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of planks you have. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$) — the lengths of the corresponding planks. It's guaranteed that the total number of planks from all queries doesn't exceed $$$10^5$$$.

Print $$$T$$$ integers — one per query. The $$$i$$$-th integer is the maximum number $$$k$$$, such that you can choose some subset of the planks given in the $$$i$$$-th query and assemble a $$$k$$$-step ladder using them. Print $$$0$$$ if you can't make even $$$1$$$-step ladder from the given set of planks.

NoteExamples for the queries $$$1-3$$$ are shown at the image in the legend section.The Russian meme to express the quality of the ladders:

package main

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

/* solution */

func solve() {

	q := readInt()

	for i := 0; i < q; i++ {
		solveSingle()
	}

}

func solveSingle() {

	n := readInt()

	a, b := -1, -1
	for i := 0; i < n; i++ {
		v := readInt()
		if v >= a {
			b = a
			a = v
		} else if v > b {
			b = v
		}
	}

	if b-1 <= n-2 {
		printInt(b - 1)
	} else if n-2 >= 0 {
		printInt(n - 2)
	} else {
		printInt(0)
	}

}

/* 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 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"
	"sort"
)

func main() {
	var n, q int
	var st string

	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &q)

	for i := 0; i < q; i++ {
		fmt.Fscanln(scr, &n)

		a := make([]int, n)

		for j := 0; j < n; j++ {
			fmt.Fscanf(scr, "%d", &a[j])
		}
		fmt.Fscanln(scr, &st)

		sort.Ints(a)

		if len(a)-2 <= a[len(a)-2]-1 {
			fmt.Println(len(a) - 2)
		} else {
			fmt.Println(a[len(a)-2] - 1)
		}
	}

}

package main

import (
	"fmt"
	"sort"
)

func ReadN(all []int, i, n int) {
	if n == 0 {
		return
	}
	if m, err := Scan(&all[i]); m != 1 {
		panic(err)
	}
	ReadN(all, i+1, n-1)
}

func Scan(a *int) (int, error) {
	return fmt.Scan(a)
}

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

func main()  {
	var requests int
	Scan(&requests)
	for j:=0;j < requests ;j++ {
		var ledCount int
		Scan(&ledCount)
		ledges := make([]int, ledCount)
		ReadN(ledges, 0, ledCount)
		sort.Ints(ledges[:])

		fmt.Printf("%d\n", min(ledges[ledCount - 2] - 1, ledCount - 2))
	}
}

//1
//4
//1 3 1 3

//HOWDY! IT'S ME! A HARD BLACKISH DICK MOVE!
package main

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

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

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := PrintlnInts(X...)

/*******************************************************************/
func max2(a []int) (int, int) {
	max1, max2 := 0, 0
	for _, v := range a {
		if v >= max2 {
			max1, max2 = max2, v
		} else if v > max1 {
			max1 = v
		}
	}
	return max1, max2
}

func main() {
	for t := ReadInt(); t > 0; t-- {
		n := ReadInt()
		a := ReadIntSlice(n)
		m1, _ := max2(a)
		fmt.Println(min(m1-1, n-2))
	}
}

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

func min(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func max(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

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

func gcd(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	gcd := args[0]
	for i := 1; i < len(args); i++ {
		gcd = _gcd(gcd, args[i])
	}
	return gcd
}

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9))
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

// ReadInt returns an integer.
func ReadInt() int {
	return readInt()
}
func ReadInt2() (int, int) {
	return readInt(), readInt()
}
func ReadInt3() (int, int, int) {
	return readInt(), readInt(), readInt()
}
func ReadInt4() (int, int, int, int) {
	return readInt(), readInt(), readInt(), readInt()
}

func readInt_64() int64 {
	return readIntNbits(64)
}

func ReadInt2_64() (int64, int64) {
	return readInt_64(), readInt_64()
}

func ReadInt3_64() (int64, int64, int64) {
	return readInt_64(), readInt_64(), readInt_64()
}

func readInt() int {
	return int(readIntNbits(32))
}

func readIntNbits(n int) int64 {
	i, err := strconv.ParseInt(ReadString(), 0, n)
	if err != nil {
		panic(err.Error())
	}
	return i
}

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

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

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

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

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

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

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

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

	return string(res)
}

package main

import (
 "fmt"
 "sort"
)

func main() {

 var testCase int

 if _, err := fmt.Scan(&testCase); err != nil {
 }

 for testCase > 0 {
  testCase -= 1
  var plankNum int
  if _, err := fmt.Scan(&plankNum); err != nil {
  }

  planks := make([]int, plankNum)
  for i := 0; i < plankNum; i += 1 {
   if _, err := fmt.Scan(&planks[i]); err != nil {
   }
  }

  if plankNum < 3 {
   fmt.Println(0)
   continue
  }

  sort.Ints(planks)
  m := planks[plankNum-2]

  if m-1 < plankNum-2 {

  if m - 1 < 0 {
    m = 1
  }
   fmt.Println(m - 1)
  } else {

   if plankNum - 2 < 0 {
    plankNum = 2
   }
   fmt.Println(plankNum - 2)
  }
 }
}

package main

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

func main() {

	//stdin, err := os.Open("test.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)
		for j := 0; j < n; j++ {
			fmt.Fscanf(reader, "%d", &a[j])
		}
		fmt.Fscanf(reader, "\n")
		sort.Ints(a)
		fmt.Fprintf(writer, "%d\n", int(math.Min(float64(n-2), math.Min(float64(a[n-1]-1), float64(a[n-2]-1)))))
	}

	writer.Flush()
}

// Author: sighduck
// URL: https://codeforces.com/contest/1197/problem/A

package main

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

func Solve(n int, a []int) int {
	if n == 2 {
		return 0
	}
	sort.Ints(a)
	baseK := a[n-2] - 1
	stepK := n - 2
	if stepK < baseK {
		return stepK
	}
	return baseK
}

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

	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &a[i])
		}
		fmt.Fscanf(reader, "\n")
		fmt.Fprintf(writer, "%d\n", Solve(n, a))
	}
}

package main

import (
	"fmt"
	"sort"
)

func ReadN(all []int, i, n int) {
	if n == 0 {
		return
	}
	if m, err := Scan(&all[i]); m != 1 {
		panic(err)
	}
	ReadN(all, i+1, n-1)
}

func Scan(a *int) (int, error) {
	return fmt.Scan(a)
}

func main()  {
	var requests int
	Scan(&requests)
	for j:=0;j < requests ;j++ {
		var ledCount int
		Scan(&ledCount)
		if ledCount < 3 {
			fmt.Printf("0\n")
			return
		}

		ledges := make([]int, ledCount)
		ReadN(ledges, 0, ledCount)
		sort.Ints(ledges[:])
		//fmt.Println(ledges)

		var optimalLedge int
		if ledges[ledCount - 1] < ledges[ledCount - 2] {
			optimalLedge = ledges[ledCount - 1]
		} else {
			optimalLedge = ledges[ledCount - 2]
		}
		//fmt.Println(optimalLedge)

		if optimalLedge - (ledCount - 2) > 0 {
			fmt.Printf("%d\n",ledCount - 2)
		} else {
			fmt.Printf("%d\n",optimalLedge - 1)
		}
	}
}

//1
//4
//1 3 1 3

package main

import (
 "fmt"
 "sort"
)

func main() {

 var testCase int

 if _, err := fmt.Scanln(&testCase); err != nil {
 }

 for testCase > 0 {
  testCase -= 1
  var plankNum int
  if _, err := fmt.Scanln(&plankNum); err != nil {
  }

  planks := make([]int, plankNum)
  for i := 0; i < plankNum; i += 1 {
   if _, err := fmt.Scan(&planks[i]); err != nil {
   }
  }

  if plankNum < 3 {
   fmt.Println(0)
   continue
  }

  sort.Ints(planks)
  m := planks[plankNum-2]

  if m-1 < plankNum-2 {

  if m - 1 < 0 {
    m = 1
  }
   fmt.Println(m - 1)
  } else {

   if plankNum - 2 < 0 {
    plankNum = 2
   }
   fmt.Println(plankNum - 2)
  }
 }
}