You are given a number $$$n$$$ and an array $$$b_1, b_2, \ldots, b_{n+2}$$$, obtained according to the following algorithm:   some array $$$a_1, a_2, \ldots, a_n$$$ was guessed;  array $$$a$$$ was written to array $$$b$$$, i.e. $$$b_i = a_i$$$ ($$$1 \le i \le n$$$);  The $$$(n+1)$$$-th element of the array $$$b$$$ is the sum of the numbers in the array $$$a$$$, i.e. $$$b_{n+1} = a_1+a_2+\ldots+a_n$$$;  The $$$(n+2)$$$-th element of the array $$$b$$$ was written some number $$$x$$$ ($$$1 \le x \le 10^9$$$), i.e. $$$b_{n+2} = x$$$; The  array $$$b$$$ was shuffled. For example, the array $$$b=[2, 3, 7, 12 ,2]$$$ it could be obtained in the following ways:   $$$a=[2, 2, 3]$$$ and $$$x=12$$$;  $$$a=[3, 2, 7]$$$ and $$$x=2$$$. For the given array $$$b$$$, find any array $$$a$$$ that could have been guessed initially.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$). The second row of each test case contains $$$n+2$$$ integers $$$b_1, b_2, \ldots, b_{n+2}$$$ ($$$1 \le b_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output:    "-1", if the array $$$b$$$ could not be obtained from any array $$$a$$$;  $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$, otherwise.  If there are several arrays of $$$a$$$, you can output any.

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		high := 0
		shigh := 0
		ps := 0

		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
			if b[i] <= high && b[i] > shigh {
				shigh = b[i]
			} else if b[i] > high {
				shigh = high
				high = b[i]
			}
			ps += b[i]
		}
		// sort.Ints(b)

		ps -= (high + shigh)
		if ps == high || ps == shigh {
			skip_high := true
			ship_shigh := true
			for i := 0; i < n+2; i++ {
				if skip_high {
					if b[i] == high {
						skip_high = false
						continue
					}
				}
				if ship_shigh {
					if b[i] == shigh {
						ship_shigh = false
						continue
					}
				}
				write(f, b[i], " ")
			}
			write(f, "\n")
		} else {
			rem := ps - (high - shigh)
			ok := false
			skip := -1
			for i := 0; i < n+2; i++ {
				if b[i] == rem && b[i] != shigh && b[i] != high {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				skip_high := true
				for i := 0; i < n+2; i++ {
					if i == skip || b[i] == high {
						if i == skip {
							continue
						} else if skip_high {
							skip_high = false
							continue
						}
					}
					write(f, b[i], " ")
				}
				write(f, "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
		}
		sort.Ints(b)
		ps := 0
		for i := 0; i < n; i++ {
			ps += b[i]
		}
		if ps == b[n] || ps == b[n+1] {
			for i := 0; i < n; i++ {
				write(f, b[i])
				if i == n-1 {
					write(f, "\n")
				} else {
					write(f, " ")
				}
			}
		} else {
			rem := ps - (b[n+1] - b[n])
			ok := false
			skip := -1
			for i := 0; i < n; i++ {
				if b[i] == rem {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				for i := 0; i < n; i++ {
					if i == skip {
						continue
					}
					write(f, b[i], " ")
				}
				write(f, b[n], "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {
		var n int

		fmt.Fscan(r, &n)

		b := make([]int, n + 2)

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

		r, ar := solve(b, n)

		if !r {
			fmt.Println("-1")
		} else {
			for j := 0; j < len(ar); j++ {
				fmt.Print(ar[j])
				fmt.Print(" ")
			}
		}
		fmt.Println()
	}
}

func solve(b []int, n int) (bool, []int) {
	mp := make(map[int64][]int)

	var s int64

	for i :=0 ; i < len(b); i++ {
		if len(mp[int64(b[i])]) < 2 {
			mp[int64(b[i])] = append(mp[int64(b[i])], i)
		}

		s += int64(b[i])
	}

	var a []int

	for i := 0; i < len(b); i++ {
		rest := s - int64(b[i])

		if rest % 2 == 1 {
			continue
		}

		r := rest/2

		v, ok := mp[r]

		var idx int = -1

		if ok {

			for k := 0; k < len(v); k++ {
				if v[k] != i {
					idx = v[k]
				}
			}
		}

		if idx == -1 {
			continue
		}

		if ok {
			for j := 0; j < len(b); j++ {
				if j == i || j == idx {
					continue
				}
				a = append(a, b[j])
			}
			return true, a
		}
	}

	return false, []int{}
}

// link: https://codeforces.com/problemset/problem/1512/D
// b(n+1) must be biggest or second biggest number

package main

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

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

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

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

		bArr := make([]uint64, n+2)

		for j := 0; j < n+2; j++ {
			var val uint64
			fmt.Fscan(in, &val)

			bArr[j] = val
		}

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

		var sum uint64
		for j := 0; j < n; j++ {
			sum += bArr[j]
		}

		if sum == bArr[n] {
			for j := 0; j < n; j++ {
				fmt.Fprintf(out, "%d ", bArr[j])
			}
			fmt.Fprintln(out)
			continue
		}

		sum += bArr[n]

		var found bool
		for j := 0; j < n+1; j++ {
			if sum-bArr[j] == bArr[n+1] {
				bArr[j] = 0
				found = true
				break
			}
		}

		if found {
			for j := 0; j < n+1; j++ {
				if bArr[j] == 0 {
					continue
				}
				fmt.Fprintf(out, "%d ", bArr[j])
			}
			fmt.Fprintln(out)
		} else {
			fmt.Fprintln(out, "-1")
		}
	}
}

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

// link: https://codeforces.com/problemset/problem/1512/D
// b(n+1) must be biggest or second biggest number

package main

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

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

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

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

		bArr := make([]uint64, n+2)

		var biggestValIndex uint64
		var biggestVal uint64
		var secondBiggestValIndex uint64
		var secondBiggestVal uint64
		var sum uint64
		for j := 0; j < n+2; j++ {
			var val uint64
			fmt.Fscan(in, &val)

			bArr[j] = val
			sum += val

			if val > biggestVal {
				secondBiggestValIndex = biggestValIndex
				secondBiggestVal = biggestVal

				biggestValIndex = uint64(j)
				biggestVal = val
			} else if val > secondBiggestVal {
				secondBiggestValIndex = uint64(j)
				secondBiggestVal = val
			}
		}

		// let b(n+2) = biggestVal, b(n+1) = secondBiggestVal
		if sum-biggestVal-secondBiggestVal == secondBiggestVal {
			for j := 0; j < n+2; j++ {
				if uint64(j) == biggestValIndex || uint64(j) == secondBiggestValIndex {
					continue
				}

				fmt.Fprintf(out, "%d ", bArr[j])
			}
			fmt.Fprintln(out)
			continue
		}

		// let b(n+1) = biggestVal
		sumOfAnPlusX := sum - biggestVal
		x := -1

		for j := 0; j < n+2; j++ {
			if uint64(j) == biggestValIndex {
				continue
			}

			if sumOfAnPlusX-bArr[j] == biggestVal {
				x = j
				break
			}
		}

		if x == -1 {
			fmt.Fprintln(out, "-1")
		} else {
			for j := 0; j < n+2; j++ {
				if uint64(j) == biggestValIndex || j == x {
					continue
				}

				fmt.Fprintf(out, "%d ", bArr[j])
			}
			fmt.Fprintln(out)
		}
	}
}

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

package main

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

func check(b bool) {
	if !b {
		_, _, line, _ := runtime.Caller(1)
		fmt.Printf("check failed line %d\n", line)
		os.Exit(-1)
	}
}

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

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

func lowerBound(arr []int, t int) int {
	lo := 0
	hi := len(arr)
	for lo < hi {
		mid := lo + (hi-lo)/2
		if arr[mid] >= t {
			hi = mid
		} else {
			lo = mid + 1
		}
	}
	return hi
}

const (
	INIT = -1
	INF  = int(1e9)
)

var (
	r      = bufio.NewReader(os.Stdin)
	w      = bufio.NewWriter(os.Stdout)
	exists = struct{}{} // for use with map[...]struct{}

	n int
	a []int64
)

func output() {
	for i := 0; i < n; i++ {
		fmt.Fprintf(w, "%d ", a[i])
	}
	fmt.Fprintln(w)
}
func solve() bool {
	check(len(a) == n+2)
	sort.Slice(a, func(i, j int) bool {
		return a[i] < a[j]
	})

	var sum int64
	for i := 0; i < len(a); i++ {
		sum += a[i]
	}

	if sum-a[n+1] == 2*a[n] {
		// fmt.Printf("I %+v\n", a)
		output()
		return true
	}

	for i := 0; i < n+1; i++ {
		x := a[i]
		if sum-x == 2*a[n+1] {
			a[i], a[n+1] = a[n+1], a[i]
			a[i], a[n] = a[n], a[i]

			// fmt.Printf("II %+v\n", a)
			output()
			return true
		}
	}
	return false
}

func main() {
	defer w.Flush()

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

	for ; tc > 0; tc-- {
		fmt.Fscan(r, &n)
		a = make([]int64, n+2)
		for i := 0; i < n+2; i++ {
			fmt.Fscan(r, &a[i])
		}

		if !solve() {
			fmt.Fprintln(w, INIT)
		}
	}
}

package main

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

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		mp, nums := make(map[int64]int), make([]int64, n + 2)

		var sum int64
		for i, _ := range nums {
			Fscan(in, &nums[i])
			sum += nums[i]
			mp[nums[i]]++
		}

		pos, s := -1, -1
		if sum & 0x1 == 0 {
			for i, val := range nums {
				if val & 0x1 == 0 {
					if (sum - val) / 2 != val || ((sum - val) / 2 == val && mp[val] > 1) {
						if mp[(sum - val) >> 1] != 0 {
							pos = i
							break
						}
					}
				}
			}

		} else {
			for i, val := range nums {
				if val & 0x1 == 1 {
					if (sum - val) / 2 != val || ((sum - val) / 2 == val && mp[val] > 1) {
						if mp[(sum - val) / 2] > 0 {
							pos = i
							break
						}
					}
				}
			}
		}

		if pos == -1 {
			Fprintln(out, -1)
		} else {
			for i, val := range nums {
				if i != pos && val == (sum - nums[pos]) / 2 {
					s = i
				}
			}
			for i, val := range nums {
				if i != s && i != pos {
					Fprint(out, val, " ")
				}
			}
			Fprintln(out)
		}
	}
}

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

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

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

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

package main

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

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

	solve := func() {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int64, n+2)
		for i := 0; i < n+2; i++ {
			fmt.Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
		var sum int64
		sum = 0

		for i := 0; i < n; i++ {
			sum += a[i]
		}

		if sum == a[n] {
			for i := 0; i < n; i++ {
				fmt.Fprint(out, a[i], " ")
			}
			fmt.Fprintln(out)
		} else {
			sum += a[n]
			pos := -1
			for i := 0; i <= n; i++ {
				if sum-a[i] == a[n+1] {
					pos = i
					break
				}
			}
			if pos == -1 {
				fmt.Fprintln(out, -1)
			} else {
				for i := 0; i < n+1; i++ {
					if pos != i {
						fmt.Fprint(out, a[i], " ")
					}
				}
				fmt.Fprintln(out)
			}
		}

	}

	var T int
	fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		fmt.Fscan(in, &n)
		v := []int{}
		freq := map[int]int{}
		var sum int64
		for i := 0; i<n+2 ; i++ {
			var x int
			fmt.Fscan(in, &x)
			v = append(v, x) //*
			freq[x]++
			sum += int64(x)
		}
		sort.Ints(v)
		ok := false
		for i, x := range v {
			rem := sum - int64(x)
			if rem % 2 == 1 {
				continue
			}
			rem /= 2
			need := 1
			if int(rem) == x {
				need++
			}
			if rem <= int64(v[n+1]) && freq[int(rem)] >= need {
				ok = true
				v[i] = -1
				sum = rem
				break
			}
		}
		if !ok {
			fmt.Println(-1)
			continue
		}
		for _, x := range v {
			if x != int(sum) && x!=-1 {
				fmt.Printf("%d ", x)
			}else if x == int(sum) {
				sum = -1
			}
		}
		fmt.Println("")
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, n + 2)
		var sum int64 = 0
		for i := 0; i < n + 2; i++ {
			fmt.Fscan(in, &arr[i])
			sum = sum + int64(arr[i])
		}
		sort.Ints(arr)
		sum -= int64(arr[n + 1])
		var done = false
		for i := 0; i <= n; i++ {
			if sum - int64(arr[i]) == int64(arr[n + 1]) {
				for j := 0; j <= n; j++ {
					if i == j {
						continue
					}
					fmt.Fprint(out, arr[j], " ")
				}
				fmt.Fprintln(out, "")
				done = true
				break
			}
		}
		if done {
			t--
			continue
		}
		if sum - int64(arr[n]) == int64(arr[n]) {
			for i := 0; i < n; i++ {
				fmt.Fprint(out, arr[i], " ")
			}
			fmt.Fprintln(out, "")
			done = true
		}
		if done {
			t--
			continue
		}
		fmt.Fprintln(out, -1)
		t--
	}
	out.Flush()

}

package main

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

/*
1
3
2 3 7 12 2
---

sumB == 2*sumA + x

sumB-x == 2*sumA

sumA = (sunB-x)/2

if sumB-x-sumA == sumA and sumA in b:
	yes
else:
	no

2 2 3 7 12
=======
1
3
0 0 0 0 0
---
0 0 0
*/

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

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

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

		sumB := int64(0)
		b := make([]int64, n+2)
		numToIdx := make(map[int64][]int)

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

			sumB += b[i]
			numToIdx[b[i]] = append(numToIdx[b[i]], i)
		}
		scanf("\n")

		found := false

	outer:
		for i, x := range b {
			if (sumB-x)%2 == 0 {
				sumA := (sumB - x) / 2
				indices := numToIdx[sumA]
				for _, k := range indices {
					if sumB-x-sumA == sumA && k != i {
						for j, num := range b {
							if j != i && j != k {
								fmt.Fprintf(writer, "%d ", num)
							}
						}
						fmt.Fprintln(writer)
						found = true
						break outer
					}
				}
			}
		}

		if !found {
			fmt.Fprintln(writer, -1)
		}
	}
}

const maxUint = ^uint(0)

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

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

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

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

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

//goland:noinspection GoUnusedFunction
func divCeil(num, div int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

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

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

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		ARRAY := make([]int64, n+2)
		for i := 0; i < n+2; i++ {
			fmt.Fscan(input, &ARRAY[i])
		}

		sort.Slice(ARRAY, func(i, j int) bool {
			return ARRAY[i] < ARRAY[j]
		})
		var SUM int64
		for i := 0; i < n; i++ {
			SUM = SUM + ARRAY[i]
		}
		if ARRAY[n] == SUM {
			for i := 0; i < n; i++ {
				fmt.Println(ARRAY[i])
			}
		} else {
			q := SUM + ARRAY[n] - ARRAY[n+1]
			if q <= 0 {
				fmt.Println(-1)
			} else {
				w := -1
				for i := 0; i < n+1; i++ {
					if ARRAY[i] == q {
						w = i
					}
				}
				if w == -1 {
					fmt.Println(-1)
				} else {
					for i := 0; i < n+1; i++ {
						if i != w {
							fmt.Println(ARRAY[i])
						}
					}
				}
			}
		}

	}
}

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) nextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt()
	}
	return res
}
func (s *Scanner) nextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt64()
	}
	return res
}
func min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func solve(N int, arr []int) []int {
	ans := []int{}

	sort.Ints(arr)
	sum := int64(0)
	for i := 0; i < N+2; i++ {
		sum += int64(arr[i])
	}

	for i := 0; i < N+1; i++ {
		sumA := sum - int64(arr[N+1]+arr[i])
		if sumA == int64(arr[N+1]) {
			for j := 0; j < N+1; j++ {
				if j == i {
					continue
				}
				ans = append(ans, arr[j])
			}
			return ans
		}
	}
	sumA := sum - int64(arr[N]+arr[N+1])
	if sumA == int64(arr[N]) {
		for j := 0; j < N; j++ {
			ans = append(ans, arr[j])
		}
		return ans
	}
	return nil
}

func main() {
	sc := NewScanner()
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	TC := sc.nextInt()
	for tc := 0; tc < TC; tc++ {
		N := sc.nextInt()
		arr := sc.nextInts(N + 2)

		ans := solve(N, arr)
		if ans == nil {
			fmt.Fprintln(wr, "-1")
		} else {
			for i := 0; i < N; i++ {
				fmt.Fprint(wr, ans[i], " ")
			}
			fmt.Fprintln(wr)
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"sort"
	"strings"
)

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int64, n+2)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
		sum := int64(0)
		for _, v := range a[:n] {
			sum += v
		}
		if sum == a[n] {
			for _, v := range a[:n] {
				Fprint(out, v, " ")
			}
			Fprintln(out)
			return
		}
		sum += a[n]-a[n+1]
		if sum<=0 {
			Fprintln(out, -1)
			return
		}
		b := a[:n+1]
		for i, v := range b {
			if v == sum {
				b = append(b[:i], b[i+1:]...)
				for _, v := range b {
					Fprint(out, v, " ")
				}
				Fprintln(out)
				return
			}
		}
		Fprintln(out, -1)
	}

	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		high := 0
		shigh := 0
		ps := 0

		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
			if b[i] <= high && b[i] > shigh {
				shigh = b[i]
			} else if b[i] > high {
				shigh = high
				high = b[i]
			}
			ps += b[i]
		}
		// sort.Ints(b)
		if t == 426 {
			fmt.Println(b)
		}
		ps -= (high + shigh)
		if ps == high || ps == shigh {
			skip_high := true
			ship_shigh := true
			for i := 0; i < n+2; i++ {
				if skip_high {
					if b[i] == high {
						skip_high = false
						continue
					}
				}
				if ship_shigh {
					if b[i] == shigh {
						ship_shigh = false
						continue
					}
				}
				write(f, b[i], " ")
			}
			write(f, "\n")
		} else {
			rem := ps - (high - shigh)
			ok := false
			skip := -1
			for i := 0; i < n+2; i++ {
				if b[i] == rem && b[i] != shigh && b[i] != high {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				skip_high := true
				for i := 0; i < n+2; i++ {
					if i == skip || b[i] == high {
						if i == skip {
							continue
						} else if skip_high {
							skip_high = false
							continue
						}
					}
					write(f, b[i], " ")
				}
				write(f, "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		high := 0
		shigh := 0
		ps := 0

		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
			if b[i] <= high && b[i] > shigh {
				shigh = b[i]
			} else if b[i] > high {
				shigh = high
				high = b[i]
			}
			ps += b[i]
		}
		// sort.Ints(b)
		if t == 426 {
			fmt.Println(b)
		}
		ps -= (high + shigh)
		if ps == high || ps == shigh {
			skip_high := true
			ship_shigh := true
			for i := 0; i < n+2; i++ {
				if skip_high {
					if b[i] == high {
						skip_high = false
						continue
					}
				}
				if ship_shigh {
					if b[i] == shigh {
						ship_shigh = false
						continue
					}
				}
				write(f, b[i], " ")
			}
			write(f, "\n")
		} else {
			rem := ps - (high - shigh)
			ok := false
			skip := -1
			for i := 0; i < n+2; i++ {
				if b[i] == rem && b[i] != shigh && b[i] != high {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				for i := 0; i < n+2; i++ {
					if i == skip || b[i] == high {
						continue
					}
					write(f, b[i], " ")
				}
				write(f, "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		high := 0
		shigh := 0
		ps := 0

		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
			if b[i] <= high && b[i] > shigh {
				shigh = b[i]
			} else if b[i] > high {
				shigh = high
				high = b[i]
			}
			ps += b[i]
		}
		// sort.Ints(b)

		ps -= (high + shigh)
		if ps == high || ps == shigh {
			skip_high := true
			ship_shigh := true
			for i := 0; i < n+2; i++ {
				if skip_high {
					if b[i] == high {
						skip_high = false
						continue
					}
				}
				if ship_shigh {
					if b[i] == shigh {
						ship_shigh = false
						continue
					}
				}
				write(f, b[i], " ")
			}
			write(f, "\n")
		} else {
			rem := ps - (high - shigh)
			ok := false
			skip := -1
			for i := 0; i < n+2; i++ {
				if b[i] == rem && b[i] != shigh && b[i] != high {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				for i := 0; i < n+2; i++ {
					if i == skip || b[i] == high {
						continue
					}
					write(f, b[i], " ")
				}
				write(f, "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		high := 0
		shigh := 0
		ps := 0

		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
			if b[i] <= high && b[i] > shigh {
				shigh = b[i]
			} else if b[i] > high {
				shigh = high
				high = b[i]
			}
			ps += b[i]
		}
		// sort.Ints(b)
		if t == 490 {
			fmt.Println(b)
		}
		ps -= (high + shigh)
		if ps == high || ps == shigh {
			skip_high := true
			ship_shigh := true
			for i := 0; i < n+2; i++ {
				if skip_high {
					if b[i] == high {
						skip_high = false
						continue
					}
				}
				if ship_shigh {
					if b[i] == shigh {
						ship_shigh = false
						continue
					}
				}
				write(f, b[i], " ")
			}
			write(f, "\n")
		} else {
			rem := ps - (high - shigh)
			ok := false
			skip := -1
			for i := 0; i < n+2; i++ {
				if b[i] == rem && b[i] != shigh && b[i] != high {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				for i := 0; i < n+2; i++ {
					if i == skip || b[i] == high || b[i] == shigh {
						continue
					}
					write(f, b[i], " ")
				}
				write(f, shigh, "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		high := 0
		shigh := 0
		ps := 0

		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
			if b[i] <= high && b[i] > shigh {
				shigh = b[i]
			} else if b[i] > high {
				shigh = high
				high = b[i]
			}
			ps += b[i]
		}
		// sort.Ints(b)
		ps -= (high + shigh)
		if ps == high || ps == shigh {
			skip_high := true
			ship_shigh := true
			for i := 0; i < n+2; i++ {
				if skip_high {
					if b[i] == high {
						skip_high = false
						continue
					}
				}
				if ship_shigh {
					if b[i] == shigh {
						ship_shigh = false
						continue
					}
				}
				write(f, b[i], " ")
			}
			write(f, "\n")
		} else {
			rem := ps - (high - shigh)
			ok := false
			skip := -1
			for i := 0; i < n+2; i++ {
				if b[i] == rem && b[i] != shigh && b[i] != high {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				for i := 0; i < n+2; i++ {
					if i == skip || b[i] == high || b[i] == shigh {
						continue
					}
					write(f, b[i], " ")
				}
				write(f, shigh, "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		high := 0
		shigh := 0
		ps := 0

		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
			if b[i] <= high && b[i] > shigh {
				shigh = b[i]
			} else if b[i] > high {
				shigh = high
				high = b[i]
			}
			ps += b[i]
		}
		// sort.Ints(b)
		ps -= (high + shigh)
		if ps == high || ps == shigh {
			skip_high := true
			ship_shigh := true
			for i := 0; i < n+2; i++ {
				if skip_high {
					if b[i] == high {
						skip_high = false
						continue
					}
				}
				if ship_shigh {
					if b[i] == shigh {
						ship_shigh = false
						continue
					}
				}
				write(f, b[i], " ")
			}
			write(f, "\n")
		} else {
			rem := ps - (high - shigh)
			ok := false
			skip := -1
			for i := 0; i < n+2; i++ {
				if b[i] == rem {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				for i := 0; i < n+2; i++ {
					if i == skip || b[i] == high || b[i] == shigh {
						continue
					}
					write(f, b[i], " ")
				}
				write(f, shigh, "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		high := 0
		shigh := 0
		ps := 0

		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
			if b[i] <= high && b[i] > shigh {
				shigh = b[i]
			} else if b[i] > high {
				shigh = high
				high = b[i]
			}
			ps += b[i]
		}
		// sort.Ints(b)
		ps -= (high + shigh)
		if ps == high || ps == shigh {
			count := 2
			for i := 0; i < n+2; i++ {
				if (b[i] == high || b[i] == shigh) && count > 0 {
					count--
					continue
				}
				write(f, b[i], " ")
			}
			write(f, "\n")
		} else {
			rem := ps - (high - shigh)
			ok := false
			skip := -1
			for i := 0; i < n+2; i++ {
				if b[i] == rem {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				for i := 0; i < n+2; i++ {
					if i == skip || b[i] == high || b[i] == shigh {
						continue
					}
					write(f, b[i], " ")
				}
				write(f, shigh, "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		high := 0
		shigh := 0
		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
			if b[i] <= high && b[i] > shigh {
				shigh = b[i]
			} else if b[i] > high {
				shigh = high
				high = b[i]
			}
		}
		// sort.Ints(b)
		ps := 0
		for i := 0; i < n+2; i++ {
			if b[i] != high && b[i] != shigh {
				ps += b[i]
			}
		}
		if ps == high || ps == shigh {
			for i := 0; i < n+2; i++ {
				if b[i] == high || b[i] == shigh {
					continue
				}
				write(f, b[i], " ")
			}
			write(f, "\n")
		} else {
			rem := ps - (high - shigh)
			ok := false
			skip := -1
			for i := 0; i < n+2; i++ {
				if b[i] == rem {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				for i := 0; i < n+2; i++ {
					if i == skip || b[i] == high || b[i] == shigh {
						continue
					}
					write(f, b[i], " ")
				}
				write(f, shigh, "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {
		var n int

		fmt.Fscan(r, &n)

		b := make([]int, n + 2)

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

		r, ar := solve(b, n)

		if !r {
			fmt.Println("-1")
		} else {
			for j := 0; j < len(ar); j++ {
				fmt.Print(ar[j])
				fmt.Print(" ")
			}
		}
		fmt.Println()
	}
}

func solve(b []int, n int) (bool, []int) {
	mp := make(map[int][]int)

	var s int64

	for i :=0 ; i < len(b); i++ {
		if len(mp[b[i]]) < 5 {
			mp[b[i]] = append(mp[b[i]], i)
		}

		s += int64(b[i])
	}

	var a []int

	for i := 0; i < len(b); i++ {
		rest := s - int64(b[i])

		if rest % 2 == 1 {
			continue
		}

		r := rest/2

		v, ok := mp[int(r)]

		var idx int = -1

		if ok {

			for k := 0; k < len(v); k++ {
				if v[k] != i {
					idx = v[k]
				}
			}
		}

		if idx == -1 {
			continue
		}

		if ok {
			for j := 0; j < len(b); j++ {
				if j == i || j == idx {
					continue
				}
				a = append(a, b[j])
			}
			return true, a
		}
	}

	return false, []int{}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {
		var n int

		fmt.Fscan(r, &n)

		b := make([]int, n + 2)

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

		r, ar := solve(b, n)

		if !r {
			fmt.Println("-1")
		} else {
			for j := 0; j < len(ar); j++ {
				fmt.Print(ar[j])
				fmt.Print(" ")
			}
		}
		fmt.Println()
	}
}

func solve(b []int, n int) (bool, []int) {
	mp := make(map[int][]int)

	var s int64

	for i :=0 ; i < len(b); i++ {
		if len(mp[b[i]]) < 2 {
			mp[b[i]] = append(mp[b[i]], i)
		}

		s += int64(b[i])
	}

	var a []int

	for i := 0; i < len(b); i++ {
		rest := s - int64(b[i])

		if rest % 2 == 1 {
			continue
		}

		r := rest/2

		v, ok := mp[int(r)]

		var idx int = -1

		if ok {

			for k := 0; k < len(v); k++ {
				if v[k] != i {
					idx = v[k]
				}
			}
		}

		if idx == -1 {
			continue
		}

		if ok {
			for j := 0; j < len(b); j++ {
				if j == i || j == idx {
					continue
				}
				a = append(a, b[j])
			}
			return true, a
		}
	}

	return false, []int{}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {
		var n int

		fmt.Fscan(r, &n)

		b := make([]int, n + 2)

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

		r, ar := solve(b, n)

		if !r {
			fmt.Println("-1")
		} else {
			for j := 0; j < len(ar); j++ {
				fmt.Print(ar[j])
				fmt.Print(" ")
			}
		}
		fmt.Println()
	}
}

func solve(b []int, n int) (bool, []int) {
	mp := make(map[int]int)

	var s int64

	for i :=0 ; i < len(b); i++ {
		mp[b[i]] = i

		s += int64(b[i])
	}

	var a []int

	for i := 0; i < len(b); i++ {
		rest := s - int64(b[i])

		if rest % 2 == 1 {
			continue
		}

		r := rest/2

		v, ok := mp[int(r)]

		if ok {
			if v == i {
				continue
			}
		}

		if ok {
			for j := 0; j < len(b); j++ {
				if j == i || j == v {
					continue
				}
				a = append(a, b[j])
			}
			return true, a
		}
	}

	return false, []int{}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {
		var n int

		fmt.Fscan(r, &n)

		b := make([]int, n + 2)

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

		r, ar := solve(b, n)

		if !r {
			fmt.Println("-1")
		} else {
			for j := 0; j < len(ar); j++ {
				fmt.Print(ar[j])
				fmt.Print(" ")
			}
		}
		fmt.Println()
	}
}

func solve(b []int, n int) (bool, []int) {
	mp := make(map[int]int)

	var s int64

	for i :=0 ; i < len(b); i++ {
		mp[b[i]] = i

		s+= int64(b[i])
	}

	var a []int

	for i := 0; i < len(b); i++ {
		rest := s - int64(b[i])

		if rest % 2 == 1 {
			continue
		}

		r := rest/2

		v, ok := mp[int(r)]

		if ok {
			for j := 0; j < len(b); j++ {
				if j == i || j == v {
					continue
				}
				a = append(a, b[j])
			}
			return true, a
		}
	}

	return false, []int{}
}

// link: https://codeforces.com/problemset/problem/1512/D
// b(n+1) must be biggest or second biggest number

package main

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

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

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

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

		bArr := make([]int, n+2)

		var biggestValIndex int
		var biggestVal int
		var secondBiggestValIndex int
		var secondBiggestVal int
		var sum int
		for j := 0; j < n+2; j++ {
			var val int
			fmt.Fscan(in, &val)

			bArr[j] = val
			sum += val

			if val > biggestVal {
				secondBiggestValIndex = biggestValIndex
				secondBiggestVal = biggestVal

				biggestValIndex = j
				biggestVal = val
			} else if val > secondBiggestVal {
				secondBiggestValIndex = j
				secondBiggestVal = val
			}
		}

		// let b(n+2) = biggestVal, b(n+1) = secondBiggestVal
		if sum-biggestVal-secondBiggestVal == secondBiggestVal {
			for j := 0; j < n+2; j++ {
				if j == biggestValIndex || j == secondBiggestValIndex {
					continue
				}

				fmt.Fprintf(out, "%d ", bArr[j])
			}
			fmt.Fprintln(out)
			continue
		}

		// let b(n+1) = biggestVal
		sumOfAnPlusX := sum - biggestVal
		x := -1

		for j := 0; j < n+2; j++ {
			if j == biggestValIndex {
				continue
			}

			if sumOfAnPlusX-bArr[j] == biggestVal {
				x = j
				break
			}
		}

		if x == -1 {
			fmt.Fprintln(out, "-1")
		} else {
			for j := 0; j < n+2; j++ {
				if j == biggestValIndex || j == x {
					continue
				}

				fmt.Fprintf(out, "%d ", bArr[j])
			}
			fmt.Fprintln(out)
		}
	}
}

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

package main

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

func check(b bool) {
	if !b {
		_, _, line, _ := runtime.Caller(1)
		fmt.Printf("check failed line %d\n", line)
		os.Exit(-1)
	}
}

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

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

func lowerBound(arr []int, t int) int {
	lo := 0
	hi := len(arr)
	for lo < hi {
		mid := lo + (hi-lo)/2
		if arr[mid] >= t {
			hi = mid
		} else {
			lo = mid + 1
		}
	}
	return hi
}

const (
	INIT = -1
	INF  = int(1e9)
)

var (
	r      = bufio.NewReader(os.Stdin)
	w      = bufio.NewWriter(os.Stdout)
	exists = struct{}{} // for use with map[...]struct{}

	n int
	a []int64
)

func solve() bool {
	var sum int64
	has := make(map[int64]int)
	for i := 0; i < n+2; i++ {
		sum += a[i]
		has[a[i]] = i
	}
	// fmt.Printf("has %+v\n", has)

	for i := 0; i < n+2; i++ {
		x := a[i]
		total := sum - x
		if (total % 2) != 0 {
			continue
		}
		half := total / 2

		if j, ok := has[half]; ok {
			if j == i {
				continue
			}

			a[j], a[n] = a[n], a[j]
			a[i], a[n+1] = a[n+1], a[i]

			for i := 0; i < n; i++ {
				fmt.Fprintf(w, "%d ", a[i])
			}
			fmt.Fprintln(w)
			return true
		}
	}

	return false
}

func main() {
	defer w.Flush()

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

	for ; tc > 0; tc-- {
		fmt.Fscan(r, &n)
		a = make([]int64, n+2)
		for i := 0; i < n+2; i++ {
			fmt.Fscan(r, &a[i])
		}

		if !solve() {
			fmt.Fprintln(w, INIT)
		}
	}
}

package main

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

func check(b bool) {
	if !b {
		_, _, line, _ := runtime.Caller(1)
		fmt.Printf("check failed line %d\n", line)
		os.Exit(-1)
	}
}

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

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

func lowerBound(arr []int, t int) int {
	lo := 0
	hi := len(arr)
	for lo < hi {
		mid := lo + (hi-lo)/2
		if arr[mid] >= t {
			hi = mid
		} else {
			lo = mid + 1
		}
	}
	return hi
}

const (
	INIT = -1
	INF  = int(1e9)
)

var (
	r      = bufio.NewReader(os.Stdin)
	w      = bufio.NewWriter(os.Stdout)
	exists = struct{}{} // for use with map[...]struct{}

	n int
	a []int64
)

func solve() bool {
	var sum int64
	has := make(map[int64][]int)
	for i := 0; i < n+2; i++ {
		sum += a[i]
		has[a[i]] = append(has[a[i]], i)
	}
	// fmt.Printf("has %+v\n", has)

	for i := 0; i < n+2; i++ {
		x := a[i]
		total := sum - x
		if (total % 2) != 0 {
			continue
		}
		half := total / 2

		if _, ok := has[half]; !ok {
			continue
		}

		for _, j := range has[half] {
			if j == i {
				continue
			}
			a[j], a[n] = a[n], a[j]
			a[i], a[n+1] = a[n+1], a[i]

			for i := 0; i < n; i++ {
				fmt.Fprintf(w, "%d ", a[i])
			}
			fmt.Fprintln(w)
			return true
		}
	}

	return false
}

func main() {
	defer w.Flush()

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

	for ; tc > 0; tc-- {
		fmt.Fscan(r, &n)
		a = make([]int64, n+2)
		for i := 0; i < n+2; i++ {
			fmt.Fscan(r, &a[i])
		}

		if !solve() {
			fmt.Fprintln(w, INIT)
		}
	}
}

package main

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

func check(b bool) {
	if !b {
		_, _, line, _ := runtime.Caller(1)
		fmt.Printf("check failed line %d\n", line)
		os.Exit(-1)
	}
}

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

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

func lowerBound(arr []int, t int) int {
	lo := 0
	hi := len(arr)
	for lo < hi {
		mid := lo + (hi-lo)/2
		if arr[mid] >= t {
			hi = mid
		} else {
			lo = mid + 1
		}
	}
	return hi
}

const (
	INIT = -1
	INF  = int(1e9)
)

var (
	r      = bufio.NewReader(os.Stdin)
	w      = bufio.NewWriter(os.Stdout)
	exists = struct{}{} // for use with map[...]struct{}

	n int
	a []int64
)

func solve() bool {
	var sum int64
	has := make(map[int64]int)
	for i := 0; i < n+2; i++ {
		sum += a[i]
		has[a[i]] = i
	}

	for i := 0; i < n+2; i++ {
		x := a[i]
		total := sum - x
		if (total % 2) != 0 {
			continue
		}
		half := total / 2

		if pos, ok := has[half]; ok {
			a[pos], a[n] = a[n], a[pos]
			a[i], a[n+1] = a[n+1], a[i]

			for i := 0; i < n; i++ {
				fmt.Fprintf(w, "%d ", a[i])
			}
			fmt.Fprintln(w)
			return true
		}
	}

	return false
}

func main() {
	defer w.Flush()

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

	for ; tc > 0; tc-- {
		fmt.Fscan(r, &n)
		a = make([]int64, n+2)
		for i := 0; i < n+2; i++ {
			fmt.Fscan(r, &a[i])
		}

		if !solve() {
			fmt.Fprintln(w, INIT)
		}
	}
}

package main

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

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		mp, nums := make(map[int64]int), make([]int64, n + 2)

		var sum int64
		for i, _ := range nums {
			Fscan(in, &nums[i])
			sum += nums[i]
			mp[nums[i]]++
		}

		pos := -1
		if sum & 0x1 == 0 {
			for i, val := range nums {
				if val & 0x1 == 0 {
					if (sum - val) / 2 != val || ((sum - val) / 2 == val && mp[val] > 1) {
						if mp[(sum - val) >> 1] != 0 {
							pos = i
							break
						}
					}
				}
			}

		} else {
			for i, val := range nums {
				if val & 0x1 == 1 {
					if (sum - val) / 2 != val || ((sum - val) / 2 == val && mp[val] > 1) {
						if mp[(sum - val) / 2] > 0 {
							pos = i
							break
						}
					}
				}
			}
		}

		if pos == -1 {
			Fprintln(out, -1)
		} else {
			cnt := 0
			for i, val := range nums {
				if (val != (sum - nums[pos]) / 2 || cnt != 0) && i != pos {
					Fprint(out, val, " ")
				}
				if val == (sum - nums[pos]) / 2 {
					cnt++
				}
			}
			Fprintln(out)
		}
	}
}

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

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

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

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

package main

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

	//"math"
	"os"
)

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		nums := make([]int, n + 3)

		for i, _ := range nums {
			if i == 0 {
				continue
			}
			Fscan(in, &nums[i])
		}

		sort.Ints(nums)
		for i, _ := range nums {
			if i == 0 {
				continue
			}
			nums[i] += nums[i-1]
		}

		if nums[n + 1] == 2 * nums[n] {
			for i := 1; i < n+1; i++ {
				Fprint(out, nums[i] - nums[i - 1], " ")
			}

		} else {
			var pos int
			target := nums[n + 2] - nums[n + 1]
			for pos = 1; pos < n + 2; pos++ {
				if target == nums[n + 1] - nums[pos] + nums[pos - 1] {
					break
				}
			}
			if pos == n + 2 {
				Fprint(out, -1)
			} else {
				for i := 1; i < pos; i++ {
					Fprint(out, nums[i] - nums[i - 1], " ")
				}
				for i := pos + 1; i < n + 2; i++ {
					Fprint(out, nums[i] - nums[i - 1], " ")
				}
			}
		}
		Fprintln(out)
	}
}

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

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

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

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

package main

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

	//"math"
	"os"
)

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		nums := make([]int, n + 3)

		for i, _ := range nums {
			if i == 0 {
				continue
			}
			Fscan(in, &nums[i])
		}

		sort.Ints(nums)
		for i, _ := range nums {
			if i == 0 {
				continue
			}
			nums[i] += nums[i-1]
		}

		if nums[n + 1] == 2 * nums[n] {
			for i := 1; i < n+1; i++ {
				Fprint(out, nums[i] - nums[i - 1], " ")
			}

		} else {
			var pos int
			target := nums[n + 2] - nums[n + 1]
			for pos = 1; pos < n + 3; pos++ {
				if target == nums[n + 1] - nums[pos] + nums[pos - 1] {
					break
				}
			}
			if pos == n + 3 {
				Fprint(out, -1)
			} else {
				for i := 1; i < pos; i++ {
					Fprint(out, nums[i] - nums[i - 1], " ")
				}
				for i := pos + 1; i < n + 2; i++ {
					Fprint(out, nums[i] - nums[i - 1], " ")
				}
			}
		}
		Fprintln(out)
	}
}

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

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

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

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

package main

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

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

	solve := func() {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int64, n+2)
		for i := 0; i < n+2; i++ {
			fmt.Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
		var sum int64
		sum = 0

		for i := 0; i < n; i++ {
			sum += a[i]
		}

		if sum == a[n] {
			for i := 0; i < n; i++ {
				fmt.Fprint(out, a[i], " ")
			}
			fmt.Fprintln(out)
		} else {
			sum += a[n]
			pos := -1
			for i := 0; i < n; i++ {
				if sum-a[i] == a[n+1] {
					pos = i
					break
				}
			}
			if pos == -1 {
				fmt.Fprintln(out, -1)
			} else {
				for i := 0; i < n+1; i++ {
					if pos != i {
						fmt.Fprint(out, a[i], " ")
					}

				}
				fmt.Fprintln(out)
			}
		}

	}

	var T int
	fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		fmt.Fscan(in, &n)
		v := []int{}
		freq := map[int]int{}
		var sum int64
		for i := 0; i<n+2 ; i++ {
			var x int
			fmt.Fscan(in, &x)
			v = append(v, x) //*
			freq[x]++
			sum += int64(x)
		}
		sort.Ints(v)
		ok := false
		for i, x := range v {
			rem := sum - int64(x)
			if rem % 2 == 1 {
				continue
			}
			rem /= 2
			need := 1
			if int(rem) == x {
				need++
			}
			if rem <= int64(v[n+1]) && freq[int(rem)] >= need {
				ok = true
				v[i] = -1
				sum = rem
				break
			}
		}
		if !ok {
			fmt.Println(-1)
			continue
		}
		for _, x := range v {
			if x != int(sum) && x!=-1{
				fmt.Printf("%d ", x)
			}
		}
		fmt.Println("")
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, n + 2)
		var sum int64 = 0
		for i := 0; i < n + 2; i++ {
			fmt.Fscan(in, &arr[i])
			sum = sum + int64(arr[i])
		}
		sort.Ints(arr)
		sum -= int64(arr[n + 1])
		var done = false
		for i := 0; i <= n; i++ {
			if sum - int64(arr[i]) == int64(arr[n + 1]) {
				for j := 0; j <= n; j++ {
					if i == j {
						continue
					}
					fmt.Fprint(out, arr[j], " ")
				}
				fmt.Fprintln(out, "")
				done = true
				break
			}
		}
		if done {
			t--
			continue
		}
		sum += int64(arr[n + 1])
		if sum - int64(arr[n]) == int64(arr[n]) {
			for i := 0; i < n; i++ {
				fmt.Fprint(out, arr[i], " ")
			}
			fmt.Fprintln(out, "")
			done = true
		}
		if done {
			t--
			continue
		}
		fmt.Fprintln(out, -1)
		t--
	}
	out.Flush()

}


Diana loves playing with numbers. She's got $$$n$$$ cards with positive integer numbers $$$a_i$$$ written on them. She spends her free time multiplying the numbers on the cards. She picks a non-empty subset of the cards and multiplies all the numbers $$$a_i$$$ written on them.Diana is happy when the product of the numbers ends with her favorite digit $$$d$$$. Now she is curious what cards she should pick so that the product of the numbers on them is the largest possible and the last decimal digit of the product is $$$d$$$. Please, help her.

The first line contains the integers $$$n$$$ and $$$d$$$ ($$$1\le n\le 10^5$$$, $$$0\le d\le 9$$$). The second line contains $$$n$$$ integers $$$a_i$$$ ($$$1\le a_i\le 1000$$$).

On the first line, print the number of chosen cards $$$k$$$ ($$$1\le k\le n$$$). On the next line, print the numbers written on the chosen cards in any order.  If it is impossible to choose a subset of cards with the product that ends with the digit $$$d$$$, print the single line with $$$-1$$$.

NoteIn the first example, $$$1 \times 2 \times 4 \times 11 \times 13 = 1144$$$, which is the largest product that ends with the digit 4. The same set of cards without the number 1 is also a valid answer, as well as a set of 8, 11, and 13 with or without 1 that also has the product of 1144.In the second example, all the numbers on the cards are even and their product cannot end with an odd digit 1.In the third example, the only possible products are 1, 3, 5, 9, 15, and 45, none of which end with the digit 7.In the fourth example, $$$9 \times 11 \times 17 = 1683$$$, which ends with the digit 3. In the fifth example, $$$2 \times 2 \times 2 \times 2 = 16$$$, which ends with the digit 6.

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct {
		i, j int
		use  bool
	}

	var n, d, v int
	Fscan(in, &n, &d)
	a := []int{}
	for i := 0; i < n; i++ {
		if Fscan(in, &v); v > 1 {
			a = append(a, v)
		}
	}
	n = len(a)
	if n == 0 {
		if d == 1 {
			Fprintln(out, 1)
			Fprintln(out, 1)
		} else {
			Fprintln(out, -1)
		}
		return
	}
	dp := make([][10]float64, n)
	for i := range dp[0] {
		dp[0][i] = -1
	}
	fa := make([][10]pair, n)
	for i := range a {
		v := a[i]
		lg := math.Log(float64(v))
		v %= 10
		if i == 0 {
			dp[i][v] = lg
			fa[i][v] = pair{i, v, true}
			continue
		}
		dp[i] = dp[i-1]
		if dp[i][v] < 0 || lg > dp[i][v] {
			dp[i][v] = lg
			fa[i][v] = pair{i, v, true}
		}
		for j, dv := range dp[i-1] {
			if dv < 0 {
				continue
			}
			res := j * v % 10
			if dv+lg > dp[i][res] {
				dp[i][res] = dv + lg
				fa[i][res] = pair{i - 1, j, true}
			}
		}
	}
	path := []int{}
	i, j := n-1, d
	for {
		f := fa[i][j]
		if !f.use {
			if i == 0 {
				Fprint(out, -1)
				return
			}
			i--
			continue
		}
		path = append(path, a[i])
		if f.i == i {
			break
		}
		i, j = f.i, f.j
	}
	Fprintln(out, len(path))
	for _, v := range path {
		Fprint(out, v, " ")
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct {
		i, j int
		use  bool
	}

	var n, d, v int
	Fscan(in, &n, &d)
	a := []int{}
	for i := 0; i < n; i++ {
		if Fscan(in, &v); v > 1 {
			a = append(a, v)
		}
	}
	n = len(a)
	if n == 0 {
		if d == 1 {
			Fprintln(out, 1)
			Fprintln(out, 1)
		} else {
			Fprintln(out, -1)
		}
		return
	}
	dp := make([][10]float64, n)
	for i := range dp[0] {
		dp[0][i] = -1
	}
	fa := make([][10]pair, n)
	for i := range a {
		Fscan(in, &a[i])
		v := a[i]
		lg := math.Log(float64(v))
		v %= 10
		if i == 0 {
			dp[i][v] = lg
			fa[i][v] = pair{i, v, true}
			continue
		}
		dp[i] = dp[i-1]
		if dp[i][v] < 0 {
			dp[i][v] = lg
			fa[i][v] = pair{i, v, true}
		}
		for j, dv := range dp[i-1] {
			if dv < 0 {
				continue
			}
			res := j * v % 10
			if dv+lg > dp[i][res]+1e-8 {
				dp[i][res] = dv + lg
				fa[i][res] = pair{i - 1, j, true}
			}
		}
	}
	path := []int{}
	i, j := n-1, d
	for {
		f := fa[i][j]
		if !f.use {
			if i == 0 {
				Fprint(out, -1)
				return
			}
			i--
			continue
		}
		path = append(path, a[i])
		if f.i == i {
			break
		}
		i, j = f.i, f.j
	}
	Fprintln(out, len(path))
	for _, v := range path {
		Fprint(out, v, " ")
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct {
		i, j int
		use  bool
	}

	var n, d, v int
	Fscan(in, &n, &d)
	a := []int{}
	for i := 0; i < n; i++ {
		if Fscan(in, &v); v > 1 {
			a = append(a, v)
		}
	}
	n = len(a)
	if n == 0 {
		if d == 1 {
			Fprintln(out, 1)
			Fprintln(out, 1)
		} else {
			Fprintln(out, -1)
		}
		return
	}
	dp := make([][10]float64, n)
	for i := range dp[0] {
		dp[0][i] = -1
	}
	fa := make([][10]pair, n)
	for i := range a {
		Fscan(in, &a[i])
		v := a[i]
		lg := math.Log(float64(v))
		v %= 10
		if i == 0 {
			dp[i][v] = lg
			fa[i][v] = pair{i, v, true}
			continue
		}
		dp[i] = dp[i-1]
		if dp[i][v] < 0 {
			dp[i][v] = lg
			fa[i][v] = pair{i, v, true}
		}
		for j, dv := range dp[i-1] {
			if dv < 0 {
				continue
			}
			res := j * v % 10
			if dv+lg > dp[i][res] {
				dp[i][res] = dv + lg
				fa[i][res] = pair{i - 1, j, true}
			}
		}
	}
	path := []int{}
	i, j := n-1, d
	for {
		f := fa[i][j]
		if !f.use {
			if i == 0 {
				Fprint(out, -1)
				return
			}
			i--
			continue
		}
		path = append(path, a[i])
		if f.i == i {
			break
		}
		i, j = f.i, f.j
	}
	Fprintln(out, len(path))
	for _, v := range path {
		Fprint(out, v, " ")
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct {
		i, j int
		use  bool
	}

	var n, d int
	Fscan(in, &n, &d)
	a := make([]int, n)
	dp := make([][10]float64, n)
	for _i := range dp[0] {
		dp[0][_i] = -1
	}
	fa := make([][10]pair, n)
	for i := range a {
		Fscan(in, &a[i])
		v := a[i]
		lg := math.Log(float64(v))
		v %= 10
		if i == 0 {
			dp[i][v] = lg
			fa[i][v] = pair{i, v, true}
			continue
		}
		dp[i] = dp[i-1]
		if dp[i][v] < 0 {
			dp[i][v] = lg
			fa[i][v] = pair{i, v, true}
		}
		for j, dv := range dp[i-1] {
			if dv < 0 {
				continue
			}
			res := j * v % 10
			if dv+lg > dp[i][res] {
				dp[i][res] = dv + lg
				fa[i][res] = pair{i - 1, j, true}
			}
		}
	}
	path := []int{}
	i,j := n-1,d
	for {
		f := fa[i][j]
		if !f.use {
			if i == 0 {
				Fprint(out, -1)
				return
			}
			i--
			continue
		}
		path = append(path, a[i])
		if f.i == i {
			break
		}
		i,j = f.i,f.j
	}
	Fprintln(out, len(path))
	for _, v := range path {
		Fprint(out, v, " ")
	}
}

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


There is a river of width $$$n$$$. The left bank of the river is cell $$$0$$$ and the right bank is cell $$$n + 1$$$ (more formally, the river can be represented as a sequence of $$$n + 2$$$ cells numbered from $$$0$$$ to $$$n + 1$$$). There are also $$$m$$$ wooden platforms on a river, the $$$i$$$-th platform has length $$$c_i$$$ (so the $$$i$$$-th platform takes $$$c_i$$$ consecutive cells of the river). It is guaranteed that the sum of lengths of platforms does not exceed $$$n$$$.You are standing at $$$0$$$ and want to reach $$$n+1$$$ somehow. If you are standing at the position $$$x$$$, you can jump to any position in the range $$$[x + 1; x + d]$$$. However you don't really like the water so you can jump only to such cells that belong to some wooden platform. For example, if $$$d=1$$$, you can jump only to the next position (if it belongs to the wooden platform). You can assume that cells $$$0$$$ and $$$n+1$$$ belong to wooden platforms.You want to know if it is possible to reach $$$n+1$$$ from $$$0$$$ if you can move any platform to the left or to the right arbitrary number of times (possibly, zero) as long as they do not intersect each other (but two platforms can touch each other). It also means that you cannot change the relative order of platforms.Note that you should move platforms until you start jumping (in other words, you first move the platforms and then start jumping).For example, if $$$n=7$$$, $$$m=3$$$, $$$d=2$$$ and $$$c = [1, 2, 1]$$$, then one of the ways to reach $$$8$$$ from $$$0$$$ is follow:    The first example: $$$n=7$$$.

The first line of the input contains three integers $$$n$$$, $$$m$$$ and $$$d$$$ ($$$1 \le n, m, d \le 1000, m \le n$$$) — the width of the river, the number of platforms and the maximum distance of your jump, correspondingly. The second line of the input contains $$$m$$$ integers $$$c_1, c_2, \dots, c_m$$$ ($$$1 \le c_i \le n, \sum\limits_{i=1}^{m} c_i \le n$$$), where $$$c_i$$$ is the length of the $$$i$$$-th platform.

If it is impossible to reach $$$n+1$$$ from $$$0$$$, print NO in the first line. Otherwise, print YES in the first line and the array $$$a$$$ of length $$$n$$$ in the second line — the sequence of river cells (excluding cell $$$0$$$ and cell $$$n + 1$$$). If the cell $$$i$$$ does not belong to any platform, $$$a_i$$$ should be $$$0$$$. Otherwise, it should be equal to the index of the platform ($$$1$$$-indexed, platforms are numbered from $$$1$$$ to $$$m$$$ in order of input) to which the cell $$$i$$$ belongs. Note that all $$$a_i$$$ equal to $$$1$$$ should form a contiguous subsegment of the array $$$a$$$ of length $$$c_1$$$, all $$$a_i$$$ equal to $$$2$$$ should form a contiguous subsegment of the array $$$a$$$ of length $$$c_2$$$, ..., all $$$a_i$$$ equal to $$$m$$$ should form a contiguous subsegment of the array $$$a$$$ of length $$$c_m$$$. The leftmost position of $$$2$$$ in $$$a$$$ should be greater than the rightmost position of $$$1$$$, the leftmost position of $$$3$$$ in $$$a$$$ should be greater than the rightmost position of $$$2$$$, ..., the leftmost position of $$$m$$$ in $$$a$$$ should be greater than the rightmost position of $$$m-1$$$. See example outputs for better understanding.

NoteConsider the first example: the answer is $$$[0, 1, 0, 2, 2, 0, 3]$$$. The sequence of jumps you perform is $$$0 \rightarrow 2 \rightarrow 4 \rightarrow 5 \rightarrow 7 \rightarrow 8$$$.Consider the second example: it does not matter how to place the platform because you always can jump from $$$0$$$ to $$$11$$$.Consider the third example: the answer is $$$[0, 0, 0, 0, 1, 1, 0, 0, 0, 0]$$$. The sequence of jumps you perform is $$$0 \rightarrow 5 \rightarrow 6 \rightarrow 11$$$.

package main

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

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

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

func Dprint(format string, a ...interface{}) {
	if Debug {
		fmt.Fprintf(os.Stderr, format+"\n", a...)
	}
}

var (
	n, m, d int
	c       []int
)

func main() {
	defer writer.Flush()
	Scanf("%d %d %d\n", &n, &m, &d)

	c = make([]int, m)
	for i := 0; i < m; i++ {
		Scanf("%d ", &c[i])
	}

	// Calculate sum array.
	cs := make([]int, m)
	cs[m-1] = c[m-1]
	for i := m - 2; i >= 0; i-- {
		cs[i] = c[i] + cs[i+1]
	}

	if cs[0] > n {
		// The platforms don't fit into the river.
		Printf("NO\n")
		return
	}

	cPos := -1 // Current position of a person, 0 means first river block.
	pIdx := make([]int, m)
	// Iterate over all platforms...
	for i := 0; i < m; i++ {
		// Jump as far as possible and place the next wooden platform there.
		pPos := cPos + d
		if cs[i] > n-pPos {
			// We can't put next platform at pPos, because the other platforms would not fit in the river.
			// Let's place the next platform as far as possible.
			pPos = n - cs[i]
		}
		pIdx[i] = pPos
		// Let's move along the wooden platform, at the end.
		cPos = pPos + c[i] - 1
	}

	if cPos+d < n {
		Printf("NO\n")
		return
	}

	Printf("YES\n")
	cPos = 0
	for i := 0; i < m; i++ {
		for ; cPos < pIdx[i]; cPos++ {
			Printf("0 ")
		}
		for ; cPos < pIdx[i]+c[i]; cPos++ {
			Printf("%d ", i+1)
		}
	}
	for ; cPos < n; cPos++ {
		Printf("0 ")
	}
}

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])
		// 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 n, m, d int
var C []int

func main() {
	n, m, d = ReadInt3()
	C = ReadIntSlice(m)

	csum := Sum(C...)

	// need := (n + 1 + (d - 1)) / d
	// need--

	// if csum >= need {
	// 	fmt.Println("YES")
	// } else {
	// 	fmt.Println("NO")
	// }

	zeroNum := n - csum
	avg := (zeroNum + ((m + 1) - 1)) / (m + 1)

	id := 1
	if avg <= (d - 1) {
		fmt.Println("YES")
		answers := []int{}
		for i := 0; i < m; i++ {
			// 0を埋める
			for j := 0; j < d-1; j++ {
				if zeroNum == 0 {
					break
				}
				answers = append(answers, 0)
				zeroNum--
			}

			// C[i]個埋める
			for j := 0; j < C[i]; j++ {
				answers = append(answers, id)
			}

			id++
		}
		for zeroNum > 0 {
			answers = append(answers, 0)
			zeroNum--
		}
		fmt.Println(PrintIntsLine(answers...))
	} else {
		fmt.Println("NO")
	}
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

/************************************/
/* Date		: 2019-11-06 14:35:59	*/
/* Author	: MiohitoKiri5474		*/
/* Email	: lltzpp@gmail.com		*/
/************************************/

package main

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

type pii struct{
	F int
	S int
}

const maxN = 1005

var ans, len [maxN]int
var data [maxN] pii

func main() {
	input := bufio.NewReader ( os.Stdin )
	var n, m, d, in, dis, swp, flag int
	sum := 0
	idx := 0
	fmt.Fscan ( input, &n, &m, &d )
	for i := 1 ; i <= m ; i++ {
		fmt.Fscan ( input, &in )
		data[idx] = pii { in, i }
		sum += in
		idx++
	}

	if sum + d > n {
		fmt.Println ( "Yes" )
		for i := 0 ; i < m ; i++ {
			for data[i].F > 0 {
				fmt.Printf ( "%d ", data[i].S )
				data[i].F--
			}
		}

		n -= sum
		for n > 0 {
			n--
			fmt.Printf ( "0 " )
		}
		fmt.Println()
		return;
	}

	if ( n - sum > ( d - 1 ) * ( m + 1 ) ){
		fmt.Println ( "No" )
		return;
	}

	fmt.Println ( "Yes" )
	if n - sum <= m - 1 {
		i := 0
		for idx = 0 ; i < d ; i++ {
			d = n - sum
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				ans[idx] = data[i].S
				idx++
			}
			idx++
		}

		for ; i < m ; i++ {
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				ans[idx] = data[i].S
				idx++
			}
		}
	} else {
		if n - sum == m {
			flag = 0
			dis = 1
		} else {
			flag = 1
			dis = ( n - sum ) / ( m + 1 )
		}

		var i int
		swp = ( n - sum ) / dis
		for i = 0 ; i < swp ; i++ {
			len[i] = dis;
		}

		swp = n - sum - dis * ( m + flag )

		for i := 0 ; i < swp ; i++ {
			len[i]++
		}

		idx = 0
		for i = 0 ; i < m ; i++ {
			idx += len[i]
			for cnt := 0 ; cnt < data[i].F ; cnt++{
				ans[idx] = data[i].S
				idx++
			}
		}
	}

	for i := 0 ; i < n ; i++ {
		fmt.Printf ( "%d ", ans[i] )
	}

	fmt.Println()
}

// Author: sighduck
// URL: https://codeforces.com/contest/1256/problem/C

package main

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

type Platform struct {
	Start  int
	Length int
}

type Solution struct {
	Exists bool
	Answer []int
}

func end(p Platform) int {
	return p.Start + p.Length - 1
}

func canReach(p Platform, q Platform, d int) bool {
	return end(p)+d >= q.Start
}

func getPlatforms(c []int, n int) []Platform {
	platforms := []Platform{}
	for i, ci := range c {
		if i == 0 {
			platforms = append(platforms, Platform{1, ci})
		} else {
			prevPlatform := platforms[len(platforms)-1]
			platforms = append(platforms, Platform{prevPlatform.Start + prevPlatform.Length, ci})
		}
	}
	platforms = append(platforms, Platform{n + 1, 1})
	platforms = append([]Platform{{0, 1}}, platforms...)
	return platforms
}

func formatPlatforms(p []Platform, n int, m int) []int {
	answer := make([]int, n)
	for i := 1; i <= m; i++ {
		for j := p[i].Start; j <= end(p[i]); j++ {
			answer[j-1] = i
		}
	}
	return answer
}

func Solve(n int, m int, d int, c []int) Solution {
	platforms := getPlatforms(c, n)
	for i := m; i >= 1; i-- {
		if canReach(platforms[i], platforms[i+1], d) {
			return Solution{Exists: true, Answer: formatPlatforms(platforms, n, m)}
		}
		platforms[i].Start = platforms[i+1].Start - platforms[i].Length - d + 1
	}
	if d >= platforms[1].Start {
		return Solution{Exists: true, Answer: formatPlatforms(platforms, n, m)}
	}
	return Solution{Exists: false}
}

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

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

	solution := Solve(n, m, d, c)
	if !solution.Exists {
		fmt.Fprintf(writer, "NO\n")
	} else {
		fmt.Fprintf(writer, "YES\n")
		for _, elem := range solution.Answer {
			fmt.Fprintf(writer, "%d ", elem)
		}
		fmt.Fprintf(writer, "\n")
	}
}

/************************************/
/* Date		: 2019-11-06 14:35:59	*/
/* Author	: MiohitoKiri5474		*/
/* Email	: lltzpp@gmail.com		*/
/************************************/

package main

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

type pii struct{
	F int
	S int
}

const maxN = 1005

var ans, len [maxN]int
var data [maxN] pii

func main() {
	input := bufio.NewReader ( os.Stdin )
	var n, m, d, in, dis, swp, flag int
	sum := 0
	idx := 0
	fmt.Fscan ( input, &n, &m, &d )
	for i := 1 ; i <= m ; i++ {
		fmt.Fscan ( input, &in )
		data[idx] = pii { in, i }
		sum += in
		idx++
	}

	if sum + d > n {
		fmt.Println ( "Yes" )
		for i := 0 ; i < m ; i++ {
			for data[i].F > 0 {
				fmt.Printf ( "%d ", data[i].S )
				data[i].F--
			}
		}

		n -= sum
		for n > 0 {
			n--
			fmt.Printf ( "0 " )
		}
		fmt.Println()
		return;
	}

	div := float32 ( ( n - sum ) * 1 / ( m + 1 ) * 1 )

	if ( div > float32 ( d - 1 ) ){
		fmt.Println ( "No" )
		return;
	}

	fmt.Println ( "Yes" )
	if n - sum <= m - 1 {
		i := 0
		for idx = 0 ; i < d ; i++ {
			d = n - sum
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				ans[idx] = data[i].S
				idx++
			}
			idx++
		}

		for ; i < m ; i++ {
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				ans[idx] = data[i].S
				idx++
			}
		}
	} else {
		if n - sum == m {
			flag = 0
			dis = 1
		} else {
			flag = 1
			dis = ( n - sum ) / ( m + 1 )
		}

		var i int
		swp = ( n - sum ) / dis
		for i = 0 ; i < swp ; i++ {
			len[i] = dis;
		}

		swp = n - sum - dis * ( m + flag )

		for i := 0 ; i < swp ; i++ {
			len[i]++
		}

		idx = 0
		for i = 0 ; i < m ; i++ {
			idx += len[i]
			for cnt := 0 ; cnt < data[i].F ; cnt++{
				ans[idx] = data[i].S
				idx++
			}
		}
	}

	for i := 0 ; i < n ; i++ {
		fmt.Printf ( "%d ", ans[i] )
	}

	fmt.Println()
}

/************************************/
/* Date		: 2019-11-06 14:35:59	*/
/* Author	: MiohitoKiri5474		*/
/* Email	: lltzpp@gmail.com		*/
/************************************/

package main

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

type pii struct{
	F int
	S int
}

const maxN = 1005

var ans, len [maxN]int
var data [maxN] pii

func main() {
	input := bufio.NewReader ( os.Stdin )
	var n, m, d, in, dis, swp, flag int
	sum := 0
	idx := 0
	fmt.Fscan ( input, &n, &m, &d )
	for i := 1 ; i <= m ; i++ {
		fmt.Fscan ( input, &in )
		data[idx] = pii { in, i }
		sum += in
		idx++
	}

	if sum + d > n {
		fmt.Println ( "Yes" )
		for i := 0 ; i < m ; i++ {
			for data[i].F > 0 {
				fmt.Printf ( "%d ", data[i].S )
				data[i].F--
			}
		}

		n -= sum
		for n > 0 {
			n--
			fmt.Printf ( "0 " )
		}
		fmt.Println()
		return;
	}

	div := ( n - sum ) * 1 / ( m + 1 ) * 1

	if ( div > d - 1 ){
		fmt.Println ( "No" )
		return;
	}

	fmt.Println ( "Yes" )
	if n - sum <= m - 1 {
		i := 0
		for idx = 0 ; i < d ; i++ {
			d = n - sum
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				ans[idx] = data[i].S
				idx++
			}
			idx++
		}

		for ; i < m ; i++ {
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				ans[idx] = data[i].S
				idx++
			}
		}
	} else {
		if n - sum == m {
			flag = 0
			dis = 1
		} else {
			flag = 1
			dis = ( n - sum ) / ( m + 1 )
		}

		var i int
		swp = ( n - sum ) / dis
		for i = 0 ; i < swp ; i++ {
			len[i] = dis;
		}

		swp = n - sum - dis * ( m + flag )

		for i := 0 ; i < swp ; i++ {
			len[i]++
		}

		idx = 0
		for i = 0 ; i < m ; i++ {
			idx += len[i]
			for cnt := 0 ; cnt < data[i].F ; cnt++{
				ans[idx] = data[i].S
				idx++
			}
		}
	}

	for i := 0 ; i < n ; i++ {
		fmt.Printf ( "%d ", ans[i] )
	}

	fmt.Println()
}

/************************************/
/* Date		: 2019-11-06 14:35:59	*/
/* Author	: MiohitoKiri5474		*/
/* Email	: lltzpp@gmail.com		*/
/************************************/

package main

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

type pii struct{
	F int
	S int
}

const maxN = 1005

var ans, len [maxN]int
var data [maxN] pii

func main() {
	input := bufio.NewReader ( os.Stdin )
	var n, m, d, in, dis, swp, flag int
	sum := 0
	idx := 0
	fmt.Fscan ( input, &n, &m, &d )
	for i := 1 ; i <= m ; i++ {
		fmt.Fscan ( input, &in )
		data[idx] = pii { in, i }
		sum += in
		idx++
	}

	if sum + d > n {
		fmt.Println ( "Yes" )
		for i := 0 ; i < m ; i++ {
			for data[i].F > 0 {
				fmt.Printf ( "%d ", data[i].S )
				data[i].F--
			}
		}

		n -= sum
		for n > 0 {
			n--
			fmt.Printf ( "0 " )
		}
		fmt.Println()
		return;
	}

	div := float32 ( ( n - sum ) * 1 / ( m + 1 ) * 1 )
	fmt.Println ( div )

	if ( div > float32 ( d - 1 ) ){
		fmt.Println ( "No" )
		return;
	}

	fmt.Println ( "Yes" )
	if n - sum <= m - 1 {
		i := 0
		for idx = 0 ; i < d ; i++ {
			d = n - sum
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				ans[idx] = data[i].S
				idx++
			}
			idx++
		}

		for ; i < m ; i++ {
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				ans[idx] = data[i].S
				idx++
			}
		}
	} else {
		if n - sum == m {
			flag = 0
			dis = 1
		} else {
			flag = 1
			dis = ( n - sum ) / ( m + 1 )
		}

		var i int
		swp = ( n - sum ) / dis
		for i = 0 ; i < swp ; i++ {
			len[i] = dis;
		}

		swp = n - sum - dis * ( m + flag )

		for i := 0 ; i < swp ; i++ {
			len[i]++
		}

		idx = 0
		for i = 0 ; i < m ; i++ {
			idx += len[i]
			for cnt := 0 ; cnt < data[i].F ; cnt++{
				ans[idx] = data[i].S
				idx++
			}
		}
	}

	for i := 0 ; i < n ; i++ {
		fmt.Printf ( "%d ", ans[i] )
	}

	fmt.Println()
}

/************************************/
/* Date		: 2019-11-06 14:35:59	*/
/* Author	: MiohitoKiri5474		*/
/* Email	: lltzpp@gmail.com		*/
/************************************/

package main

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

type pii struct{
	F int
	S int
}

const maxN = 1005

var ans, len [maxN]int
var data [maxN] pii

func main() {
	input := bufio.NewReader ( os.Stdin )
	var n, m, d, in, dis, swp, flag int
	sum := 0
	idx := 0
	fmt.Fscan ( input, &n, &m, &d )
	for i := 1 ; i <= m ; i++ {
		fmt.Fscan ( input, &in )
		data[idx] = pii { in, i }
		sum += in
		idx++
	}

	if sum + d > n {
		fmt.Println ( "Yes" )
		for i := 0 ; i < m ; i++ {
			for data[i].F > 0 {
				fmt.Printf ( "%d ", data[i].S )
				data[i].F--
			}
		}

		n -= sum
		for n > 0 {
			n--
			fmt.Printf ( "0 " )
		}
		fmt.Println()
		return;
	}

	div := ( n - sum ) * 1 / ( m + 1 ) * 1

	if ( div > d - 1 ){
		fmt.Println ( "No" )
		return;
	}

	fmt.Println ( "Yes" )
	if n - sum <= m - 1 {
		i := 0
		for idx = 0 ; i < d ; i++ {
			idx++
			d = n - sum
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				ans[idx] = data[i].S
				idx++
			}
		}

		for ; i < m ; i++ {
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				idx++
				ans[idx] = data[i].S
			}
		}
	} else {
		if n - sum == m {
			flag = 0
			dis = 1
		} else {
			flag = 1
			dis = ( n - sum ) / ( m + 1 )
		}

		var i int
		swp = ( n - sum ) / dis
		for i = 0 ; i < swp ; i++ {
			len[i] = dis;
		}

		swp = n - sum - dis * ( m + flag )

		for i := 0 ; i < swp ; i++ {
			len[i]++
		}

		idx = 0
		for i = 0 ; i < m ; i++ {
			idx += len[i]
			for cnt := 0 ; cnt < data[i].F ; cnt++{
				ans[idx] = data[i].S
				idx++
			}
		}
	}

	for i := 0 ; i < n ; i++ {
		fmt.Printf ( "%d ", ans[i] )
	}

	fmt.Println()
}