Permutation $$$p$$$ is a sequence of integers $$$p=[p_1, p_2, \dots, p_n]$$$, consisting of $$$n$$$ distinct (unique) positive integers between $$$1$$$ and $$$n$$$, inclusive. For example, the following sequences are permutations: $$$[3, 4, 1, 2]$$$, $$$[1]$$$, $$$[1, 2]$$$. The following sequences are not permutations: $$$[0]$$$, $$$[1, 2, 1]$$$, $$$[2, 3]$$$, $$$[0, 1, 2]$$$.The important key is in the locked box that you need to open. To open the box you need to enter secret code. Secret code is a permutation $$$p$$$ of length $$$n$$$. You don't know this permutation, you only know the array $$$q$$$ of prefix maximums of this permutation. Formally:  $$$q_1=p_1$$$,  $$$q_2=\max(p_1, p_2)$$$,  $$$q_3=\max(p_1, p_2,p_3)$$$,  ...  $$$q_n=\max(p_1, p_2,\dots,p_n)$$$. You want to construct any possible suitable permutation (i.e. any such permutation, that calculated $$$q$$$ for this permutation is equal to the given array).

The first line contains integer number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. The first line of a test case contains one integer $$$n$$$ $$$(1 \le n \le 10^{5})$$$ — the number of elements in the secret code permutation $$$p$$$. The second line of a test case contains $$$n$$$ integers $$$q_1, q_2, \dots, q_n$$$ $$$(1 \le q_i \le n)$$$ — elements of the array $$$q$$$ for secret permutation. It is guaranteed that $$$q_i \le q_{i+1}$$$ for all $$$i$$$ ($$$1 \le i < n$$$). The sum of all values $$$n$$$ over all the test cases in the input doesn't exceed $$$10^5$$$.

For each test case, print:   If it's impossible to find such a permutation $$$p$$$, print "-1" (without quotes).  Otherwise, print $$$n$$$ distinct integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$). If there are multiple possible answers, you can print any of them.

package main

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

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

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

func init() {
	var f *os.File
	if runtime.GOROOT() == "C:\\SOFT\\Go" {
		f, _ = os.Open("input.txt")
		//defer f.Close()
	} else {
		f = os.Stdin
	}
	ReadString = newReadString(f)
	stdout = bufio.NewWriter(os.Stdout)
}

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

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

// ReadInt returns an integer.
func ReadInt() int {
	return 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
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// 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])
		// 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)
}

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

func solve() {
	n := ReadInt()
	q := ReadIntSlice(n)
	p := make([]int, n)
	nums := make(map[int]int,n)
	for i:=0;i<n;i++{
		nums[i+1]=i+1
	}
	p[0]=q[0]
	delete(nums, q[0])
	for i := 1; i < n; i++ {
		qq := q[i]
		if qq > q[i-1] {
			p[i] = qq
			delete(nums, qq)
			continue
		}
		has :=  false
		for v := range nums {
			if v<qq {
				p[i] = v
				delete(nums, v)
				has= true
				break
			}
		}
		if !has {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(PrintIntsLine(p...))
}

func main() {
	t := ReadInt()
	//t :=1
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

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

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

func init() {
	var f *os.File
	if runtime.GOROOT() == "C:\\SOFT\\Go" {
		f, _ = os.Open("input.txt")
		//defer f.Close()
	} else {
		f = os.Stdin
	}
	ReadString = newReadString(f)
	stdout = bufio.NewWriter(os.Stdout)
}

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

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

// ReadInt returns an integer.
func ReadInt() int {
	return 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
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// 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])
		// 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)
}

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

func solve() {
	n := ReadInt()
	q := ReadIntSlice(n)
	p := make([]int, n)
	nums := make(map[int]int,n)
	p[0]=q[0]
	nums[q[0]]++
	start:=0
	for i := 1; i < n; i++ {
		qq := q[i]
		if qq > q[i-1] {
			p[i] = qq
			nums[qq]++
			continue
		}
		has :=  false
		for k:=start+1; k<qq;k++ {
			if _, ok := nums[k]; !ok {
				p[i] = k
				nums[k]++
				has= true
				start=k
				break
			}
		}
		if !has {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(PrintIntsLine(p...))
}

func main() {
	t := ReadInt()
	//t :=1
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

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

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

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

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

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

// ReadInt returns an integer.
func ReadInt() int {
	return 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
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var t int
var n int
var Q []int

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		n = ReadInt()
		Q = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	memo := make([]int, n+1)
	for i := 1; i <= n; i++ {
		memo[i] = 1
	}

	answers := make([]int, n)
	answers[0] = Q[0]
	memo[Q[0]] = 0
	for i := 1; i < n; i++ {
		if Q[i-1] < Q[i] {
			answers[i] = Q[i]
			memo[Q[i]] = 0
		}
	}

	c := 1
	for i := 0; i < n; i++ {
		// 未割り当てならば、小さいものを割り当てる、矛盾したらアウト
		if answers[i] == 0 {
			for c <= n {
				if memo[c] == 1 {
					if Q[i] >= c {
						answers[i] = c
						c++
						break
					} else {
						fmt.Println(-1)
						return
					}
				}
				// 次の未割り当ての小さい数字まですすめる
				c++
			}
		}
	}

	fmt.Println(PrintIntsLine(answers...))
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

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

package main

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

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

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

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

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

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

// ReadInt returns an integer.
func ReadInt() int {
	return 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
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var t int
var n int
var Q []int

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		n = ReadInt()
		Q = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	memo := make([]int, n+1)
	for i := 1; i <= n; i++ {
		memo[i] = 1
	}

	answers := make([]int, n)
	answers[0] = Q[0]
	memo[Q[0]] = 0
	for i := 1; i < n; i++ {
		if Q[i-1] < Q[i] {
			answers[i] = Q[i]
			memo[Q[i]] = 0
		}
	}

	// 未使用のものを小さい順にスライスに詰める
	unused := []int{}
	for i := 1; i <= n; i++ {
		if memo[i] == 1 {
			unused = append(unused, i)
		}
	}

	for i := 0; i < n; i++ {
		// 未割り当てならば、小さいものを割り当てる、矛盾したらアウト
		if answers[i] == 0 {
			// 次の未使用のものを取り出す
			c := unused[0]
			unused = unused[1:]
			if Q[i] >= c {
				answers[i] = c
			} else {
				fmt.Println(-1)
				return
			}
		}
	}

	// c := 1
	// for i := 0; i < n; i++ {
	// 	// 未割り当てならば、小さいものを割り当てる、矛盾したらアウト
	// 	if answers[i] == 0 {
	// 		for c <= n {
	// 			if memo[c] == 1 {
	// 				if Q[i] >= c {
	// 					answers[i] = c
	// 					c++
	// 					break
	// 				} else {
	// 					fmt.Println(-1)
	// 					return
	// 				}
	// 			}
	// 			// 次の未割り当ての小さい数字まですすめる
	// 			c++
	// 		}
	// 	}
	// }

	fmt.Println(PrintIntsLine(answers...))
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

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

package main

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

func solve(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var t int
outer:
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		ans := make([]int, n)
		vis := make([]bool, n+1)
		vis[a[0]] = true
		ans[0] = a[0]
		for i := 1; i < n; i++ {
			ai := a[i]
			if ai > a[i-1] {
				ans[i] = ai
				vis[ai]=true
			}
		}
		j := 1
		for i := range ans {
			if ans[i] == 0 {
				for ; j < n; j++ {
					if !vis[j] {
						ans[i] = j
						j++
						break
					}
				}
				if ans[i] == 0 {
					Fprintln(out, -1)
					continue outer
				}
			}
		}
		maxv := ans[0]
		for i, ai := range a {
			maxv = max(maxv, ans[i])
			if ai != maxv {
				Fprintln(out, -1)
				continue outer
			}
		}

		for _,ai := range ans {
			Fprint(out, ai, " ")
		}
		Fprintln(out)
	}

}

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

func ifElseI(cond bool, a, b int) int {
	if cond {
		return a
	}
	return b
}
func ifElseS(cond bool, a, b string) string {
	if cond {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

package main

import (
	"fmt"
)

func solve() {
	var n int
	fmt.Scan(&n)
	q:= make([]int,n)
	for i:=0; i<n; i++{
		fmt.Scanf("%d", &q[i])
	}
	p := make([]int, n)
	nums := make(map[int]int,n)
	p[0]=q[0]
	nums[q[0]]++
	start:=0
	for i := 1; i < n; i++ {
		qq := q[i]
		if qq > q[i-1] {
			p[i] = qq
			nums[qq]++
			continue
		}
		has :=  false
		for k:=start+1; k<qq;k++ {
			if _, ok := nums[k]; !ok {
				p[i] = k
				nums[k]++
				has= true
				start=k
				break
			}
		}
		if !has {
			fmt.Println(-1)
			return
		}
	}
	for _,v:= range p{
		fmt.Printf("%d ",v)
	}
	fmt.Println()
}

func main() {
	var t int
	fmt.Scanf("%d\n",&t)
	//t :=1
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

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

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

func init() {
	var f *os.File
	if runtime.GOROOT() == "C:\\SOFT\\Go" {
		f, _ = os.Open("input.txt")
		//defer f.Close()
	} else {
		f = os.Stdin
	}
	ReadString = newReadString(f)
	stdout = bufio.NewWriter(os.Stdout)
}

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

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

// ReadInt returns an integer.
func ReadInt() int {
	return 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
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// 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])
		// 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)
}

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

func solve() {
	n := ReadInt()
	q := ReadIntSlice(n)
	res := true
	p := make([]int,n)
	m := make([]bool,int(1e5+1))
	FOR:
	for i:=0; i<n;i++{
		qq := q[i]
		for {
			if !m[qq]{
				m[qq] = true
				break
			}
			qq--
			if qq<=0 {
				res = false
				break FOR
			}
		}
		p[i] = qq
	}
	if !res {
		fmt.Println(-1)
	}else {
		fmt.Println(PrintIntsLine(p[0:n-1]...))
	}
}

func main() {
	t := ReadInt()
	//t :=1
	for ; t > 0; t-- {
		solve()
	}
}

package main

import (
	"fmt"
)

func solve() {
	var n int
	fmt.Scan(&n)
	q:= make([]int,n)
	for i:=0; i<n; i++{
		fmt.Scanf("%d", &q[i])
	}
	p := make([]int, n)
	nums := make(map[int]int,n)
	p[0]=q[0]
	nums[q[0]]++
	start:=0
	for i := 1; i < n; i++ {
		qq := q[i]
		if qq > q[i-1] {
			p[i] = qq
			nums[qq]++
			continue
		}
		has :=  false
		for k:=start+1; k<qq;k++ {
			if _, ok := nums[k]; !ok {
				p[i] = k
				nums[k]++
				has= true
				start=k
				break
			}
		}
		if !has {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(p)
}

func main() {
	var t int
	fmt.Scanf("%d\n",&t)
	//t :=1
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

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

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

func init() {
	var f *os.File
	if runtime.GOROOT() == "C:\\SOFT\\Go" {
		f, _ = os.Open("input.txt")
		//defer f.Close()
	} else {
		f = os.Stdin
	}
	ReadString = newReadString(f)
	stdout = bufio.NewWriter(os.Stdout)
}

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

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

// ReadInt returns an integer.
func ReadInt() int {
	return 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
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// 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])
		// 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)
}

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

func solve() {
	n := ReadInt()
	q := ReadIntSlice(n)
	p := make([]int, n)
	m := make([]bool, int(1e5+1))
	start := 0
	for i := 0; i < n; i++ {
		qq := start + 1
		for {
			if qq > q[i] {
				fmt.Println(-1)
				return
			}
			if !m[qq] {
				m[qq] = true
				break
			}
			qq++
		}
		p[i] = qq
		start = qq
	}
	fmt.Println(PrintIntsLine(p...))
}

func main() {
	t := ReadInt()
	//t :=1
	for ; t > 0; t-- {
		solve()
	}
}


One day Sasha visited the farmer 2D and his famous magnetic farm. On this farm, the crop grows due to the influence of a special magnetic field. Maintaining of the magnetic field is provided by $$$n$$$ machines, and the power of the $$$i$$$-th machine is $$$a_i$$$. This year 2D decided to cultivate a new culture, but what exactly he didn't say. For the successful growth of the new culture, it is necessary to slightly change the powers of the machines. 2D can at most once choose an arbitrary integer $$$x$$$, then choose one machine and reduce the power of its machine by $$$x$$$ times, and at the same time increase the power of one another machine by $$$x$$$ times (powers of all the machines must stay positive integers). Note that he may not do that if he wants. More formally, 2D can choose two such indices $$$i$$$ and $$$j$$$, and one integer $$$x$$$ such that $$$x$$$ is a divisor of $$$a_i$$$, and change powers as following: $$$a_i = \frac{a_i}{x}$$$, $$$a_j = a_j \cdot x$$$Sasha is very curious, that's why he wants to calculate the minimum total power the farmer can reach. There are too many machines, and Sasha can't cope with computations, help him!

The first line contains one integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — the number of machines. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 100$$$) — the powers of the machines.

Print one integer — minimum total power.

NoteIn the first example, the farmer can reduce the power of the $$$4$$$-th machine by $$$2$$$ times, and increase the power of the $$$1$$$-st machine by $$$2$$$ times, then the powers will be: $$$[2, 2, 3, 2, 5]$$$.In the second example, the farmer can reduce the power of the $$$3$$$-rd machine by $$$2$$$ times, and increase the power of the $$$2$$$-nd machine by $$$2$$$ times. At the same time, the farmer can leave is be as it is and the total power won't change.In the third example, it is optimal to leave it be as it is.

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	res := 0
	d := 0
	for i := 0; i < n; i++ {
		res += a[i]
		for j := 1; j <= a[i]; j++ {
			if a[i]%j == 0 {
				t := a[i] - a[i]/j + a[0] - a[0]*j
				if t > 0 && t > d {
					d = t
				}
			}
		}
	}
	fmt.Printf("%d", res-d)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	sum := 0
	a := make([]int, 101)
	q := 0
	for i := 1; i <= n; i++ {
		fmt.Fscanf(in, "%d", &q)
		a[q]++
		sum += q
	}
	fmt.Fscanf(in, "\n")
	max := 0
	//fmt.Println(a)
	for i := 100; i >= 1; i-- {
		for j := 1; j < i; j++ {
			if a[i] > 0 && a[j] > 0 {
				for k := 2; k <= i; k++ {
					if i%k == 0 {
						if (i+j)-(i/k+j*k) > max {
							max = (i + j) - (i/k + j*k)
							//fmt.Println(max, i, j, k)
						}
					}
				}
			}
		}
	}
	fmt.Fprintf(out, "%d\n", sum-max)
	return
}

package main

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

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

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

func main() {
	defer writer.Flush()
	var n, t1, t2 int
	scanf("%d\n", &n)
	arr := [111]int{}
	for i := 0; i < n; i++ {
		scanf("%d", &t1)
		arr[t1]++
	}

	p1, p2, dd, cnt := 0, 0, 1, 0

	mx := -1

	for mn := 1; mn < 100; mn++ {
		if arr[mn] == 0 {
			continue
		}
		for i := 100; i > mn; i-- {
			if arr[i] > 0 {
				for d := 2; d <= i; d++ {
					if i%d == 0 {
						lessn := i - i/d
						inc := (d - 1) * mn
						if inc < lessn {
							t1 = arr[mn]
							t2 = arr[i]
							if t2 > t1 {
								t2 = t1
							}
							if lessn-inc > mx {
								mx = lessn - inc
								p1 = mn
								p2 = i
								cnt = 1
								dd = d

							}
						}

					}
				}
			}

		}
	}
	arr[p1] -= cnt
	arr[p1*dd] += cnt
	arr[p2/dd] += cnt
	arr[p2] -= cnt

	ans := 0
	for i := 1; i < 111; i++ {
		ans += arr[i] * i
	}
	fmt.Println(ans)
}

package main

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

func main() {
	rd := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(rd, "%d", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	res := 0
	d := 0
	for i := 0; i < n; i++ {
		res += a[i]
		for j := 1; j <= a[i]; j++ {
			if a[i]%j == 0 {
				t := a[i] - a[i]/j + a[0] - a[0]*j
				if t > 0 && t > d {
					d = t
				}
			}
		}
	}
	fmt.Println(res - d)
}

package main

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

func main() {
	rd := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(rd, "%d", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	res := 0
	d := 0
	for i := 0; i < n; i++ {
		res += a[i]
		for j := 1; j <= a[i]; j++ {
			if a[i]%j == 0 {
				t := a[i] - a[i]/j + a[0] - a[0]*j
				if t > 0 && t > d {
					d = t
				}
			}
		}
	}
	fmt.Printf("%d", res-d)
}

package main

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

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

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

func main() {
	defer writer.Flush()
	var n, t1, t2 int
	scanf("%d\n", &n)
	arr := [111]int{}
	for i := 0; i < n; i++ {
		scanf("%d", &t1)
		arr[t1]++
	}
	flag := true
	for flag {
		flag = false
		mn := 111
		for i := 1; i < 101; i++ {
			if arr[i] > 0 {
				mn = i
				break
			}
		}

		for i := 100; i > mn; i-- {
			if flag {
				break
			}
			if arr[i] > 0 {
				for d := 2; d <= i; d++ {
					if i%d == 0 {

						lessn := i - i/d
						inc := (d - 1) * mn

						if inc < lessn {
							t1 = arr[mn]
							t2 = arr[i]
							if t2 > t1 {
								t2 = t1
							}
							arr[mn] -= t2
							arr[d*mn] += t2
							arr[i] -= t2
							arr[i/d] += t2
							flag = true
							break
						}

					}
				}
			}

		}
	}
	ans := 0
	for i := 1; i < 111; i++ {
		ans += arr[i] * i
	}
	fmt.Println(ans)
}

package main

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

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

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

func main() {
	defer writer.Flush()
	var n, t1, t2 int
	scanf("%d\n", &n)
	arr := [111]int{}
	for i := 0; i < n; i++ {
		scanf("%d", &t1)
		arr[t1]++
	}
	flag := true
	for flag {
		flag = false
		mn := 111
		for i := 1; i < 101; i++ {
			if arr[i] > 0 {
				mn = i
				break
			}
		}

		for i := 100; i > mn; i-- {
			if flag {
				break
			}
			if arr[i] > 0 {
				for d := i; d > 1; d-- {
					if i%d == 0 {

						lessn := i - i/d
						inc := (d - 1) * mn

						if inc < lessn {
							t1 = arr[mn]
							t2 = arr[i]
							if t2 > t1 {
								t2 = t1
							}
							arr[mn] -= t2
							arr[d*mn] += t2
							arr[i] -= t2
							arr[i/d] += t2
							flag = true
							break
						}

					}
				}
			}

		}
	}
	ans := 0
	for i := 1; i < 111; i++ {
		ans += arr[i] * i
	}
	fmt.Println(ans)
}

package main

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

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

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

func main() {
	defer writer.Flush()
	var n, t1, t2 int
	scanf("%d\n", &n)
	arr := [111]int{}
	for i := 0; i < n; i++ {
		scanf("%d", &t1)
		arr[t1]++
	}

	p1, p2, dd, cnt := 0, 0, 1, 0

	mx := -1

	for mn := 1; mn < 100; mn++ {
		if arr[mn] == 0 {
			continue
		}
		for i := 100; i > mn; i-- {
			if arr[i] > 0 {
				for d := 2; d <= i; d++ {
					if i%d == 0 {
						lessn := i - i/d
						inc := (d - 1) * mn
						if inc < lessn {
							t1 = arr[mn]
							t2 = arr[i]
							if t2 > t1 {
								t2 = t1
							}
							if t2*(lessn-inc) > mx {
								mx = t2 * (lessn - inc)
								p1 = mn
								p2 = i
								cnt = t2
								dd = d

							}
						}

					}
				}
			}

		}
	}
	arr[p1] -= cnt
	arr[p1*dd] += cnt
	arr[p2/dd] += cnt
	arr[p2] -= cnt

	ans := 0
	for i := 1; i < 111; i++ {
		ans += arr[i] * i
	}
	fmt.Println(ans)
}

package main

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

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

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

func main() {
	defer writer.Flush()
	var n, t1, t2 int
	scanf("%d\n", &n)
	arr := [111]int{}
	for i := 0; i < n; i++ {
		scanf("%d", &t1)
		arr[t1]++
	}

	p1, p2, dd, cnt := 0, 0, 1, 0

	mx := -1

	for mn := 1; mn < 100; mn++ {
		if arr[mn] == 0 {
			continue
		}
		for i := 100; i > mn; i-- {
			if arr[i] > 0 {
				for d := 2; d <= i; d++ {
					if i%d == 0 {
						lessn := i - i/d
						inc := (d - 1) * mn
						if inc < lessn {
							t1 = arr[mn]
							t2 = arr[i]
							if t2 > t1 {
								t2 = t1
							}
							if lessn-inc > mx {
								mx = lessn - inc
								p1 = mn
								p2 = i
								cnt = t2
								dd = d

							}
						}

					}
				}
			}

		}
	}
	arr[p1] -= cnt
	arr[p1*dd] += cnt
	arr[p2/dd] += cnt
	arr[p2] -= cnt

	ans := 0
	for i := 1; i < 111; i++ {
		ans += arr[i] * i
	}
	fmt.Println(ans)
}


This is the hard version of the problem. The only difference is that in this version $$$n \leq 200000$$$. You can make hacks only if both versions of the problem are solved.There are $$$n$$$ potions in a line, with potion $$$1$$$ on the far left and potion $$$n$$$ on the far right. Each potion will increase your health by $$$a_i$$$ when drunk. $$$a_i$$$ can be negative, meaning that potion will decrease will health.You start with $$$0$$$ health and you will walk from left to right, from first potion to the last one. At each potion, you may choose to drink it or ignore it. You must ensure that your health is always non-negative.What is the largest number of potions you can drink?

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 200000$$$) — the number of potions.  The next line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ... ,$$$a_n$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) which represent the change in health after drinking that potion.

Output a single integer, the maximum number of potions you can drink without your health becoming negative.

NoteFor the sample, you can drink $$$5$$$ potions by taking potions $$$1$$$, $$$3$$$, $$$4$$$, $$$5$$$ and $$$6$$$. It is not possible to drink all $$$6$$$ potions because your health will go negative at some point

package main

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

const (
	MOD int64 = 1e9+7
	NL byte = byte('\n')
	SP byte = byte(' ')
)

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

	n int
	a [200000]int
	res int
)

func main() {
	initBuffer()
	var t int = 1
	// t = getInt()
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {

}

func input() {
	n = getInt()
	for i := 0; i < n; i++ {
		a[i] = getInt()
	}
}

type IntHeap []int
type any = interface{}

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

func (h *IntHeap) Push(x any) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() any {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func count() {
	var cur int64
	h := &IntHeap{}
	heap.Init(h)
	for i := 0; i < n; i++ {
		res++
		cur += int64(a[i])
		heap.Push(h, a[i])
		if cur < 0 {
			res--
			cur -= int64((*h)[0])
			heap.Pop(h)
		}
	}
}

func output() {
	out.Write(intToBytes(res))
}

func test() {
	fmt.Print()
}

func initBuffer() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	in.Split(scanWords)
	out = bufio.NewWriter(os.Stdout)
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	i := bytes.IndexByte(data, '\n')
	j := bytes.IndexByte(data, ' ')
	ind := min(i, j)
	if ind < 0 {
		ind = max(i, j)
	}
	if ind >= 0 {
		return ind + 1, dropCR(data[0:ind]), nil
	}
	if atEOF {
		return len(data), dropCR(data), nil
	}
	return 0, nil, nil
}

func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[:len(data)-1]
	}
	return data
}

func getFloat() float64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res1 int64
	for i := 0; i < len(b); i++ {
		if b[i] == '.' {
			b = b[i+1:]
			break
		}
		res1 *= 10
		res1 += int64(b[i]) - 48
		if i == len(b) - 1 {
			b = b[:0]
		}
	}
	var res2 float64
	for i := len(b); i > 0; i-- {
		res2 += float64(b[i-1]) - 48
		res2 /= 10
	}
	if isNeg {
		res1 *= -1
		res2 *= -1
	}
	return float64(res1) + res2
}

func getInt() int {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getInt64() int64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int64
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int64(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

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

func intToBytes(n int) []byte {
	var res [33]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 33
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 33 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func int64ToBytes(n int64) []byte {
	var res [65]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 65
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 65 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	if n1 > n2 {
		return n1
	}
	return n2
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	if n1 < n2 {
		return n1
	}
	return n2
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(arr[ind])
	out.WriteByte(NL)
	return res
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)
type IntHeap []int

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

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}
func main() {
	var n int
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	fmt.Fscan(in,&n)
	a := make([]int,n+5)
	for i:=1;i<=n;i++{
		fmt.Fscan(in,&a[i])
	}
	st := &IntHeap{}
	heap.Init(st)
	var cur int64
	cur = 0
	ret := 0
	for i:=1;i<=n;i++{
		if a[i]>=0{
			cur += int64(a[i])
			ret++
		}else{
			if cur + int64(a[i]) >= 0{
				cur = cur + int64(a[i])
				heap.Push(st,a[i])
				ret++
			}else{
				if len(*st)>0{
					if (*st)[0]<a[i]{
						cur -= int64((*st)[0])
						cur += int64(a[i])
						heap.Pop(st)
						heap.Push(st,a[i])
					}
				}
			}
		}
	}
	fmt.Fprintln(out,ret)
}

package main

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

// github.com/EndlessCheng/codeforces-go
type hp struct{ sort.IntSlice }

func (h *hp) Push(v interface{}) { h.IntSlice = append(h.IntSlice, v.(int)) }
func (h *hp) Pop() interface{}   { a := h.IntSlice; v := a[len(a)-1]; h.IntSlice = a[:len(a)-1]; return v }
func (h *hp) push(v int)         { heap.Push(h, v) }
func (h hp) empty() bool         { return len(h.IntSlice) == 0 }
func (h hp) top() int            { return h.IntSlice[0] }

func CF1526C2(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, cntP int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
		if a[i] >= 0 {
			cntP++
		}
	}

	s := int64(0)
	h := hp{}
	for _, v := range a {
		if v >= 0 {
			s += int64(v)
		} else {
			if s+int64(v) >= 0 {
				h.push(v)
				s += int64(v)
			} else if h.Len() > 0 && v > h.top() {
				s -= int64(h.top())
				s += int64(v)
				h.IntSlice[0] = v
				heap.Fix(&h, 0)
			}
		}
	}
	Fprint(out, cntP+h.Len())
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
type hp struct{ sort.IntSlice }

func (h *hp) Push(v interface{}) { h.IntSlice = append(h.IntSlice, v.(int)) }
func (h *hp) Pop() interface{}   { a := h.IntSlice; v := a[len(a)-1]; h.IntSlice = a[:len(a)-1]; return v }
func (h *hp) push(v int)         { heap.Push(h, v) }
func (h *hp) pop() int           { return heap.Pop(h).(int) }
func (h hp) empty() bool         { return len(h.IntSlice) == 0 }
func (h hp) top() int            { return h.IntSlice[0] }

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

	var n, cntP int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
		if a[i] >= 0 {
			cntP++
		}
	}

	s := int64(0)
	h := hp{}
	for _, v := range a {
		if v >= 0 {
			s += int64(v)
		} else {
			if s+int64(v) >= 0 {
				h.push(v)
				s += int64(v)
			} else if !h.empty() {
				if v > h.top() {
					s -= int64(h.top())
					s += int64(v)
					h.IntSlice[0] = v
					heap.Fix(&h, 0)
				}
			}
		}
	}
	Fprintln(out, cntP+h.Len())
}

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

package main

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

type Item struct {
	value    int
	priority int
	index    int
}

type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = j
	pq[j].index = i
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil
	item.index = -1
	*pq = old[:n-1]
	return item
}

func (pq *PriorityQueue) update(item *Item, value int, priority int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

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

func main() {
	defer out.Flush()
	solve := func(Case int) {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		pq := PriorityQueue{}
		heap.Init(&pq)
		cur := int64(0)
		for i, elem := range a {
			heap.Push(&pq, &Item{elem, elem, i})
			cur += int64(elem)
			for cur < 0 {
				top := (*pq[0]).value
				cur -= int64(top)
				heap.Pop(&pq)
			}
		}
		fmt.Fprintln(out, len(pq))
	}

	T := 1
	//fmt.Fscan(in, &T) //
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}
}

func powMod(x, y, mod int64) int64 {
	ans := int64(1)
	for y != 0 {
		if y&1 != 0 {
			ans = (ans * x) % mod
		}
		y = y >> 1
		x = (x * x) % mod
	}
	return ans
}
func max(x ...int) int {
	ans := math.MinInt32
	for i := range x {
		if x[i] > ans {
			ans = x[i]
		}
	}
	return ans
}

func min(x ...int) int {
	ans := math.MaxInt32
	for i := range x {
		if x[i] < ans {
			ans = x[i]
		}
	}
	return ans
}
func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func reverse(s []byte) []byte {
	a := []byte(s)
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return a
}

package main

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

type viPair struct {
	v  int
	hi int // *viPair 在 mh 中的下标，可随着 Push Pop 等操作自动改变
}
type mh []*viPair // mh 指 modifiable heap

func (h mh) Len() int              { return len(h) }
func (h mh) Less(i, j int) bool    { return h[i].v > h[j].v } // > 为最大堆
func (h mh) Swap(i, j int)         { h[i], h[j] = h[j], h[i]; h[i].hi = i; h[j].hi = j }
func (h *mh) Push(v interface{})   { *h = append(*h, v.(*viPair)) }
func (h *mh) Pop() interface{}     { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v }
func (h *mh) push(v int) *viPair   { p := &viPair{v, len(*h)}; heap.Push(h, p); return p }
func (h *mh) pop() *viPair         { return heap.Pop(h).(*viPair) }
func (h *mh) fix(i int)            { heap.Fix(h, i) }
func (h *mh) remove(i int) *viPair { return heap.Remove(h, i).(*viPair) }
func (h mh) top() int              { return h[0].v }

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

var n int

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

func main() {
	defer ww.Flush()
	fmt.Fscan(rr, &n)
	nums := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(rr, &nums[i])
	}
	sum, take, ans := 0, 0, 0
	hp := mh{}
	for i := 0; i < n; i++ {
		if nums[i] >= 0 {
			sum += nums[i]
			take++
		} else {
			sum += nums[i]
			take++
			hp.push(-nums[i])
			for hp.Len() > 0 && sum < 0 {
				sum += hp.top()
				take--
				hp.pop()
			}
		}
		ans = max(ans, take)
	}
	fmt.Fprintln(ww, ans)
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

type PQItem struct {
	value    string // The value of the item; arbitrary.
	priority int    // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds PQItems.
type PriorityQueue []*PQItem

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// Min heap instead of the Max heap in the example
	return pq[i].priority < pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*PQItem)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an PQItem in the queue.
func (pq *PriorityQueue) update(item *PQItem, value string, priority int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)
	l2, _ := Readln(reader)
	pvals := strings.Split(l2, " ")
	vals := make([] int, k)
	for i:= range vals {
		vals[i],_ = strconv.Atoi(pvals[i])
	}
	pq := make(PriorityQueue , 0)
	heap.Init(&pq)
	hp := int64(0)
	for i,priority := range vals {
		temp := &PQItem{
			priority: priority,
			index: i,
		}
		hp+= int64(priority)
		//heap.Push(&pq,temp)
		if hp>= 0 {
			heap.Push(&pq,temp)
		} else {
			heap.Push(&pq,temp)
			hp-= int64(heap.Pop(&pq).(*PQItem).priority)
		}

	}
	//for i:= range pq {
	//	fmt.Println(pq[i].priority)
	//}
	fmt.Println(len(pq))
}

package main

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

const (
	MOD int64 = 1e9+7
	NL byte = byte('\n')
	SP byte = byte(' ')
)

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

	n int
	a [200000]int
	res int
)

func main() {
	initBuffer()
	var t int = 1
	// t = getInt()
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {

}

func input() {
	n = getInt()
	for i := 0; i < n; i++ {
		a[i] = getInt()
	}
}

func count() {
	sort.Ints(a[:n])
	var cur int64
	for i := n - 1; i >= 0; i-- {
		cur += int64(a[i])
		if cur < 0 {
			return
		}
		res++
	}
}

func output() {
	out.Write(intToBytes(res))
}

func test() {
	fmt.Print()
}

func initBuffer() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	in.Split(scanWords)
	out = bufio.NewWriter(os.Stdout)
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	i := bytes.IndexByte(data, '\n')
	j := bytes.IndexByte(data, ' ')
	ind := min(i, j)
	if ind < 0 {
		ind = max(i, j)
	}
	if ind >= 0 {
		return ind + 1, dropCR(data[0:ind]), nil
	}
	if atEOF {
		return len(data), dropCR(data), nil
	}
	return 0, nil, nil
}

func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[:len(data)-1]
	}
	return data
}

func getFloat() float64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res1 int64
	for i := 0; i < len(b); i++ {
		if b[i] == '.' {
			b = b[i+1:]
			break
		}
		res1 *= 10
		res1 += int64(b[i]) - 48
		if i == len(b) - 1 {
			b = b[:0]
		}
	}
	var res2 float64
	for i := len(b); i > 0; i-- {
		res2 += float64(b[i-1]) - 48
		res2 /= 10
	}
	if isNeg {
		res1 *= -1
		res2 *= -1
	}
	return float64(res1) + res2
}

func getInt() int {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getInt64() int64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int64
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int64(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

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

func intToBytes(n int) []byte {
	var res [33]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 33
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 33 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func int64ToBytes(n int64) []byte {
	var res [65]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 65
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 65 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	if n1 > n2 {
		return n1
	}
	return n2
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	if n1 < n2 {
		return n1
	}
	return n2
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(arr[ind])
	out.WriteByte(NL)
	return res
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)
type IntHeap []int

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

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}
func main() {
	var n int
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	fmt.Fscan(in,&n)
	a := make([]int,n+5)
	for i:=1;i<=n;i++{
		fmt.Fscan(in,&a[i])
	}
	st := &IntHeap{}
	heap.Init(st)
	cur := 0
	ret := 0
	for i:=1;i<=n;i++{
		if a[i]>=0{
			cur += a[i]
			ret++
		}else{
			if cur + a[i] >= 0{
				cur = cur + a[i]
				heap.Push(st,a[i])
				ret++
			}else{
				if len(*st)>0{
					if (*st)[0]<a[i]{
						cur -= (*st)[0]
						cur += a[i]
						heap.Pop(st)
						heap.Push(st,a[i])
					}
				}
			}
		}
	}
	fmt.Fprintln(out,ret)
}

package main

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

type Item struct {
	value    int
	priority int
	index    int
}

type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = j
	pq[j].index = i
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil
	item.index = -1
	*pq = old[:n-1]
	return item
}

func (pq *PriorityQueue) update(item *Item, value int, priority int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

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

func main() {
	defer out.Flush()
	solve := func(Case int) {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		pq := PriorityQueue{}
		heap.Init(&pq)
		cur, ans := int64(0), int64(0)
		for i := range a {
			elem := a[i]
			if cur+int64(elem) >= 0 {
				ans++
				heap.Push(&pq, &Item{int(elem), int(elem), i})
				cur += int64(elem)
			} else {
				if len(pq) == 0 {
					continue
				}
				top := (*pq[0]).value
				if top < elem {
					heap.Pop(&pq)
					cur -= int64(top - elem)
				}
			}
		}
		fmt.Fprintln(out, ans)
	}

	T := 1
	//fmt.Fscan(in, &T) //
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}
}

func powMod(x, y, mod int64) int64 {
	ans := int64(1)
	for y != 0 {
		if y&1 != 0 {
			ans = (ans * x) % mod
		}
		y = y >> 1
		x = (x * x) % mod
	}
	return ans
}
func max(x ...int) int {
	ans := math.MinInt32
	for i := range x {
		if x[i] > ans {
			ans = x[i]
		}
	}
	return ans
}

func min(x ...int) int {
	ans := math.MaxInt32
	for i := range x {
		if x[i] < ans {
			ans = x[i]
		}
	}
	return ans
}
func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func reverse(s []byte) []byte {
	a := []byte(s)
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return a
}


Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple:  The game starts with n piles of stones indexed from 1 to n. The i-th pile contains si stones. The players make their moves alternatively. A move is considered as removal of some number of stones from a pile. Removal of 0 stones does not count as a move. The player who is unable to make a move loses.Now Jon believes that he is ready for battle, but Sam does not think so. To prove his argument, Sam suggested that they play a modified version of the game.In this modified version, no move can be made more than once on a pile. For example, if 4 stones are removed from a pile, 4 stones cannot be removed from that pile again.Sam sets up the game and makes the first move. Jon believes that Sam is just trying to prevent him from going to battle. Jon wants to know if he can win if both play optimally.

First line consists of a single integer n (1 ≤ n ≤ 106) — the number of piles. Each of next n lines contains an integer si (1 ≤ si ≤ 60) — the number of stones in i-th pile.

Print a single line containing "YES" (without quotes) if Jon wins, otherwise print "NO" (without quotes)

NoteIn the first case, Sam removes all the stones and Jon loses.In second case, the following moves are possible by Sam:  In each of these cases, last move can be made by Jon to win the game as follows:

package main

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

var G []map[uint64]int

var mex_a = make([]int, 70)

func mex(a []int) int {
	n := len(a)
	for i := 0; i <= n; i++ {
		mex_a[i] = 0
	}
	for _, x := range a {
		if x <= n {
			mex_a[x] = 1
		}
	}
	r := 0
	for mex_a[r] == 1 {
		r += 1
	}
	return r
}

func grandi(n int, mask uint64) int {
	if n < 1 {
		return 0
	}
	if v, ok := G[n][mask]; ok {
		return v
	}
	a := make([]int, 0, n)
	for i := 1; i <= n; i++ {
		if (mask & (1 << uint(i))) == 0 {
			a = append(a, grandi(n - i, mask | (1 << uint(i))))
		}
	}
	r := mex(a)
	G[n][mask] = r
	// fmt.Printf("%d %d = %d\n", n, mask, r)
	return r
}

func solve(n int, a []int) bool {
	g := 0
	for _, x := range a {
		g ^= grandi(x, 0)
	}
	return g != 0
}

func main() {
	G = make([]map[uint64]int, 61)
	for i := 1; i <= 60; i++ {
		G[i] = make(map[uint64]int)
	}
	cin := NewParser(bufio.NewReaderSize(os.Stdin, 1<<16))
	n := cin.nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = cin.nextInt()
	}
	if solve(n, a) {
		fmt.Print("NO")
	} else {
		fmt.Print("YES")
	}
}

// some io

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

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

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

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

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

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

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

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


Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white.Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it will split into (k + 1) parts. Note, that each part will be a tree with colored vertices.Now Appleman wonders, what is the number of sets splitting the tree in such a way that each resulting part will have exactly one black vertex? Find this number modulo 1000000007 (109 + 7).

The first line contains an integer n (2  ≤ n ≤ 105) — the number of tree vertices.  The second line contains the description of the tree: n - 1 integers p0, p1, ..., pn - 2 (0 ≤ pi ≤ i). Where pi means that there is an edge connecting vertex (i + 1) of the tree and vertex pi. Consider tree vertices are numbered from 0 to n - 1. The third line contains the description of the colors of the vertices: n integers x0, x1, ..., xn - 1 (xi is either 0 or 1). If xi is equal to 1, vertex i is colored black. Otherwise, vertex i is colored white.

Output a single integer — the number of ways to split the tree modulo 1000000007 (109 + 7).

//http://codeforces.com/contest/461/problem/B

package main
import (
	"fmt"
)

const MOD = 1e9 + 7
var (
	n int
	dp []struct{zero, one int64}
	tree [][]int
	cols []bool
	visited []bool
)

func Solve(cur int) (int64, int64) {
	if dp[cur].zero != -1 && dp[cur].one != -1 {
		return dp[cur].zero, dp[cur].one
	}
//	fmt.Println(cur)
	var ans struct{zero, one int64}
	if (cols[cur]) {
		ans.zero, ans.one = 0, 1
	} else {
		ans.zero, ans.one = 1, 0
	}
	for _, i := range tree[cur] {
//		fmt.Println(i)
		if visited[i] {
			continue
		}
		visited[i] = true
		a, b := Solve(i)
		if cols[cur] {
			ans.one *= (a + b) % MOD
			ans.one %= MOD
		} else {
			ans.one *= (a + b) % MOD
			ans.one %= MOD
			ans.one += (ans.zero * b) % MOD
			ans.one %= MOD
			ans.zero *= (a + b) % MOD
			ans.zero %= MOD
		}
	}
	dp[cur] = ans
	return ans.zero, ans.one
}

func main() {
	fmt.Scanf("%d\n", &n)
	tree = make([][]int, n)
	for i := 0; i < n-1; i++ {
		var x int
		fmt.Scanf("%d", &x)
//		fmt.Println(x)
		tree[x] = append(tree[x], i+1)
		tree[i+1] = append(tree[i+1], x)
	}
	fmt.Scanf("\n")
	cols = make([]bool, n)
	for i := 0; i < n; i++ {
		var x int
		fmt.Scanf("%d", &x)
//		fmt.Println(x)
		cols[i] = (x == 1)
	}
//	fmt.Println(cols)
	visited = make([]bool, n)
	visited[0] = true
	dp = make([]struct{zero, one int64}, n)
	for i := range dp {
		dp[i].zero = -1
		dp[i].one = -1
	}
//	fmt.Println(children)
	_, ans := Solve(0)
	fmt.Println(ans)
}

package main

func main() {
	var a func(int)
	a = func(x int) {
		if x <= 0 {
			return
		}
		go a(x-1)
	}
	go a(100)
}