Given an array $$$a$$$ of length $$$n$$$, find another array, $$$b$$$, of length $$$n$$$ such that:  for each $$$i$$$ $$$(1 \le i \le n)$$$ $$$MEX(\{b_1$$$, $$$b_2$$$, $$$\ldots$$$, $$$b_i\})=a_i$$$. The $$$MEX$$$ of a set of integers is the smallest non-negative integer that doesn't belong to this set.If such array doesn't exist, determine this.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_n$$$ ($$$0 \le a_i \le i$$$) — the elements of the array $$$a$$$. It's guaranteed that $$$a_i \le a_{i+1}$$$ for $$$1\le i < n$$$.

If there's no such array, print a single line containing $$$-1$$$. Otherwise, print a single line containing $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, $$$\ldots$$$, $$$b_n$$$ ($$$0 \le b_i \le 10^6$$$) If there are multiple answers, print any.

NoteIn the second test case, other answers like $$$[1,1,1,0]$$$, for example, are valid.

package main

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

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

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

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

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

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

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

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

	return i
}

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

	n := readNum(reader)
	A := readNNums(reader, n)
	B := solve(n, A)
	if len(B) == 0 {
		fmt.Println(-1)
		return
	}
	var buf bytes.Buffer
	for i := 0; i < n; i++ {
		buf.WriteString(strconv.Itoa(B[i]))
		buf.WriteByte(' ')
	}
	fmt.Println(buf.String())
}

const MAX = 1000000

func solve(n int, A []int) []int {
	ex := make([]bool, MAX+1)
	B := make([]int, n)
	for i := 0; i < n; i++ {
		B[i] = -1
	}
	for i := 1; i < n; i++ {
		if A[i] != A[i-1] {
			B[i] = A[i-1]
			ex[B[i]] = true
		}
	}

	ex[A[n-1]] = true
	var mex int
	for i := 0; i < n; i++ {
		for ex[mex] {
			mex++
		}
		if B[i] == -1 {
			B[i] = mex
			ex[mex] = true
		}
	}

	return B
}

package main

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

var checked []bool
var edges [][]int
var cnt int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	//fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
		}
		fmt.Fscanf(in, "\n")
		// if a[0] == 0 && a[n-1] == n {
		// 	fmt.Fprintf(out, "-1\n")
		// 	continue
		// }
		ans := make([]int, n)
		i := n - 1
		random := n + 1
		needToFill := []int{}
		filled := make(map[int]bool)
		for i >= 0 {
			from := i
			to := i
			for from > 0 && a[from-1] == a[from] {
				from--
			}
			if from != 0 {
				ans[from] = a[from-1]
				//fmt.Println("debug", a[from-1])
			} else if a[0] == 1 {
				ans[from] = 0
			} else {
				if len(needToFill) > 0 {
					ans[from] = needToFill[0]
					needToFill = needToFill[1:]
				} else {
					ans[from] = random
				}
			}
			for j := from + 1; j <= to; j++ {
				if len(needToFill) > 0 {
					ans[j] = needToFill[0]
					needToFill = needToFill[1:]
				} else {
					ans[j] = random
				}
			}
			if from > 0 {
				for j := a[from-1] + 1; j < a[from]; j++ {
					if !filled[j] {
						filled[j] = true
						needToFill = append(needToFill, j)
					}
				}
			}
			i = from - 1
		}
		if len(needToFill) > 0 {
			fmt.Fprintf(out, "-1\n")
		} else {
			for i := 0; i < n-1; i++ {
				fmt.Fprintf(out, "%d ", ans[i])
			}
			fmt.Fprintf(out, "%d\n", ans[n-1])
		}
	}
	return
}

func canWin(a []int) bool {
	//fmt.Println(a)
	if len(a) <= 1 {
		return true
	}
	sum := 0
	for i := range a {
		sum += a[i]
	}
	if (sum-2)%2 == 0 {
		return false
	}
	return true
}

func dfs(cur int) {
	cnt++
	checked[cur] = true
	for _, next := range edges[cur] {
		if !checked[next] {
			dfs(next)
		}
	}
}

package main

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

func sch(i int, a []int) bool {
	s := 0
	e := len(a) - 1

	for s <= e {
		m := (s + e) / 2
		if a[m] > i {
			e = m - 1
		} else if a[m] < i {
			s = m + 1
		} else {
			return true
		}
	}

	return false
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

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

	n := in()
	a := make([]int, n)

	for i := range a {
		a[i] = in()
	}

	b := make([]int, n)

	if a[0] > 1 {

	}

	m := 0

	for i := 0; i < n; i++ {
		if a[i] > (i + 1) {
			fmt.Println(-1)
			return
		}

		if i != 0 && a[i] != a[i-1]{
			b[i] = a[i-1]
			if m < b[i] + 1{
				m = b[i] + 1
			}
		} else {
			for sch(m, a) {
				m++
			}

			b[i] = m
			m++
		}
		//fmt.Println(b)
	}

	for i := range b {
		fmt.Print(b[i], " ")
	}

	fmt.Println()
}

/*
URL:
https://codeforces.com/contest/1364/problem/C
*/

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 (
	n int
	A []int

	memo [1000000 + 50]int
)

func main() {
	n = ReadInt()
	A = ReadIntSlice(n)

	for i := 0; i < n; i++ {
		memo[A[i]]++
	}

	tr := NewTreap()

	// ni := -1
	for i := 0; i <= 100000+50; i++ {
		if memo[i] == 0 {
			// ni = i
			// break
			tr.Insert(i)
		}
	}
	B := make([]int, n)
	for i := 0; i < n; i++ {
		// B[i] = ni
		node := tr.FindMinimum()
		B[i] = node.key
		tr.Delete(node.key)

		memo[A[i]]--
		memo[B[i]]++
		if memo[A[i]] == 0 {
			// ni = A[i]
			tr.Insert(A[i])
		} else {
			// for j := 0; j <= 1000000; j++ {
			// 	if memo[j] == 0 {
			// 		ni = j
			// 		break
			// 	}
			// }
		}
	}

	fmt.Println(PrintIntsLine(B...))
}

// Treap usage
// tr := NewTreap()
// tr.Insert(k)
// node := tr.Find(k)
// min := tr.FindMinimum()
// max := tr.FindMaximum()
// tr.Delete(k)
// node := tr.MinGeq(x)
// node := tr.MinGreater(x)
// node := tr.MaxLeq(x)
// node := tr.MaxLess(x)
// fmt.Println(PrintIntsLine(tr.Inorder()...))
// fmt.Println(PrintIntsLine(tr.Preorder()...))
// tr.InsertBySettingPri(k, p)

type Node struct {
	key, priority int
	right, left   *Node
}

type Treap struct {
	root *Node
}

/*************************************/
// Public method
/*************************************/

// NewTreap returns a pointer of a Treap instance.
func NewTreap() *Treap {
	tr := new(Treap)
	tr.root = nil
	return tr
}

// InsertBySettingPri method inserts a new node consisting of new key and priority.
// A duplicate key is ignored and nothing happens.
func (tr *Treap) InsertBySettingPri(key, priority int) {
	tr.root = tr.insert(tr.root, key, priority)
}

// for XorShift
var _gtx, _gty, _gtz, _gtw = 123456789, 362436069, 521288629, 88675123

// Insert method inserts a new node consisting o new key.
// The priority is automatically set by random value.
// A duplicate key is ignored and nothing happens.
func (tr *Treap) Insert(key int) {
	// XorShiftによる乱数生成
	// 下記URLを参考
	// https://qiita.com/tubo28/items/f058582e457f6870a800#lower_bound-upper_bound
	randInt := func() int {
		tt := (_gtx ^ (_gtx << 11))
		_gtx = _gty
		_gty = _gtz
		_gtz = _gtw
		_gtw = (_gtw ^ (_gtw >> 19)) ^ (tt ^ (tt >> 8))
		return _gtw
	}

	tr.root = tr.insert(tr.root, key, randInt())
}

// Find returns a node that has an argument key value.
// Find returns nil when there is no node that has an argument key value.
func (tr *Treap) Find(k int) *Node {
	u := tr.root
	for u != nil && k != u.key {
		if k < u.key {
			u = u.left
		} else {
			u = u.right
		}
	}
	return u
}

// FindMinimum returns a node that has the minimum key in the treap.
// FindMinimum returns nil when there is no nodes.
func (tr *Treap) FindMinimum() *Node {
	u := tr.root
	for u != nil && u.left != nil {
		u = u.left
	}
	return u
}

// FindMaximum returns a node that has the maximum key in the treap.
// FindMaximum returns nil when there is no nodes.
func (tr *Treap) FindMaximum() *Node {
	u := tr.root
	for u != nil && u.right != nil {
		u = u.right
	}
	return u
}

// Delete method deletes a node that has an argument key value.
// A duplicate key is ignored and nothing happens.
func (tr *Treap) Delete(key int) {
	tr.root = tr.delete(tr.root, key)
}

// Inorder returns a slice consisting of treap nodes in order of INORDER.
// The nodes are sorted by key values.
func (tr *Treap) Inorder() []int {
	res := make([]int, 0, 200000+5)
	tr.inorder(tr.root, &res)
	return res
}

// Preorder returns a slice consisting of treap nodes in order of PREORDER.
func (tr *Treap) Preorder() []int {
	res := make([]int, 0, 200000+5)
	tr.preorder(tr.root, &res)
	return res
}

// MinGeq returns a node that has MINIMUM KEY MEETING key >= x.
// https://qiita.com/tubo28/items/f058582e457f6870a800#lower_bound-upper_bound
func (tr *Treap) MinGeq(x int) *Node {
	return tr.biggerLowerBound(tr.root, x)
}

// MinGreater returns a node that has MINIMUM KEY MEETING key > x.
// https://qiita.com/tubo28/items/f058582e457f6870a800#lower_bound-upper_bound
func (tr *Treap) MinGreater(x int) *Node {
	return tr.biggerUpperBound(tr.root, x)
}

// MaxLeq returns a node that has MAXIMUM KEY MEETING key <= x.
// for AGC005-B
func (tr *Treap) MaxLeq(x int) *Node {
	return tr.smallerUpperBound(tr.root, x)
}

// MaxLess returns a node that has MAXIMUM KEY MEETING key < x.
// for AGC005-B
func (tr *Treap) MaxLess(x int) *Node {
	return tr.smallerLowerBound(tr.root, x)
}

/*************************************/
// Private method
/*************************************/

func (tr *Treap) insert(t *Node, key, priority int) *Node {
	// 葉に到達したら新しい節点を生成して返す
	if t == nil {
		node := new(Node)
		node.key, node.priority = key, priority
		return node
	}

	// 重複したkeyは無視
	if key == t.key {
		return t
	}

	if key < t.key {
		// 左の子へ移動
		t.left = tr.insert(t.left, key, priority) // 左の子へのポインタを更新
		// 左の子の方が優先度が高い場合右回転
		if t.priority < t.left.priority {
			t = tr.rightRotate(t)
		}
	} else {
		// 右の子へ移動
		t.right = tr.insert(t.right, key, priority) // 右の子へのポインタを更新
		if t.priority < t.right.priority {
			// 右の子の方が優先度が高い場合左回転
			t = tr.leftRotate(t)
		}
	}

	return t
}

// 削除対象の節点を回転によって葉まで移動させた後に削除する
func (tr *Treap) delete(t *Node, key int) *Node {
	if t == nil {
		return nil
	}

	// 削除対象を検索
	if key < t.key {
		t.left = tr.delete(t.left, key)
	} else if key > t.key {
		t.right = tr.delete(t.right, key)
	} else {
		// 削除対象を発見、葉ノードとなるように回転を繰り返す
		return tr._delete(t, key)
	}

	return t
}

// 削除対象の節点の場合
func (tr *Treap) _delete(t *Node, key int) *Node {
	if t.left == nil && t.right == nil {
		// 葉の場合
		return nil
	} else if t.left == nil {
		// 右の子のみを持つ場合は左回転
		t = tr.leftRotate(t)
	} else if t.right == nil {
		// 左の子のみを持つ場合は右回転
		t = tr.rightRotate(t)
	} else {
		// 優先度が高い方を持ち上げる
		if t.left.priority > t.right.priority {
			t = tr.rightRotate(t)
		} else {
			t = tr.leftRotate(t)
		}
	}

	return tr.delete(t, key)
}

func (tr *Treap) rightRotate(t *Node) *Node {
	s := t.left
	t.left = s.right
	s.right = t
	return s
}

func (tr *Treap) leftRotate(t *Node) *Node {
	s := t.right
	t.right = s.left
	s.left = t
	return s
}

// rootからスタートする
func (tr *Treap) biggerLowerBound(t *Node, x int) *Node {
	if t == nil {
		return nil
	} else if t.key >= x {
		// 探索キーxが現在のノードキー以下の場合、左を探索する
		node := tr.biggerLowerBound(t.left, x)
		if node != nil {
			return node
		} else {
			return t
		}
	} else {
		// 探索キーxが現在のノードキーより大きい場合、右を探索する
		return tr.biggerLowerBound(t.right, x)
	}
}

// rootからスタートする
func (tr *Treap) biggerUpperBound(t *Node, x int) *Node {
	if t == nil {
		return nil
	} else if t.key > x {
		// 探索キーxが現在のノードキーより小さい場合、左を探索する
		node := tr.biggerUpperBound(t.left, x)
		if node != nil {
			return node
		} else {
			return t
		}
	} else {
		// 探索キーxが現在のノードキー以上の場合、右を探索する
		return tr.biggerUpperBound(t.right, x)
	}
}

// rootからスタートする
func (tr *Treap) smallerUpperBound(t *Node, x int) *Node {
	if t == nil {
		return nil
	} else if t.key <= x {
		node := tr.smallerUpperBound(t.right, x)
		if node != nil {
			return node
		} else {
			return t
		}
	} else {
		return tr.smallerUpperBound(t.left, x)
	}
}

// rootからスタートする
func (tr *Treap) smallerLowerBound(t *Node, x int) *Node {
	if t == nil {
		return nil
	} else if t.key < x {
		node := tr.smallerLowerBound(t.right, x)
		if node != nil {
			return node
		} else {
			return t
		}
	} else {
		return tr.smallerLowerBound(t.left, x)
	}
}

func (tr *Treap) inorder(u *Node, res *[]int) {
	if u == nil {
		return
	}
	tr.inorder(u.left, res)
	*res = append(*res, u.key)
	tr.inorder(u.right, res)
}

func (tr *Treap) preorder(u *Node, res *[]int) {
	if u == nil {
		return
	}
	*res = append(*res, u.key)
	tr.preorder(u.left, res)
	tr.preorder(u.right, res)
}

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

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

package main

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

var n int
var a [100000]int
var b [100000]int

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

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

	miss := []int{}
	for i := n - 1; i > 0; i-- {
		if a[i] != a[i-1] {
			b[i] = a[i-1]
			from := a[i-1] + 1
			to := a[i]

			for j := from; j < to && i > 0; j++ {

				if i > 1 && a[i-1] != a[i-2] {
					// fmt.Println(a[i-1], a[i-2])
					// fmt.Println(from, to)
					for k := to - 1; k >= j; k-- {
						// fmt.Println(k)
						miss = append(miss, k)
					}
					break
				}

				b[i-1] = j
				i--
			}
		}
	}

	// for _, x := range miss {
	// 	// fmt.Println(x)
	// }

	j := 0
	for i := 0; i < n && j < len(miss); i++ {
		if b[i] == -1 {
			if i == 0 && a[i] == 1 {
				b[i] = 0
			} else {
				b[i] = miss[len(miss)-1-j]
				j++
			}
		}
	}

	if j != len(miss) {
		fmt.Print(-1)
		return
	}

	val := 0
	for i := 0; i < n; i++ {
		if b[i] == -1 {
			if a[i] == 0 {
				b[i] = 100001
			} else {
				b[i] = val
			}
		} else {
			val = b[i]
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintf(out, "%d ", b[i])
	}
	fmt.Fprintln(out)
	out.Flush()
}

package main

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

var n int
var a [100000]int
var b [100000]int

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

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

	if a[0] == 1 {
		b[0] = 0
	}

	miss := []int{}
	for i := n - 1; i > 0; i-- {
		if a[i] != a[i-1] {
			b[i] = a[i-1]
			for j := a[i] - 1; j > a[i-1]; j-- {
				miss = append(miss, j)
			}
		}
	}

	j := 0
	for i := 0; i < n && j < len(miss); i++ {
		if b[i] == -1 {
			b[i] = miss[len(miss)-1-j]
			j++
		}
	}

	for i := 0; i < n; i++ {
		if b[i] == -1 {
			b[i] = a[n-1] + 1
		}
		fmt.Fprintf(out, "%d ", b[i])
	}
	fmt.Fprintln(out)
	out.Flush()
}

package main

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

var n int
var a [100000]int
var b [100000]int

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

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

	if a[0] == 1 {
		b[0] = 0
	}

	miss := []int{}
	for i := n - 1; i > 0; i-- {
		if a[i] != a[i-1] {
			b[i] = a[i-1]
			for j := a[i] - 1; j > a[i-1]; j-- {
				miss = append(miss, j)
			}
		}
	}

	j := 0
	no := false
	for i := 0; i < n && j < len(miss); i++ {
		if b[i] == -1 {
			b[i] = miss[len(miss)-1-j]

			if i < n-1 && b[i+1] != -1 && b[i]+1 < a[i+1] {
				no = true
			}
			j++
		}
	}

	// Verify answer
	if j != len(miss) || no {
		fmt.Println(-1)
		return
	}

	for i := 0; i < n; i++ {
		if b[i] == -1 {
			fmt.Fprintf(out, "100001 ")
		} else {
			fmt.Fprintf(out, "%d ", b[i])
		}
	}
	fmt.Fprintln(out)
	out.Flush()
}

package main

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

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

	var n, cur int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	b := make([]int, n)
	for i := range b {
		b[i] = -1
	}
	used := make([]bool, n+1)
	for v := 1; ; {
		i := sort.SearchInts(a, v)
		if i == n {
			break
		}
		if i == 0 {
			b[i] = 0
		} else {
			b[i] = a[i-1]
		}
		used[b[i]] = true
		v = a[i] + 1
	}
	used[a[n-1]] = true
	for _, v := range b {
		if v < 0 {
			for ; used[cur]; cur++ {
			}
			v = cur
			cur++
		}
		Fprint(out, v, " ")
	}
}

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

package main

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

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

	var n, cur int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	b := make([]int, n)
	for i := range b {
		b[i] = -1
	}
	used := make([]bool, n+2)
	for v := 1; ; {
		i := sort.SearchInts(a, v)
		if i == n {
			break
		}
		if i == 0 {
			b[i] = 0
		} else {
			b[i] = a[i-1]
		}
		used[b[i]] = true
		v = a[i] + 1
	}
	used[a[n-1]] = true
	for _, v := range b {
		if v < 0 {
			for ; used[cur]; cur++ {
			}
			v = cur
			cur++
		}
		Fprint(out, v, " ")
	}
}

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

package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	n := NextInt()
	a := make([]int, n)
	m := make([]int, n + 10)
	var ret []int
	for i := 0; i < n; i++ {
		a[i] = NextInt()
		m[a[i]] = 1
	}
	d := 0
	for ; m[d] == 1; {
		d++
	}
	m[d] = 1
	ret = append(ret, d)
	for i := 1; i < n; i++ {
		if a[i] != a[i - 1] {
			ret = append(ret, a[i - 1])
			//m[a[i - 1]] = 0
		} else {
			for ; m[d] == 1; {
				d++
			}
			m[d] = 1
			ret = append(ret, d)
		}
	}
	for i := 0; i < len(ret); i++ {
		fmt.Print(ret[i], " ")
	}
	fmt.Println("")

}

package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	n := NextInt()
	a := make([]int, n)
	m := make([]int, n + 10)
	var ret []int
	for i := 0; i < n; i++ {
		a[i] = NextInt()
		m[a[i]] = 1
	}
	d := 0
	for ; m[d] == 1; {
		d++
	}
	m[d] = 1
	ret = append(ret, d)
	for i := 1; i < n; i++ {
		if a[i] != a[i - 1] {
			ret = append(ret, a[i - 1])
			//m[a[i - 1]] = 0
		} else {
			for ; m[d] == 1; {
				d++
			}
			m[d] = 1
			ret = append(ret, d)
		}
	}
	for i := 0; i < len(ret); i++ {
		fmt.Print(ret[i], " ")
	}
	fmt.Println()

}

package main

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

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

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

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

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

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

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

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

	return i
}

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

	n := readNum(reader)
	A := readNNums(reader, n)
	B := solve(n, A)
	if len(B) == 0 {
		fmt.Println(-1)
		return
	}
	var buf bytes.Buffer
	for i := 0; i < n; i++ {
		buf.WriteString(strconv.Itoa(B[i]))
		buf.WriteByte(' ')
	}
	fmt.Println(buf.String())
}

const MAX = 1000000

func solve(n int, A []int) []int {
	if A[0] > 1 {
		return nil
	}

	B := make([]int, n)
	for i := 0; i < n; i++ {
		B[i] = MAX
	}
	var j int
	if A[0] == 1 {
		B[0] = 0
		j++
	}
	for i := 1; i < n; i++ {
		if A[i] == A[i-1] {
			continue
		}
		diff := A[i] - A[i-1] - 1
		dist := i - j
		if dist < diff {
			return nil
		}
		B[i] = A[i-1]
		if diff == 0 {
			continue
		}
		// dist >= diff
		mex := A[i-1] + 1
		for j < i {
			B[j] = mex
			if mex+1 < A[i] {
				mex++
			}
			j++
		}
	}

	return B
}

package main

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

func sch(i int, a []int) int {
	s := 0
	e := len(a) - 1

	for s <= e {
		m := (s + e) / 2
		if a[m] >= i {
			e = m - 1
		} else {
			s = m + 1
		}
	}

	if e != len(a)-1 && a[e+1] == i {
		return e + 1
	}
	return len(a)
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

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

	n := in()
	a := make([]int, n)

	for i := range a {
		a[i] = in()
	}

	b := make([]int, n)

	if a[0] == 0 {
		b[0] = 1
	} else if a[0] == 1 {
		b[0] = 0
	} else {
		fmt.Println(-1)
		return
	}

	m := b[0] + 1

	for i := 1; i < n; i++ {
		if a[i] > (i + 1) {
			fmt.Println(-1)
			return
		}

		j := sch(a[i], b[0:i])
		//fmt.Println(i, j)
		//fmt.Println(b)

		if j != i {
			for j < n {
				if b[j] == a[i] {
					b[j] = m
					m++
				} else {
					break
				}
			}
		}

		//fmt.Println(b)

		if a[i] != a[i-1] {
			b[i] = a[i-1]
			if m < b[i] + 1{
				m = b[i] + 1
			}
		} else {
			b[i] = m
			m++
			if b[i] == a[i] {
				b[i]++
				m++
			}
		}
		//fmt.Println(b)
		//fmt.Println("----------------")
	}

	for i := range b {
		fmt.Print(b[i], " ")
	}

	fmt.Println()
}

package main

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

func sch(i int, a []int) int {
	s := 0
	e := len(a) - 1

	for s <= e {
		m := (s+e)/2
		if a[m] == i {
			return m
		} else if a[m] > i {
			e = m-1
		} else {
			s = m + 1
		}
	}

	return len(a)
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

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

	n := in()
	a := make([]int, n)

	for i := range a {
		a[i] = in()
	}

	b := make([]int, n)

	if a[0] == 0 {
		b[0] = 1
	} else if a[0] == 1 {
		b[0] = 0
	} else {
		fmt.Println(-1)
		return
	}

	for i := 1; i < n; i++ {
		// fmt.Println(b)
		if a[i] > (i+1) {
			fmt.Println(-1)
			return
		}

		j := sch(a[i], b[0:i])

		if j != i {
			if a[i] == 1{
				b[j]++
			} else {
				b[j]--
				if b[j] == a[j] {
					b[j]--
				}
			}
		}

		if a[i] != a[i-1] {
			b[i] = a[i-1]
		} else {
			b[i] = b[i-1]+1
			if b[i] == a[i] {
				b[i]++
			}
		}
	}

	for i := range b {
		fmt.Print(b[i], " ")
	}

	fmt.Println()
}

package main

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

func sch(i int, a []int) int {
	s := 0
	e := len(a) - 1

	for s <= e {
		m := (s + e) / 2
		if a[m] >= i {
			e = m - 1
		} else {
			s = m + 1
		}
	}

	if e != len(a)-1 && a[e+1] == i {
		return e + 1
	}
	return len(a)
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

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

	n := in()
	a := make([]int, n)

	for i := range a {
		a[i] = in()
	}

	b := make([]int, n)

	if a[0] == 0 {
		b[0] = 1
	} else if a[0] == 1 {
		b[0] = 0
	} else {
		fmt.Println(-1)
		return
	}

	m := b[0] + 1

	for i := 1; i < n; i++ {
		if a[i] > (i + 1) {
			fmt.Println(-1)
			return
		}

		j := sch(a[i], b[0:i])
		//fmt.Println(i, j)
		//fmt.Println(b)

		if j != i {
			for j < n {
				if b[j] == a[i] {
					b[j] = m
					m++
				} else {
					break
				}
			}
		}

		//fmt.Println(b)

		if a[i] != a[i-1] {
			b[i] = a[i-1]
		} else {
			b[i] = m
			m++
			if b[i] == a[i] {
				b[i]++
				m++
			}
		}
		//fmt.Println(b)
		//fmt.Println("----------------")
	}

	for i := range b {
		fmt.Print(b[i], " ")
	}

	fmt.Println()
}

package main

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

func sch(i int, a []int) bool {
	s := 0
	e := len(a) - 1

	for s <= e {
		m := (s + e) / 2
		if a[m] > i {
			e = m - 1
		} else if a[m] < i {
			s = m + 1
		} else {
			return true
		}
	}

	return false
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

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

	n := in()
	a := make([]int, n)

	for i := range a {
		a[i] = in()
	}

	b := make([]int, n)

	if a[0] == 0 {
		b[0] = 1
	} else if a[0] == 1 {
		b[0] = 0
	} else {
		fmt.Println(-1)
		return
	}

	m := b[0] + 1

	for i := 1; i < n; i++ {
		if a[i] > (i + 1) {
			fmt.Println(-1)
			return
		}

		if a[i] != a[i-1] {
			b[i] = a[i-1]
			if m < b[i] + 1{
				m = b[i] + 1
			}
		} else {
			for sch(m, a) {
				m++
			}

			b[i] = m
			m++
		}
		//fmt.Println(b)
	}

	for i := range b {
		fmt.Print(b[i], " ")
	}

	fmt.Println()
}

package main

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

var n int
var a [100000]int
var b [100000]int

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

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

	miss := []int{}
	for i := n - 1; i > 0; i-- {
		if a[i] != a[i-1] {
			b[i] = a[i-1]
			from := a[i-1] + 1
			to := a[i]

			for j := from; j < to && i > 0; j++ {
				if i > 1 && a[i-1] != a[i-2] {
					for k := j; k < to; k++ {
						miss = append(miss, k)
					}
					break
				}

				b[i-1] = j
				i--
			}
		}
	}

	for i, m := range miss {
		if a[i] != 0 {
			fmt.Fprint(out, -1)
			out.Flush()
			return
		}

		b[i] = m
	}

	val := 0
	for i := 0; i < n; i++ {
		if b[i] == -1 {
			if a[i] == 0 {
				b[i] = 100001
			} else {
				b[i] = val
			}
		} else {
			val = b[i]
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintf(out, "%d ", b[i])
	}
	fmt.Fprintln(out)
	out.Flush()
}

package main

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

var n int
var a [100000]int
var b [100000]int

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

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

	miss := []int{}
	for i := n - 1; i > 0; i-- {
		if a[i] != a[i-1] {
			b[i] = a[i-1]
			from := a[i-1] + 1
			to := a[i]

			for j := from; j < to && i > 0; j++ {

				if i > 1 && a[i-1] != a[i-2] {
					// fmt.Println(a[i-1], a[i-2])
					// fmt.Println(from, to)
					for k := to - 1; k >= j; k-- {
						// fmt.Println(k)
						miss = append(miss, k)
					}
					break
				}

				b[i-1] = j
				i--
			}
		}
	}

	// for _, x := range miss {
	// 	// fmt.Println(x)
	// }

	j := 0
	for i := 0; i < n && j < len(miss); i++ {
		if b[i] == -1 {
			b[i] = miss[j]
			j++
		}
	}

	if j != len(miss) {
		fmt.Print(-1)
		return
	}

	val := 0
	for i := 0; i < n; i++ {
		if b[i] == -1 {
			if a[i] == 0 {
				b[i] = 100001
			} else {
				b[i] = val
			}
		} else {
			val = b[i]
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintf(out, "%d ", b[i])
	}
	fmt.Fprintln(out)
	out.Flush()
}

package main

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

var n int
var a [100000]int
var b [100000]int

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

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

	yes := true
	for i := n - 1; i > 0; i-- {
		if a[i] != a[i-1] {
			b[i] = a[i-1]
			from := a[i-1] + 1
			to := a[i]

			for j := from; j < to && i > 0; j++ {
				if i > 1 && a[i-1] != a[i-2] {
					yes = false
					break
				}

				b[i-1] = j
				i--
			}

			if !yes {
				break
			}
		}
	}

	if !yes {
		fmt.Fprint(out, -1)
		out.Flush()
		return
	}

	val := 0
	for i := 0; i < n; i++ {

		if b[i] == -1 {
			if a[i] == 0 {
				b[i] = 100001
			} else {
				b[i] = val
			}
		} else {
			val = b[i]
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintf(out, "%d ", b[i])
	}
	fmt.Fprintln(out)
	out.Flush()
}

package main

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

var n int
var a [100000]int
var b [100000]int

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

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

	miss := []int{}
	for i := n - 1; i > 0; i-- {
		if a[i] != a[i-1] {
			b[i] = a[i-1]
			from := a[i-1] + 1
			to := a[i]

			for j := from; j < to && i > 0; j++ {

				if i > 1 && a[i-1] != a[i-2] {
					// fmt.Println(a[i-1], a[i-2])
					// fmt.Println(from, to)
					for k := to - 1; k >= j; k-- {
						// fmt.Println(k)
						miss = append(miss, k)
					}
					break
				}

				b[i-1] = j
				i--
			}
		}
	}

	// for _, x := range miss {
	// 	// fmt.Println(x)
	// }

	j := 0
	for i := 0; i < n && j < len(miss); i++ {
		if b[i] == -1 {
			if i == 0 && a[i] == 1 {
				b[i] = 0
			} else {
				b[i] = miss[j]
				j++
			}
		}
	}

	if j != len(miss) {
		fmt.Print(-1)
		return
	}

	val := 0
	for i := 0; i < n; i++ {
		if b[i] == -1 {
			if a[i] == 0 {
				b[i] = 100001
			} else {
				b[i] = val
			}
		} else {
			val = b[i]
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintf(out, "%d ", b[i])
	}
	fmt.Fprintln(out)
	out.Flush()
}

package main

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

var n int
var a [100000]int
var b [100000]int

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

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

	if a[0] == 1 {
		b[0] = 0
	}

	miss := []int{}
	for i := n - 1; i > 0; i-- {
		if a[i] != a[i-1] {
			b[i] = a[i-1]
			for j := a[i] - 1; j > a[i-1]; j-- {
				miss = append(miss, j)
			}
		}
	}

	j := 0
	no := false
	for i := 0; i < n && j < len(miss); i++ {
		if b[i] == -1 {
			b[i] = miss[len(miss)-1-j]

			if i < n-1 && b[i+1] != -1 && b[i] >= b[i+1] {
				no = true
			}
			j++
		}
	}

	// Verify answer
	if j != len(miss) || no {
		fmt.Println(-1)
		return
	}

	for i := 0; i < n; i++ {
		if b[i] == -1 {
			fmt.Fprintf(out, "100001 ")
		} else {
			fmt.Fprintf(out, "%d ", b[i])
		}
	}
	fmt.Fprintln(out)
	out.Flush()
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	n := NextInt()
	a := make([]int, n)
	m := make([]int, n + 10)
	var ret []int
	for i := 0; i < n; i++ {
		a[i] = NextInt()
		m[a[i]] = 1
	}
	d := 0
	for ; m[d] == 1; {
		d++
	}
	m[d] = 1
	ret = append(ret, d)
	for i := 1; i < n; i++ {
		if a[i] != a[i - 1] {
			ret = append(ret, a[i - 1])
			m[a[i - 1]] = 0
		} else {
			for ; m[d] == 1; {
				d++
			}
			m[d] = 1
			ret = append(ret, d)
		}
	}
	for i := 0; i < len(ret); i++ {
		fmt.Print(ret[i], " ")
	}
	fmt.Println("")

}


Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).

First line of input contains an integer n (1 ≤ n ≤ 100) — the number of names in the list. Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.

NoteIn test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".

package main

import "fmt"

func main() {
	s := make(map[string]bool)
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var name string
		fmt.Scan(&name)
		if s[name] {
			fmt.Println("YES")
		} else {
			s[name] = true
			fmt.Println("NO")
		}
	}
}

// A. Tom Riddle's Diary
/*
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.

He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.

Formally, for a name s i in the i-th line, output "YES" (without quotes) if there exists an index j such that s i = s j and j < i, otherwise, output "NO" (without quotes).

Input
First line of input contains an integer n (1 ≤ n ≤ 100) — the number of names in the list.

Next n lines each contain a string s i, consisting of lowercase English letters. The length of each string is between 1 and 100.

Output
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.

You can print each letter in any case (upper or lower).

Examples
Input
6
tom
lucius
ginny
harry
ginny
harry

Output
NO
NO
NO
NO
YES
YES

Input
3
a
a
a

Output
NO
YES
YES

Note
In test case 1, for i = 5 there exists j = 3 such that s i = s j and j < i, which means that answer for i = 5 is "YES".
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _ := reader.ReadString('\n')
	n, _ := strconv.Atoi(strings.TrimSpace(input))

	sMap := map[string]int{}
	for ; n > 0; n-- {
		s, _ := reader.ReadString('\n')
		s = strings.TrimSpace(s)

		if _, ok := sMap[s]; ok {
			fmt.Println("YES")
		} else {
			sMap[s] = 1
			fmt.Println("NO")
		}
	}
}

package main

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

func solve() {
	n := readInt()
	v := map[string]bool{}
	for i := 0; i < n; i++ {
		name := readString()
		if _, ok := v[name]; ok {
			fmt.Println("YES")
		} else {
			v[name] = true
			fmt.Println("NO")
		}
	}
}

var scanner *bufio.Scanner

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

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

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

// IO

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

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

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

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

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

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanln(&n)
	var seen map[string]bool = make(map[string]bool)
	for i := 0; i < n; i++ {
		var name string
		fmt.Scanln(&name)
		if seen[name] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
		seen[name] = true
	}
}

package main

import "fmt"

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

	readDiary := make(map[string]int)

	for i := 0; i < persons; i++ {
	 	var person string
	 	fmt.Scan(&person)

	 	if readDiary[person] == 0 {
	 		fmt.Println("NO")
	 	} else {
	 		fmt.Println("YES")
	 	}

	 	readDiary[person] ++
	 }
}

package main

import "fmt"

func main() {
	var persons int
	var person string

	fmt.Scanf("%d ",&persons)

	readDiary := make(map[string]bool)

	for i := 0; i < persons; i++ {
	 	fmt.Scanf("%s\n", &person)

	 	if readDiary[person] {
	 		fmt.Println("YES")
	 	} else {
	 		fmt.Println("NO")
	 	}

	 	readDiary[person] = true
	 }
}

package main

import "fmt"

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

	readDiary := make(map[string]int)
	var responses []string

	for i := 0; i < persons; i++ {
	 	var person string
	 	fmt.Scan(&person)

	 	if readDiary[person] == 0 {
	 		responses = append(responses, "NO")
	 	} else {
	 		responses = append(responses, "YES")
	 	}

	 	readDiary[person] ++
	 }

	for _, response := range responses {
		fmt.Println(response)
	}
}


Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that its sides are parallel to the office walls. Bob doesn't want to change or rearrange anything, that's why all the squares that will be occupied by the table should be initially free. Bob wants the new table to sit as many people as possible, thus its perimeter should be maximal. Help Bob find out the maximum possible perimeter of a bargaining table for his office.

The first line contains 2 space-separated numbers n and m (1 ≤ n, m ≤ 25) — the office room dimensions. Then there follow n lines with m characters 0 or 1 each. 0 stands for a free square meter of the office room. 1 stands for an occupied square meter. It's guaranteed that at least one square meter in the room is free.

Output one number — the maximum possible perimeter of a bargaining table for Bob's office room.

package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"bytes"
)
var dp [25][25][25][25] bool

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	max := 0
	for i := 0;i < n;i ++ {
		for j := 0;j < m;j ++ {
			var c byte
			fmt.Fscanf(reader, "%c", &c)
			if c == '1' {
				continue
			}
			for k := 0;k <= i;k ++ {
				for l := 0;l <= j;l ++ {
					if k == 0 && l == 0 {
						dp[i][j][k][l] = true
					} else if k == 0 {
						dp[i][j][k][l] = dp[i][j - 1][k][l - 1]
					} else if l == 0 {
						dp[i][j][k][l] = dp[i - 1][j][k - 1][l]
					} else {
						dp[i][j][k][l] = dp[i][j - 1][k][l - 1] && dp[i - 1][j][k - 1][l]
					}
					if dp[i][j][k][l] && max < 2 * (k + l + 2) {
						max = 2 * (k + l + 2)
					}
				}
			}
		}
		fmt.Fscanf(reader, "\n")
	}
	fmt.Printf("%d", max)
}


Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In this table, Vanya chose n rectangles with sides that go along borders of squares (some rectangles probably occur multiple times). After that for each cell of the table he counted the number of rectangles it belongs to and wrote this number into it. Now he wants to find the sum of values in all cells of the table and as the table is too large, he asks you to help him find the result.

The first line contains integer n (1 ≤ n ≤ 100) — the number of rectangles. Each of the following n lines contains four integers x1, y1, x2, y2 (1 ≤ x1 ≤ x2 ≤ 100, 1 ≤ y1 ≤ y2 ≤ 100), where x1 and y1 are the number of the column and row of the lower left cell and x2 and y2 are the number of the column and row of the upper right cell of a rectangle.

In a single line print the sum of all values in the cells of the table.

NoteNote to the first sample test:Values of the table in the first three rows and columns will be as follows:121121110So, the sum of values will be equal to 10.Note to the second sample test:Values of the table in the first three rows and columns will be as follows:222222222So, the sum of values will be equal to 18.

package main

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

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

const MAX = 101

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

	var x1, y1, x2, y2 int
	n := nextInt()
	var table [MAX][MAX]int

	for i := 0; i < n; i++ {
		x1, y1, x2, y2 = nextInt(), nextInt(), nextInt(), nextInt()

		for ; x1 <= x2; x1++ {
			for j := y1; j <= y2; j++ {
				table[x1][j]++
			}
		}
	}

	// println(table[:4])

	sum := 0

	for i := range table {
		for j := range table[i] {
			sum += table[i][j]
		}
	}

	println(sum)
}

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

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

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

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

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

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

package main

import "fmt"

func main() {
    var n, x1, y1, x2, y2 int
    fmt.Scanf("%d\n", &n)

    r := 0
    for i := 0; i < n; i++ {
        fmt.Scanf("%d %d %d %d\n", &x1, &y1, &x2, &y2)
        r += (x2-x1+1)*(y2-y1+1)
    }

    fmt.Println(r)
}

package main

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

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

func main() {

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

	var n, ret int = NextInt(), 0
	for i := 0; i < n; i++ {
		var x1, y1, x2, y2 int = NextInt(), NextInt(), NextInt(), NextInt()
		ret += (x2 - x1 + 1) * (y2 - y1 + 1)
	}

	fmt.Fprintln(out, ret)
}

func Next() string{
	if !in.Scan() {
		panic("Scan error")
	}
	return in.Text()
}

func NextInt() int{
	ret, _ := strconv.Atoi(Next())
	return ret
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%v\n", &n)

	var arr [100][100]int

	for q := 0; q < n; q++ {
		var a, b, c, d int
		fmt.Scanf("%v %v %v %v\n", &a, &b, &c, &d)
		a, b, c, d = a-1, b-1, c-1, d-1

		for i := a; i <= c; i++ {
			for j := b; j <= d; j++ {
				arr[i][j]++
			}
		}
	}

	var sum int
	for _, i := range arr {
		for _, v := range i {
			sum += v
		}
	}

	fmt.Println(sum)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%v\n", &n)

	arr := make([][]int, 100)
	for i, _ := range arr {
		arr[i] = make([]int, 100)
	}

	for q := 0; q < n; q++ {
		var a, b, c, d int
		fmt.Scanf("%v %v %v %v\n", &a, &b, &c, &d)
		a, b, c, d = a-1, b-1, c-1, d-1

		for i := a; i <= c; i++ {
			for j := b; j <= d; j++ {
				arr[i][j]++
			}
		}
	}

	var sum int
	for _, i := range arr {
		for _, v := range i {
			sum += v
		}
	}

	fmt.Println(sum)
}

package main

import (
	"fmt"
)

func main() {
	var n, ans int
	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		var x1, y1, x2, y2 int
		fmt.Scan(&x1, &y1, &x2, &y2)
		ans += (x2 - x1 + 1) * (y2 - y1 + 1)
	}

	fmt.Println(ans)
}

package main

import "fmt"

func main() {

    var n int
    fmt.Scanf("%v\n", &n)

    sum := 0
    for i := 0; i < n; i++ {
        var x1,y1,x2,y2 int
        fmt.Scanf("%v%v%v%v\n",&x1,&y1,&x2,&y2)
        sum += (x2-x1+1)*(y2-y1+1)
    }
    fmt.Printf("%v\n", sum)
}


Define the score of some binary string $$$T$$$ as the absolute difference between the number of zeroes and ones in it. (for example, $$$T=$$$ 010001 contains $$$4$$$ zeroes and $$$2$$$ ones, so the score of $$$T$$$ is $$$|4-2| = 2$$$).Define the creepiness of some binary string $$$S$$$ as the maximum score among all of its prefixes (for example, the creepiness of $$$S=$$$ 01001 is equal to $$$2$$$ because the score of the prefix $$$S[1 \ldots 4]$$$ is $$$2$$$ and the rest of the prefixes have a score of $$$2$$$ or less).Given two integers $$$a$$$ and $$$b$$$, construct a binary string consisting of $$$a$$$ zeroes and $$$b$$$ ones with the minimum possible creepiness.

The first line contains a single integer $$$t$$$ $$$(1\le t\le 1000)$$$  — the number of test cases. The description of the test cases follows. The only line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$ 1 \le a, b \le 100$$$)  — the numbers of zeroes and ones correspondingly.

For each test case, print a binary string consisting of $$$a$$$ zeroes and $$$b$$$ ones with the minimum possible creepiness. If there are multiple answers, print any of them.

NoteIn the first test case, the score of $$$S[1 \ldots 1]$$$ is $$$1$$$, and the score of $$$S[1 \ldots 2]$$$ is $$$0$$$.In the second test case, the minimum possible creepiness is $$$1$$$ and one of the other answers is 101.In the third test case, the minimum possible creepiness is $$$3$$$ and one of the other answers is 0001100.

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x,y int
		fmt.Fscan(in,&x,&y)
		if x >= y {
			for j:=0;j<y+x;j++{
				if y > 0 {
					fmt.Fprintf(out,"%v",1)
					y--
				}
				fmt.Fprintf(out,"%v",0)
			}
		} else {
			for j:=0;j<x+y;j++{
				if x > 0 {
					fmt.Fprintf(out,"%v",0)
					x--
				}
				fmt.Fprintf(out,"%v",1)
			}
		}

		fmt.Fprintln(out,)
	}
}

package main

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var ntests int
	fmt.Fscan(scanner, &ntests)
	for iter := 0; iter < ntests; iter++ {
		var a, b int
		fmt.Fscan(scanner, &a, &b)
		if a <= b {
			for i := 0; i < a; i++ {
				fmt.Fprint(writer, "01")
			}
			for i := 0; i < b-a; i++ {
				fmt.Fprint(writer, "1")
			}
		} else {
			for i := 0; i < b; i++ {
				fmt.Fprint(writer, "10")
			}
			for i := 0; i < a-b; i++ {
				fmt.Fprint(writer, "0")
			}
		}
		fmt.Fprintln(writer)
	}
}

package main

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

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

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

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

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

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

/**
gopherbots limit time
Run solve the problem CF1694A
Date: 20/06/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1694/A
Problem: CF1694A
**/
func (in *CF1694A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		a, b := in.NextInt(), in.NextInt()
		var str strings.Builder
		for a+b > 0 {
			if a > 0 {
				str.WriteString("0")
				a--
			}
			if b > 0 {
				str.WriteString("1")
				b--
			}
		}
		fmt.Println(str.String())
	}

}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1694A
Date: 20/06/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1694/A
Problem: CF1694A
**/
func (in *CF1694A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		a, b :=in.NextInt(), in.NextInt()

		for a+b > 0 {
			if a > 0 {
				fmt.Print(0)
				a--
			}
			if b > 0 {
				fmt.Print(1)
				b--
			}
		}

		fmt.Println()
	}

}

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

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

package main

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

var r =  bufio.NewReader(os.Stdin)
var w =bufio.NewWriter(os.Stdout)

func solve() {
	var a,b int
	var an string
	fmt.Fscan(r, &a, &b)
	for  {
		if a == 0 && b == 0 {
			break
		}
		if a > 0 {
			an += "0"
			a--
		}
		if b > 0 {
			an += "1"
			b--
		}
	}
	fmt.Fprintln(w, an)
}
func main() {
	defer w.Flush()
	var T int
	fmt.Fscan(r,&T)
	for i := 0; i < T; i++ {
		solve()
	}

}

package main

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

var (
	reader  = bufio.NewReader(os.Stdin)
	t, a, b int
)

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func solve(a, b int) string {
	var ans = strings.Repeat("01", min(a, b))
	if a > b {
		ans += strings.Repeat("0", a-b)
	} else {
		ans += strings.Repeat("1", b-a)
	}
	return ans
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &a, &b)
		fmt.Println(solve(a, b))
	}
}

package main

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

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

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

	var T int
	var x int
	var y int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &x)
		Fscan(in, &y)

		ans := []byte{}
		for x > 0 && y > 0 {
			ans = append(ans, '0')
			ans = append(ans, '1')
			x--
			y--
		}
		for x > 0 {
			ans = append(ans, '0')
			x--
		}
		for y > 0 {
			ans = append(ans, '1')
			y--
		}

		Fprintln(out, string(ans))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		A,B := gi(),gi()
		ansarr := []byte{}
		for i:=1;i<=100;i++ {
			if A > 0 { ansarr = append(ansarr,'0'); A-- }
			if B > 0 { ansarr = append(ansarr,'1'); B-- }
		}
		ans := string(ansarr); fmt.Fprintln(wrtr,ans)
	}
}

package main

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

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

func printf(f string, a ...interface{}) { _, _ = fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { _, _ = fmt.Fscanf(reader, f, a...) }
func debugf(f string, a ...interface{}) { _, _ = fmt.Fprintf(debugwr, f, a...) }

func main() {
	defer writer.Flush()
	var n, a, b int
	scanf("%d\n", &n)
	for test := 0; test < n; test++ {
		scanf("%d %d\n", &a, &b)
		total := a + b
		// printf("dbg: %d %d\n", a, b)
		sb := &strings.Builder{}
		for i := 0; i < total; i++ {
			if a > 0 {
				sb.WriteRune('0')
				a--
			}
			if b > 0 {
				sb.WriteRune('1')
				b--
			}
		}
		printf("%s\n", sb.String())
	}
}

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

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

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	for k := 0; k < n; k++ {
		var a, b int
		fmt.Scan(&a)
		fmt.Scan(&b)

		if a >= b {
			fmt.Print("\n")
			for i := 0; i < b; i++ {
				fmt.Print("10")
			}
			for i := 0; i < a-b; i++ {
				fmt.Print("0")
			}
		} else {
			fmt.Print("\n")
			for i := 0; i < a; i++ {
				fmt.Print("01")
			}
			for i := 0; i < b-a; i++ {
				fmt.Print("1")
			}
		}
	}
}

package main

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

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

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

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

func do(a, b int) string {
	n := a
	c := "1"
	d := b - a
	if a > b {
		n = b
		c = "0"
		d = -d
	}
	s := strings.Repeat("01", n)
	if d < 0 {
		d = -d
	}
	s += strings.Repeat(c, d)
	return s
}

package main

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

/*
2
5 4
6 2
---
010101010
00001100

*/

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

	s := make([]rune, 0)

	maxC := max(1, abs(a-b))

	use0 := false
	if a > b {
		use0 = true
	}

	for a > 0 || b > 0 {
		if use0 {
			for i := 0; i < maxC && a > 0; i++ {
				s = append(s, '0')
				a--
			}
		} else {
			for i := 0; i < maxC && b > 0; i++ {
				s = append(s, '1')
				b--
			}
		}

		use0 = !use0
	}

	fmt.Fprintln(writer, string(s))
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

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

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

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

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

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

func abs(n int) int {
	if n < 0 {
		return n * -1
	}
	return n
}

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

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

		d := abs(a - b)
		var c int
		var buf bytes.Buffer
		for a > 0 || b > 0 {
			if a >= b {
				if c*-1 < d {
					buf.WriteByte('0')
					a--
					c--
				} else {
					buf.WriteByte('1')
					b--
					c++
				}
			} else {
				if c < d {
					buf.WriteByte('1')
					b--
					c++
				} else {
					buf.WriteByte('0')
					a--
					c--
				}
			}
		}
		fmt.Fprintln(out, buf.String())
	}
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func solve() {
	var a, b int
	fmt.Fscan(r, &a, &b)
	ans := ""
	for ; a > 0; a-- {
		ans += "0"
		if b > 0 {
			ans += "1"
			b--
		}
	}
	if b > 0 {
		ans += strings.Repeat("1", b)
	}
	fmt.Fprintln(w, ans)

}
func main() {
	defer w.Flush()
	var t int
	fmt.Fscan(r, &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x,y int
		fmt.Fscan(in,&x,&y)
		if x >= y {
			for j:=0;j<x-1;j++{
				fmt.Fprintf(out,"%v",0)
			}
			for j:=0;j<y;j++{
				fmt.Fprintf(out,"%v",1)
			}
			fmt.Fprintf(out,"%v",0)
		} else {
			for j:=0;j<y-1;j++{
				fmt.Fprintf(out,"%v",1)
			}
			for j:=0;j<x;j++{
				fmt.Fprintf(out,"%v",0)
			}
			fmt.Fprintf(out,"%v",1)
		}
		fmt.Fprintln(out,)
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x,y int
		fmt.Fscan(in,&x,&y)
		if x >= y {
			for j:=0;j<x;j++{
				fmt.Fprintf(out,"%v",0)
			}
			for j:=0;j<y;j++{
				fmt.Fprintf(out,"%v",1)
			}
		} else {
			for j:=0;j<y;j++{
				fmt.Fprintf(out,"%v",1)
			}
			for j:=0;j<x;j++{
				fmt.Fprintf(out,"%v",0)
			}
		}
		fmt.Fprintln(out,)
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x,y int
		fmt.Fscan(in,&x,&y)
		if x >= y {
			for j:=0;j<y;j++{
				fmt.Fprintf(out,"%v",1)
			}
			for j:=0;j<x;j++{
				fmt.Fprintf(out,"%v",0)
			}
		} else {
			for j:=0;j<x;j++{
				fmt.Fprintf(out,"%v",0)
			}
			for j:=0;j<y;j++{
				fmt.Fprintf(out,"%v",1)
			}
		}
		fmt.Fprintln(out,)
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x,y int
		fmt.Fscan(in,&x,&y)
		for j:=0;j<min(x,y);j++{
			fmt.Fprintf(out,"%v",0)
		}
		for j:=0;j<max(x,y);j++{
			fmt.Fprintf(out,"%v",1)
		}
		fmt.Fprintln(out,)
	}
}

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

package main

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var ntests int
	fmt.Fscan(scanner, &ntests)
	for iter := 0; iter < ntests; iter++ {
		var a, b int
		fmt.Fscan(scanner, &a, &b)
		if a <= b {
			for i := 0; i < a; i++ {
				fmt.Fprint(writer, "01")
			}
			for i := 0; i < b-a+1; i++ {
				fmt.Fprint(writer, "1")
			}
		} else {
			for i := 0; i < b; i++ {
				fmt.Fprint(writer, "10")
			}
			for i := 0; i < a-b+1; i++ {
				fmt.Fprint(writer, "0")
			}
		}
		fmt.Fprintln(writer)
	}
}

package main

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var ntests int
	fmt.Fscan(scanner, &ntests)
	for iter := 0; iter < ntests; iter++ {
		var a, b int
		fmt.Fscan(scanner, &a, &b)
		if a <= b {
			for i := 0; i < a; i++ {
				fmt.Fprint(writer, "0")
			}
			for i := 0; i < b; i++ {
				fmt.Fprint(writer, "1")
			}
		} else {
			for i := 0; i < b; i++ {
				fmt.Fprint(writer, "1")
			}
			for i := 0; i < a; i++ {
				fmt.Fprint(writer, "0")
			}
		}
		fmt.Fprintln(writer)
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1694A
Date: 20/06/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1694/A
Problem: CF1694A
**/
func (in *CF1694A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		a, b :=in.NextInt(), in.NextInt()
		if a > b {
			for i := 0; i< a+b;i++{
				if i %2 == 0 {
					fmt.Print(0)
				}else {
					fmt.Print(1)
				}
			}
		}else {
			for i := 0; i< a+b;i++{
				if i %2 == 0 {
					fmt.Print(1)
				}else {
					fmt.Print(0)
				}
			}
		}

		fmt.Println()
	}

}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1694A
Date: 20/06/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1694/A
Problem: CF1694A
**/
func (in *CF1694A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		a, b :=in.NextInt(), in.NextInt()
		for i:=0;i<a;i++{
			fmt.Print(0)
		}
		for i:=0;i<b;i++{
			fmt.Print(1)
		}
		fmt.Println()
	}

}

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

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

package main

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

var r =  bufio.NewReader(os.Stdin)
var w =bufio.NewWriter(os.Stdout)

func solve() {
	var a,b int
	fmt.Fscan(r, &a, &b)
	for  {
		if a == 0 && b == 0 {
			break
		}
		if a > 0 {
			fmt.Fprint(w,"0")
			a--
		}
		if b > 0 {
			fmt.Fprint(w,"1")
			b--
		}
	}
}
func main() {
	defer w.Flush()
	var T int
	fmt.Fscan(r,&T)
	for i := 0; i < T; i++ {
		solve()
	}

}


Mainak has an array $$$a_1, a_2, \ldots, a_n$$$ of $$$n$$$ positive integers. He will do the following operation to this array exactly once:  Pick a subsegment of this array and cyclically rotate it by any amount.  Formally, he can do the following exactly once:  Pick two integers $$$l$$$ and $$$r$$$, such that $$$1 \le l \le r \le n$$$, and any positive integer $$$k$$$.  Repeat this $$$k$$$ times: set $$$a_l=a_{l+1}, a_{l+1}=a_{l+2}, \ldots, a_{r-1}=a_r, a_r=a_l$$$ (all changes happen at the same time). Mainak wants to maximize the value of $$$(a_n - a_1)$$$ after exactly one such operation. Determine the maximum value of $$$(a_n - a_1)$$$ that he can obtain.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 50$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2000$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 999$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$.

For each test case, output a single integer — the maximum value of $$$(a_n - a_1)$$$ that Mainak can obtain by doing the operation exactly once.

Note In the first test case, we can rotate the subarray from index $$$3$$$ to index $$$6$$$ by an amount of $$$2$$$ (i.e. choose $$$l = 3$$$, $$$r = 6$$$ and $$$k = 2$$$) to get the optimal array: $$$$$$[1, 3, \underline{9, 11, 5, 7}] \longrightarrow [1, 3, \underline{5, 7, 9, 11}]$$$$$$ So the answer is $$$a_n - a_1 = 11 - 1 = 10$$$. In the second testcase, it is optimal to rotate the subarray starting and ending at index $$$1$$$ and rotating it by an amount of $$$2$$$. In the fourth testcase, it is optimal to rotate the subarray starting from index $$$1$$$ to index $$$4$$$ and rotating it by an amount of $$$3$$$. So the answer is $$$8 - 1 = 7$$$.

package main

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

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

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

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

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

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

/**
Run solve the problem CF1726A
Date: 9/6/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1726/A
Problem: CF1726A
**/
func (in *CF1726A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		min, max := 9999, 0
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			val := in.NextInt()
			arr[i] = val
			if val < min {
				min = val
			}
			if val > max {
				max = val
			}
		}

		ok := false
		for i := 0; i < n; i++ {
			if arr[i] == max && arr[(i+1)%n] == min {
				ok = true
				break
			}
		}

		if arr[0] == min || arr[n-1] == max || ok {
			fmt.Println(max - min)
		} else {
			ans := -999999
			for i, j := 0, n-1; i < n; i++ {
				val := arr[j] - arr[i]
				if val > ans {
					ans = val
				}
				j = (j + 1) % n
			}
			fmt.Println(Max(max-arr[0], Max(arr[n-1]-min, ans)))
		}

	}
}

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

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

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	t := readInt(in)
	b := strings.Builder{}
	for i := 0; i < t; i++ {
		b.WriteString(solve(in) + "\n")
	}
	fmt.Println(b.String())
}

func solve(in *bufio.Reader) string {
	n := readInt(in)
	arr := readArrInt(in)

	var ans1, ans2, ans3 int

	for i := 0; i < n; i++ {
		ans1 = max(ans1, arr[(n - 1 + i) % n] - arr[i])
		ans2 = max(ans2, arr[i] - arr[0])
		ans3 = max(ans3, arr[n - 1] - arr[i])
	}

	res := max(ans1, ans2)
	res = max(ans3, res)
	return strconv.Itoa(res)
}

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

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

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

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

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

package main
import "fmt"
func main() {
    var q int
    fmt.Scan(&q)
    for i := 0; i<q; i++{
        var n int
        fmt.Scan(&n)
        a:= make([]int,n)
        for j:=0; j<n; j++{
            fmt.Scan(&a[j])
        }
        if n==1{
            fmt.Println(0)
            continue
        }else if n==2{
            if a[1] >= a[0]{
                fmt.Println(a[1]-a[0])
            }else{
                fmt.Println(a[0]-a[1])
            }

            continue
        }

        var left int = -1000
        var right int = -1000
        var near int = -1000
        var center int = -1000

        for j:=1;j<n;j++{
            if a[j]-a[0] > left{
                left = a[j] - a[0]
            }
            if a[n-1] - a[j-1] > right{
                right = a[n-1] - a[j-1]
            }
            if a[j-1] - a[j] > near{
                near = a[j-1] - a[j]
            }
            if a[j] - a[(j+n-1)%n] > center{
                // fmt.Println((j+n-1)%n)
                center =  a[j] - a[(j+n-1)%n]
            }
        }
        if left >= right && left>=near{
            fmt.Println(left)
        }else if right>=left && right>=near{
            fmt.Println(right)
        }else{
            fmt.Println(near)
        }

    }

}

package main

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

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

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

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

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

		var tot int
		for i := 1; i < n; i++ {
			tot = max(tot, aa[i]-aa[0])
		}
		for i := 0; i < n-1; i++ {
			tot = max(tot, aa[n-1]-aa[i])
		}
		for i := 0; i < n-1; i++ {
			tot = max(tot, aa[i]-aa[i+1])
		}
		fmt.Fprintln(out, tot)
	}
}

package main

import (
	"fmt"
)

const N = 2e3
const inf = 1e9

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

func max_element(a [N]int, n int) int {
	var o int = -inf
	for i := 0; i < n; i++ {
		o = max(a[i], o)
	}
	return o
}

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

func min_element(a [N]int, n int) int {
	var o int = inf
	for i := 0; i < n; i++ {
		o = min(a[i], o)
	}
	return o
}

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		t--
		var n int
		fmt.Scan(&n)
		var a [N]int
		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
		}
		if n == 1 {
			fmt.Println(0)
			continue
		}
		o := 0
		for i := 0; i < n-1; i++ {
			o = max(a[i]-a[i+1], o)
		}
		o = max(a[n-1]-a[0], o)
		o = max(o, max_element(a, n)-a[0])
		o = max(o, a[n-1]-min_element(a, n))
		fmt.Println(o)
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1726A
Date: 9/6/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1726/A
Problem: CF1726A
**/
func (in *CF1726A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		min, max := 9999, 0
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			val := in.NextInt()
			arr[i] = val
			if val < min {
				min = val
			}
			if val > max {
				max = val
			}
		}

		ok := false
		for i := 0; i < n; i++ {
			if arr[i] == max && arr[(i+1)%n] == min {
				ok = true
				break
			}
		}

		if arr[0] == min || arr[n-1] == max || ok {
			fmt.Println(max - min)
		} else {
			ans := -999999
			for i, j := 0, n-1; i < n; i++ {
				val := arr[j] - arr[i]
				if val > ans {
					ans = val
				}
				j = (j + 1) % n
			}
			fmt.Println(ans)
		}

	}
}

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

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1726A
Date: 9/6/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1726/A
Problem: CF1726A
**/
func (in *CF1726A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		min, max := 9999, 0
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			val := in.NextInt()
			arr[i] = val
			if val < min {
				min = val
			}
			if val > max {
				max = val
			}
		}

		fmt.Println("min ", min, " max ", max)
		ok := false
		for i := 0; i < n; i++ {
			if arr[i] == max && arr[(i+1)%n] == min {
				ok = true
				break
			}
		}

		if arr[0] == min || arr[n-1] == max || ok {
			fmt.Println(max - min)
		} else {
			ans := -999999
			for i, j := 0, n-1; i < n; i++ {
				val := arr[j] - arr[i]
				if val > ans {
					ans = val
				}
				j = (j + 1) % n
			}
			fmt.Println(ans)
		}

	}
}

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

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1726A
Date: 9/6/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1726/A
Problem: CF1726A
**/
func (in *CF1726A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		min, max := 9999, 0
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			val := in.NextInt()
			arr[i] = val
			if val < min {
				min = val
			}
			if val > max {
				max = val
			}
		}

		ok := false
		for i := 0; i < n; i++ {
			if arr[i] == max && arr[(i+1)%n] == min {
				ok = true
				break
			}
		}

		if arr[0] == min || arr[n-1] == max || ok {
			fmt.Println(max - min)
		} else {
			fmt.Println(Max(max-arr[0], arr[n-1]-min))
		}

	}
}

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

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1726A
Date: 9/6/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1726/A
Problem: CF1726A
**/
func (in *CF1726A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		min, max := 9999, 0
		indexMax := 0
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			val := in.NextInt()
			arr[i] = val
			if val < min {
				min = val
			}
			if val > max {
				max = val
				indexMax = i
			}
		}

		if arr[0] == min || arr[n-1] == max || arr[(indexMax+1)%n] == min {
			fmt.Println(max - min)
		} else {
			fmt.Println(Max(max-arr[0], arr[n-1]-min))
		}

	}
}

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

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1726A
Date: 9/6/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1726/A
Problem: CF1726A
**/
func (in *CF1726A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		min, max := 9999, 0
		for i := 0; i < n; i++ {
          val := in.NextInt()
          if val < min {
            min = val
          }
          if val > max {
            max = val
          }
        }
        fmt.Println(max - min )
	}
}

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

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	t := readInt(in)
	b := strings.Builder{}
	for i := 0; i < t; i++ {
		b.WriteString(solve(in) + "\n")
	}
	fmt.Println(b.String())
}

func solve(in *bufio.Reader) string {
	n := readInt(in)
	arr := readArrInt(in)

	ans1 := arr[n - 1] - arr[0]
	ans2 := 0
	for i := 0; i < n; i++ {
		idx1 := (n - 1 + i) % n
		idx2 := i
		ans2 = max(arr[idx1] - arr[idx2], ans2)
	}

	ans2 = max(ans2, ans1)

	ans3 := 0
	for i := 0; i < n; i++ {
		ans3 = max(arr[n - 1], arr[i])
	}
	ans3 = max(ans3, ans2)

	ans4 := 0
	for i := 1; i < n; i++ {
		ans4 = max(arr[i] - arr[0], ans4)
	}

	ans4 = max(ans4, ans3)
	return strconv.Itoa(ans4)
}

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

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

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

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

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

package main
import "fmt"
func main() {
    var q int
    fmt.Scan(&q)
    for i := 0; i<q; i++{
        var n int
        fmt.Scan(&n)
        a:= make([]int,n)
        for j:=0; j<n; j++{
            fmt.Scan(&a[j])
        }
        if n==1{
            fmt.Println(0)
            continue
        }else if n==2{
            fmt.Println(a[1]-a[0])
            continue
        }

        var left int = -1000
        var right int = -1000
        var near int = -1000
        var center int = -1000

        for j:=1;j<n;j++{
            if a[j]-a[0] > left{
                left = a[j] - a[0]
            }
            if a[n-1] - a[j-1] > right{
                right = a[n-1] - a[j-1]
            }
            if a[j-1] - a[j] > near{
                near = a[j-1] - a[j]
            }
            if a[j] - a[(j+n-1)%n] > center{
                // fmt.Println((j+n-1)%n)
                center =  a[j] - a[(j+n-1)%n]
            }
        }
        if left >= right && left>=near{
            fmt.Println(left)
        }else if right>=left && right>=near{
            fmt.Println(right)
        }else{
            fmt.Println(near)
        }

    }

}

package main

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

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

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

		a, b := 10000, 0
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)
			if v > b {
				b = v
			}
			if v < a {
				a = v
			}
		}

		if n == 1 {
			fmt.Fprintln(out, 0)
		} else {
			fmt.Fprintln(out, b-a)
		}
	}
}