/*
URL:
https://codeforces.com/contest/1406/problem/A
*/

package main

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

var (
	t int

	n    int
	A    []int
	cnts [100 + 5]int
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		n = readi()
		A = readis(n)

		solve()
	}
}

func solve() {
	cnts = [100 + 5]int{}
	// for i := 0; i <= 100; i++ {
	// 	cnts[i] = 0
	// }

	for _, a := range A {
		cnts[a]++
	}

	C, D := []int{}, []int{}
	for i := 0; i <= 100; i++ {
		if cnts[i] == 0 {
			break
		}

		if cnts[i] == 1 {
			C = append(C, i)
		} else if cnts[i] >= 2 {
			C = append(C, i)
			D = append(D, i)
		}
	}

	cmemo, dmemo := [100 + 5]int{}, [100 + 5]int{}
	for _, c := range C {
		cmemo[c]++
	}
	for _, d := range D {
		dmemo[d]++
	}

	a, b := 0, 0
	for i := 0; i <= 101; i++ {
		if cmemo[i] == 0 {
			a = i
			break
		}
	}
	for i := 0; i <= 101; i++ {
		if dmemo[i] == 0 {
			b = i
			break
		}
	}

	fmt.Println(a + b)
}

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

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
)

// modi can calculate a right residual whether value is positive or negative.
func modi(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// modll can calculate a right residual whether value is positive or negative.
func modll(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

/********** bufio setting **********/

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

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

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

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

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

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

/*********** Input ***********/

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

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

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

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

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

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

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

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

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

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

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

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

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

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

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

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

package main

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

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 t int
	scanf("%d\n", &t)

	for t > 0 {

		var n int

		scanf("%d\n", &n)
		arr := make([]int, n)

		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
		}

		scanf("\n")

		sort.Ints(arr)
		mexA := 0
		mexB := 0
		ans := 0
		for i := 0; i < n; i++ {
			if arr[i] == mexA {
				mexA++
			} else {
				if arr[i] == mexB {
					mexB++
				}
			}
		}

		ans = mexA + mexB

		// printf("%v\n", arr)
		printf("%d\n", ans)
		t--
	}
}

package main

import (
	"fmt"
)

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

	for t != 0 {
		fmt.Scan(&n)
		var arr []int = make([]int, n)
		var count [101]int
		for i := 0; i < n; i++ {
			fmt.Scan(&arr[i])
			count[arr[i]]++
		}
		mexa := 0
		mexb := 0
		for i := 0; i < 101; i++ {
			if count[i] == 0 {
				mexa = i
				break
			}
		}
		for i := 0; i < 101; i++ {
			if count[i] <= 1 {
				mexb = i
				break
			}
		}
		fmt.Println(mexa + mexb)
		t--
	}
}

// 0 1 2 3
// 2 0 1 0

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scanf("%d\n", &n)
		var a []int
		for j := 0; j < n; j++ {
			var g int
			fmt.Scanf("%d", &g)
			a = append(a, g)
			if j != n-1 {
				fmt.Scan(" ")
			} else {
				fmt.Scanln()
			}
		}
		sort.Ints(a)
		l := -1
		r := -1
		for _, el := range a {
			if el == l+1 {
				l++
			} else {
				if el == r+1 {
					r++
				}
			}
		}
		fmt.Printf("%d\n", l+r+2)
	}
}

package main

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

var rw = NewFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	tt := rw.NextInt()
	for i := 0; i < tt; i++ {
		solveCase()
	}
}

func solveCase() {
	n := rw.NextInt()
	a := rw.NextInts(n)
	sort.Slice(a[:], func(i, j int) bool { return a[i] < a[j] })
	x, y := 0, 0
	for _, e := range a {
		if e == x {
			x++
		} else if e == y {
			y++
		}
	}
	rw.Println(x + y)
}

// @meooow template uwu
type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, c)
	}
	return string(s)
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}
func (f *FastIO) NextInt64() int64 {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := int64(0)
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int64(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}
func (f *FastIO) NextInt64s(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt64()
	}
	return a
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}
func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}
func (f *FastIO) PrintInt64s(a ...int64) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInt64s(a ...int64) {
	f.PrintInt64s(a...)
	f.Println()
}

package main

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

func subsetMex(a []int, n int) int {
	countArr := make([]int, 101)
	for _, ai := range a {
		countArr[ai] += 1
	}
	mexA := 0
	for ; mexA <= 100 && countArr[mexA] >= 2; mexA++ {
	}
	if mexA > 100 || countArr[mexA] == 0 {
		return mexA << 1
	}
	mexB := mexA + 1
	for ; mexB <= 100 && countArr[mexB] >= 1; mexB++ {
	}
	return mexA + mexB
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n, t, ans int
	fmt.Fscanln(reader, &t)
	for i := 0; i < t; i++ {
		fmt.Fscanln(reader, &n)
		a := make([]int, n)
		for i := 0; i < n-1; i++ {
			fmt.Fscanf(reader, "%d ", &a[i])
		}
		fmt.Fscanf(reader, "%d\n", &a[n-1])
		ans = subsetMex(a, n)
		fmt.Fprintln(writer, ans)
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	testCasesCount, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < testCasesCount; i++ {
		scanner.Scan()
		scanner.Scan()
		buffer := scanner.Text()
		stringSlices := strings.Split(buffer, " ")

		input := make([]int, 101)
		for _, str := range stringSlices {
			v, _ := strconv.Atoi(str)
			input[v]++
		}
		mexs := make([]int, 0)
		for j := 0; j < 102; j++ {
			if input[j] == 0 {
				mexs = append(mexs, j)
				mexs = append(mexs, j)
			} else if input[j] == 1 && len(mexs) == 0 {
				mexs = append(mexs, j)
			}
			if len(mexs) >= 2 {
				break
			}
		}
		result := 0
		for idx, mex := range mexs {
			if idx >= 2 {
				break
			}
			result += mex
		}
		fmt.Println(result)
	}
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

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

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		a := make([]int64, n)
		for i := range a {
			a[i] = sint64()
		}
		printf("%d\n", sol(a))
	}
}

func sol(a []int64) int64 {
	m := map[int64]int64{}
	for i := range a {
		m[a[i]]++
	}
	ret1 := int64(0)
	ret2 := int64(0)
	for i := int64(0); ; i++ {
		if m[i] >= 2 {
			if ret1 == i {
				ret1 = i+1
			}
			if ret2 == i {
				ret2 = i+1
			}
			continue
		}
		if m[i] == 1 {
			if ret1 == i {
				ret1 = i+1
			}
			continue
		}
		break
	}
	return ret1 + ret2
}

package main

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

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	for t := io.NextInt(); t > 0; t-- {
		n := io.NextInt()
		a := io.NextInts(n)

		sort.Ints(a)
		mex, mex2 := 0, 0
		for _, x := range a {
			if x == mex {
				mex++
			} else if x > mex {
				break
			} else if x == mex2 {
				mex2++
			}
		}
		io.Println(mex + mex2)
	}
}

type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

package main

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

func maxM(arr []int) int {
	a := make([]int, 101)
	for _, el := range arr {
		a[el] += 1
	}

	i := 0
	for ; i < len(a) && a[i] >= 2; i ++ {

	}

	j := i
	for ; j < len(a) && a[j] >= 1; j++ {

	}

	return i + j
}

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 t int
	scanf("%d\n", &t)
	for i := 0; i < t; i ++ {
		var N int
		scanf("%d\n", &N)

		arr := make([]int, N)
		for j := 0; j < N; j ++ {
			scanf("%d", &arr[j])
		}
		scanf("\n")
		printf("%d\n", maxM(arr))
	}
}

package main

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

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 t int
	scanf("%d\n", &t)

	for t > 0 {

		var n int

		scanf("%d\n", &n)
		arr := make([]int, n)

		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
		}

		scanf("\n")

		sort.Ints(arr)
		mexA := 0
		mexB := 0
		ans := 0
		for i := 0; i < n; i++ {
			if arr[i] == mexA {
				mexA++
			} else {
				if arr[i] == mexB {
					mexB++
				}
			}
		}

		ans = mexA + mexB

		printf("%v\n", arr)
		printf("%d\n", ans)
		t--
	}
}

package main

import (
	"fmt"
	"sort"
)

func mex(a []int) int {
	var arr = make([]int, len(a))
	copy(arr, a)
	if len(arr) == 0 {
		return 0
	}
	sort.Ints(arr)
	var i, j int = 0, 0
	for i < len(arr) {
		if j == arr[i] {
			for i < len(arr) && arr[i] == j {
				i++
			}
			j++
		} else {
			break
		}
	}
	return j
}

// 0013
func main() {
	var t, n int
	fmt.Scan(&t)

	for t != 0 {
		fmt.Scan(&n)
		var arr []int = make([]int, n)
		// var count map[int]int = make(map[int]int)
		for i := 0; i < n; i++ {
			fmt.Scan(&arr[i])
			// count[arr[i]]++
		}
		maxmex := 0
		for i := 0; i < n; i++ {
			// if count[arr[i]]%2 == 0 {
			// fmt.Println(arr[:i+1], mex(arr[:i+1]))
			// fmt.Println(arr[i+1:], mex(arr[i+1:]))
			mex := mex(arr[:i+1]) + mex(arr[i+1:])
			if maxmex < mex {
				maxmex = mex
			}
			// }
		}
		fmt.Println(maxmex)
		t--
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scanf("%d\n", &n)
		var a []int
		for j := 0; j < n; j++ {
			var g int
			fmt.Scanf("%d", &g)
			a = append(a, g)
			if j != n-1 {
				fmt.Scan(" ")
			} else {
				fmt.Scan("\n")
			}
		}
		sort.Ints(a)
		l := -1
		r := -1
		for _, el := range a {
			if el == l+1 {
				l++
			} else {
				if el == r+1 {
					r++
				}
			}
		}
		fmt.Printf("%d\n", l+r+2)
	}
}


package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1255C(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	orderP3 := [6][3]int{{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, {1, 2, 0}, {2, 0, 1}, {2, 1, 0}}

	var n int
	Fscan(in, &n)
	mp := make(map[[2]int][]int, 6*(n-2))
	q := make([][3]int, n-2)
	for i := range q {
		Fscan(in, &q[i][0], &q[i][1], &q[i][2])
		for j, order := range orderP3 {
			pair := [2]int{q[i][order[0]], q[i][order[1]]}
			mp[pair] = append(mp[pair], 6*i+j)
		}
	}

	g := make([][]int, 6*(n-2))
	inDeg := make([]int, len(g))
	for i, qi := range q {
		for j, order := range orderP3 {
			if ws, ok := mp[[2]int{qi[order[1]], qi[order[2]]}]; ok {
				v := 6*i + j
				for _, w := range ws {
					if w/6 != i {
						g[v] = append(g[v], w)
						inDeg[w]++
					}
				}
			}
		}
	}

	vOrder := make([]int, len(inDeg))
	fa := make([]int, len(inDeg))
	for i := range fa {
		fa[i] = -1
	}
	queue := []int{}
	for i, deg := range inDeg {
		if deg == 0 {
			queue = append(queue, i)
		}
	}
	var end int
	for len(queue) > 0 {
		var v int
		v, queue = queue[0], queue[1:]
		for _, w := range g[v] {
			inDeg[w]--
			if inDeg[w] == 0 {
				queue = append(queue, w)
				vOrder[w] = vOrder[v] + 1
				if vOrder[w] == n-3 {
					end = w
				}
				fa[w] = v
			}
		}
	}
	vs := make([]int, 0, n-2)
	for v := end; v != -1; v = fa[v] {
		vs = append(vs, v)
	}
	v := vs[len(vs)-1]
	q0, order0 := q[v/6], orderP3[v%6]
	Fprint(out, q0[order0[0]], q0[order0[1]])
	for i := len(vs) - 1; i >= 0; i-- {
		v = vs[i]
		qv, orderV := q[v/6], orderP3[v%6]
		Fprint(out, " ", qv[orderV[2]])
	}
}

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

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 n int
var T [][]int

type Triple struct {
	key     int
	a, b, c int
}
type TripleList []*Triple
type byKey struct {
	TripleList
}

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

func (l byKey) Less(i, j int) bool {
	return l.TripleList[i].key < l.TripleList[j].key
}

// how to use
// L := make(TripleList, 0, 200000+5)
// L = append(L, &Triple{key: intValue})
// sort.Stable(byKey{ L })                // Stable ASC
// sort.Stable(sort.Reverse(byKey{ L }))  // Stable DESC

// L := make(TripleList, 0)
// for i := 0; i < n-2; i++ {
// 	sort.Sort(sort.IntSlice(T[i]))
// 	L = append(L, &Triple{key: T[i][0], a: T[i][0], b: T[i][1], c: T[i][2]})
// }
// sort.Stable(byKey{L})

var book [100000 + 5][][]int

func main() {
	n = ReadInt()
	for i := 0; i < n-2; i++ {
		T = append(T, ReadIntSlice(3))
	}

	memo := make([]int, n+1)
	for i := 0; i < n-2; i++ {
		for j := 0; j < 3; j++ {
			q := T[i][j]
			memo[q]++
		}
	}

	ones := []int{}
	twos := []int{}
	for i := 1; i < n+1; i++ {
		if memo[i] == 1 {
			ones = append(ones, i)
		} else if memo[i] == 2 {
			twos = append(twos, i)
		}
	}

	for i := 0; i < n-2; i++ {
		a, b, c := T[i][0], T[i][1], T[i][2]
		book[a] = append(book[a], []int{a, b, c})
		book[b] = append(book[b], []int{a, b, c})
		book[c] = append(book[c], []int{a, b, c})
	}

	// 先頭のトリプルを見つける
	targetInt := ones[0]
	firstTriple := book[targetInt][0]
	answers := make([]int, 3)
	for i := 0; i < 3; i++ {
		tmp := firstTriple[i]
		if memo[tmp] == 1 {
			answers[0] = tmp
		} else if memo[tmp] == 2 {
			answers[1] = tmp
		} else {
			answers[2] = tmp
		}
	}

	// answersが完成するまでループ
	for len(answers) < n {
		l := len(answers)
		ex, inc1, inc2 := answers[l-3], answers[l-2], answers[l-1]
		// 最大3つの中から該当するものを見つける
		for _, tri := range book[inc2] {
			if sub(tri, ex, inc1, inc2) {
				// inc1, inc2以外の値をanswersに追加する
				answers = append(answers, subsubsub(tri, inc1, inc2))
				break
			}
		}
	}

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

// triが目的のものだったらtrue
func sub(tri []int, ex, inc1, inc2 int) bool {
	// exを含んだらfalse
	if subsub(tri, ex) {
		return false
	}

	// inc1を含まないならfalse
	if !subsub(tri, inc1) {
		return false
	}
	// inc2を含まないならfalse
	if !subsub(tri, inc2) {
		return false
	}

	return true
}

// triがtargetを含んだらtrue
func subsub(tri []int, target int) bool {
	for _, v := range tri {
		if v == target {
			return true
		}
	}
	return false
}

// inc1, inc2以外の値を返す
func subsubsub(tri []int, inc1, inc2 int) int {
	for _, v := range tri {
		if v != inc1 && v != inc2 {
			return v
		}
	}
	return -1
}

/*
- 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 n int
var T [][]int

var book [100000 + 5][][]int // バケット

func main() {
	n = ReadInt()
	for i := 0; i < n-2; i++ {
		T = append(T, ReadIntSlice(3))
	}

	// 頻度をカウント
	memo := make([]int, n+1)
	for i := 0; i < n-2; i++ {
		for j := 0; j < 3; j++ {
			q := T[i][j]
			memo[q]++
		}
	}

	ones := []int{}
	twos := []int{}
	for i := 1; i < n+1; i++ {
		if memo[i] == 1 {
			ones = append(ones, i)
		} else if memo[i] == 2 {
			twos = append(twos, i)
		}
	}

	// バケットでtripleを管理
	for i := 0; i < n-2; i++ {
		a, b, c := T[i][0], T[i][1], T[i][2]
		book[a] = append(book[a], []int{a, b, c})
		book[b] = append(book[b], []int{a, b, c})
		book[c] = append(book[c], []int{a, b, c})
	}

	// 先頭のトリプルを見つけ、元の配列の3番目までを復元する
	targetInt := ones[0]
	firstTriple := book[targetInt][0]
	answers := make([]int, 3)
	for i := 0; i < 3; i++ {
		tmp := firstTriple[i]
		if memo[tmp] == 1 {
			answers[0] = tmp
		} else if memo[tmp] == 2 {
			answers[1] = tmp
		} else {
			answers[2] = tmp
		}
	}

	// 完全に復元されるまでループ
	for len(answers) < n {
		l := len(answers)
		ex, inc1, inc2 := answers[l-3], answers[l-2], answers[l-1]
		// 高々3個のtripleから該当するものを見つける
		for _, tri := range book[inc2] {
			if sub(tri, ex, inc1, inc2) {
				// inc1, inc2以外の値をanswersに追加する
				answers = append(answers, subsubsub(tri, inc1, inc2))
				break
			}
		}
	}

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

// triが目的のものだったらtrue
func sub(tri []int, ex, inc1, inc2 int) bool {
	// exを含んだらfalse
	if subsub(tri, ex) {
		return false
	}

	// inc1を含まないならfalse
	if !subsub(tri, inc1) {
		return false
	}
	// inc2を含まないならfalse
	if !subsub(tri, inc2) {
		return false
	}

	return true
}

// triがtargetを含んだらtrue
func subsub(tri []int, target int) bool {
	for _, v := range tri {
		if v == target {
			return true
		}
	}
	return false
}

// inc1, inc2以外の値を返す
func subsubsub(tri []int, inc1, inc2 int) int {
	for _, v := range tri {
		if v != inc1 && v != inc2 {
			return v
		}
	}
	return -1
}

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

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

package main

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

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

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

	m := make(map[int][][2]int)
	cnt := make(map[int]int)

	var a, b, c int
	for i := 0; i < n - 2; i++ {
		fmt.Fscan(in, &a, &b, &c)
		//fmt.Println(m, a, b, c)
		m[a] = append(m[a], [2]int{b, c})
		m[b] = append(m[b], [2]int{a, c})
		m[c] = append(m[c], [2]int{a, b})
		cnt[a]++
		cnt[b]++
		cnt[c]++
	}
	//fmt.Println(m, a, b, c)

	for k, v := range cnt {
		if v == 1 {
			a = k
			if len(m[m[a][0][0]]) == 2 {
				b = m[a][0][0]
				c = m[a][0][1]
			} else {
				b = m[a][0][1]
				c = m[a][0][0]
			}
			break
		}
	}

	fmt.Fprintf(out, "%d %d %d ", a, b, c)
	//fmt.Println(a, b, c)
	for len(m[c]) != 1 {
		for _, arr := range m[b] {
			if arr[0] == c && arr[1] != a {
				a, b, c = b, c, arr[1]
				break
			} else if arr[1] == c && arr[0] != a {
				a, b, c = b, c, arr[0]
				break
			}
		}
		fmt.Fprintf(out, "%d ", c)
	}
	fmt.Fprintln(out)
}


package main
import("bufio";."fmt";."math/bits";"math/rand";."os";."time")

// github.com/EndlessCheng/codeforces-go
func main(){
	t:=Now();rand.Seed(t.UnixNano())
	in:=bufio.NewReader(Stdin)
	var n,m,p,mx int
	var ans uint64
	Fscanln(in,&n,&m,&p)
	a:=make([]uint64,n)
	for i:=range a{Fscanf(in,"%b\n",&a[i])}
	for Since(t)<Second{
		x:=a[rand.Intn(n)]
		if OnesCount64(x)<=mx{continue}
		cnt:=map[uint64]int{}
		for _,v:=range a{cnt[v&x]++}
		cnt2:=map[uint64]int{}
		for v,c:=range cnt{
			for s:=v;s>0;s=(s-1)&v{cnt2[s]+=c}
		}
		for v,c:=range cnt2{
			if o:=OnesCount64(v);c*2>=n&&o>mx{ans,mx=v,o}
		}
	}
	Printf("%0*b",m,ans)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"math/rand"
	"os"
	"time"
)

// github.com/EndlessCheng/codeforces-go
func CF1523D(_r io.Reader, out io.Writer) {
	t0 := time.Now()
	rand.Seed(t0.UnixNano())
	in := bufio.NewReader(_r)
	var n, m, p, o int
	var ans uint64
	Fscanln(in, &n, &m, &p)
	low := (n + 1) / 2
	c1 := make([]int, m)
	a := make([]uint64, n)
	for i := range a {
		Fscanf(in, "%b\n", &a[i])
		for j := range c1 {
			c1[j] += int(a[i] >> j & 1)
		}
	}
	for time.Since(t0) < 2500*time.Millisecond {
		mask := a[rand.Intn(n)]
		for i, c := range c1 {
			if c < low && mask>>i&1 > 0 {
				mask ^= 1 << i
			}
		}
		if bits.OnesCount64(mask) <= o {
			continue
		}
		cnt := map[uint64]int{}
		for _, v := range a {
			cnt[v&mask]++
		}
		cnt2 := map[uint64]int{}
		for v, c := range cnt {
			for s := v; s > 0; s = (s - 1) & v {
				cnt2[s] += c
			}
		}
		for v, c := range cnt2 {
			if c >= low {
				if om := bits.OnesCount64(v); om > o {
					ans, o = v, om
				}
			}
		}
	}
	Fprintf(out, "%0*b", m, ans)
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"math/rand"
	"os"
	"time"
)

// github.com/EndlessCheng/codeforces-go
func CF1523D(_r io.Reader, out io.Writer) {
	t0 := time.Now()
	rand.Seed(t0.UnixNano())
	in := bufio.NewReader(_r)
	var n, m, p, mx1 int
	var ans uint64
	Fscanln(in, &n, &m, &p)
	low := (n + 1) / 2
	a := make([]uint64, n)
	for i := range a {
		Fscanf(in, "%b\n", &a[i])
	}
	for time.Since(t0) < 2500*time.Millisecond {
		mask := a[rand.Intn(n)]
		if bits.OnesCount64(mask) <= mx1 {
			continue
		}
		cnt := map[uint64]int{}
		for _, v := range a {
			cnt[v&mask]++
		}
		cnt2 := map[uint64]int{}
		for v, c := range cnt {
			for s := v; s > 0; s = (s - 1) & v {
				cnt2[s] += c
			}
		}
		for v, c := range cnt2 {
			if c >= low {
				if o := bits.OnesCount64(v); o > mx1 {
					ans, mx1 = v, o
				}
			}
		}
	}
	Fprintf(out, "%0*b", m, ans)
}

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

package main
import("bufio";."fmt";."math/bits";"math/rand";."os";."time")

// github.com/EndlessCheng/codeforces-go
func main(){
	t:=Now();rand.Seed(t.UnixNano())
	in:=bufio.NewReader(Stdin)
	var n,m,p,mx int
	var ans uint64
	Fscanln(in,&n,&m,&p)
	c1:=make([]int,m)
	a:=make([]uint64,n)
	for i:=range a{
		Fscanf(in,"%b\n",&a[i])
		for j:=range c1{c1[j]+=int(a[i]>>j&1)}
	}
	for Since(t)<2500*Millisecond{
		x:=a[rand.Intn(n)]
		for i,c:=range c1{if c*2<n&&x>>i&1>0{x^=1<<i}}
		if OnesCount64(x)<=mx{continue}
		cnt:=map[uint64]int{}
		for _,v:=range a{cnt[v&x]++}
		cnt2:=map[uint64]int{}
		for v,c:=range cnt{
			for s:=v;s>0;s=(s-1)&v{cnt2[s]+=c}
		}
		for v,c:=range cnt2{
			if o:=OnesCount64(v);c*2>=n&&o>mx{ans,mx=v,o}
		}
	}
	Printf("%0*b",m,ans)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"math/rand"
	"os"
	"time"
)

// github.com/EndlessCheng/codeforces-go
func CF1523D(_r io.Reader, out io.Writer) {
	t0 := time.Now()
	in := bufio.NewReader(_r)
	var n, m, p, o int
	var ans uint64
	Fscanln(in, &n, &m, &p)
	low := (n + 1) / 2
	c1 := make([]int, m)
	a := make([]uint64, n)
	for i := range a {
		Fscanf(in, "%b\n", &a[i])
		for j := range c1 {
			c1[j] += int(a[i] >> j & 1)
		}
	}
	rand.Seed(t0.UnixNano())
	for time.Since(t0) < 2900*time.Millisecond {
		mask := a[rand.Intn(n)] & a[rand.Intn(n)]
		for i, c := range c1 {
			if c < low && mask>>i&1 > 0 {
				mask ^= 1 << i
			}
		}
		om := bits.OnesCount64(mask)
		if om <= o {
			continue
		}
		c := 0
		for _, v := range a {
			if v|mask == v {
				c++
			}
		}
		if c >= (n+1)/2 {
			ans, o = mask, om
		}
	}
	Fprintf(out, "%0*b", m, ans)
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"math/rand"
	"os"
	"time"
)

// github.com/EndlessCheng/codeforces-go
func CF1523D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, m, z int
	var ans uint64
	Fscanln(in, &n, &m, &z)
	a := make([]uint64, n)
	for i := range a {
		Fscanf(in, "%b\n", &a[i])
	}
	p := make([]int, m)
	for i := range p {
		p[i] = i
	}
	rand.Seed(time.Now().UnixNano())
	for t := 60; t > 0; t-- {
		rand.Shuffle(m, func(i, j int) { p[i], p[j] = p[j], p[i] })
		ok := uint64(0)
		for _, p := range p {
			m := ok | 1<<p
			c := 0
			for _, v := range a {
				if v|m == v {
					c++
				}
			}
			if c >= (n+1)/2 {
				ok = m
			}
		}
		if bits.OnesCount64(ok) > bits.OnesCount64(ans) {
			ans = ok
		}
	}
	Fprintf(out, "%0*b", m, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1523D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, m, z int
	var ans uint64
	Fscanln(in, &n, &m, &z)
	a := make([]uint64, n)
	for i := range a {
		Fscanf(in, "%b\n", &a[i])
	}
	p := make([]int, m)
	for i := range p {
		p[i] = i
	}
	for t := 70; t > 0; t-- {
		rand.Shuffle(m, func(i, j int) { p[i], p[j] = p[j], p[i] })
		ok := uint64(0)
		for _, p := range p {
			m := ok | 1<<p
			c := 0
			for _, v := range a {
				if v|m == v {
					c++
				}
			}
			if c >= (n+1)/2 {
				ok = m
			}
		}
		if bits.OnesCount64(ok) > bits.OnesCount64(ans) {
			ans = ok
		}
	}
	Fprintf(out, "%0*b", m, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1523D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, m, z int
	var ans uint64
	Fscanln(in, &n, &m, &z)
	a := make([]uint64, n)
	for i := range a {
		Fscanf(in, "%b\n", &a[i])
	}
	p := make([]int, m)
	for i := range p {
		p[i] = i
	}
	for t := 50; t > 0; t-- {
		rand.Shuffle(m, func(i, j int) { p[i], p[j] = p[j], p[i] })
		ok := uint64(0)
		for _, p := range p {
			m := ok | 1<<p
			c := 0
			for _, v := range a {
				if v|m == v {
					c++
				}
			}
			if c >= (n+1)/2 {
				ok = m
			}
		}
		if bits.OnesCount64(ok) > bits.OnesCount64(ans) {
			ans = ok
		}
	}
	Fprintf(out, "%0*b", m, ans)
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"math/rand"
	"os"
	"time"
)

// github.com/EndlessCheng/codeforces-go
func CF1523D(_r io.Reader, out io.Writer) {
	t0 := time.Now()
	in := bufio.NewReader(_r)
	var n, m, p, o int
	var ans int64
	Fscanln(in, &n, &m, &p)
	a := make([]int64, n)
	for i := range a {
		Fscanf(in, "%b\n", &a[i])
	}
	rand.Seed(time.Now().UnixNano())
	for time.Since(t0) < 2900*time.Millisecond {
		mask := rand.Int63n(1 << p)
		om := bits.OnesCount(uint(mask))
		if om <= o {
			continue
		}
		rand.Shuffle(m, func(i, j int) { mask = mask&^(1<<i|1<<j) | mask>>i&1<<j | mask>>j&1<<i })
		c := 0
		for _, v := range a {
			if v|mask == v {
				c++
			}
		}
		if c >= (n+1)/2 {
			ans, o = mask, om
		}
	}
	Fprintf(out, "%0*b", m, ans)
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"math/rand"
	"os"
	"time"
)

// github.com/EndlessCheng/codeforces-go
func CF1523D(_r io.Reader, out io.Writer) {
	t0 := time.Now()
	in := bufio.NewReader(_r)
	var n, m, p int
	var ans int64
	Fscanln(in, &n, &m, &p)
	a := make([]int64, n)
	for i := range a {
		Fscanf(in, "%b\n", &a[i])
	}
	rand.Seed(time.Now().UnixNano())
	for time.Since(t0) < 2900*time.Millisecond {
		mask := rand.Int63n(1 << m)
		o := bits.OnesCount(uint(mask))
		if o > p {
			continue
		}
		c := 0
		for _, v := range a {
			if v|mask == v {
				c++
			}
		}
		if c >= (n+1)/2 && o > bits.OnesCount(uint(ans)) {
			ans = mask
		}
	}
	Fprintf(out, "%0*b", m, ans)
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"math/rand"
	"os"
	"time"
)

// github.com/EndlessCheng/codeforces-go
func CF1523D(_r io.Reader, out io.Writer) {
	t0 := time.Now()
	in := bufio.NewReader(_r)
	var n, m, p int
	var ans int64
	Fscanln(in, &n, &m, &p)
	a := make([]int64, n)
	for i := range a {
		Fscanf(in, "%b\n", &a[i])
	}
	rand.Seed(time.Now().UnixNano())
	for time.Since(t0) < 2900*time.Millisecond {
		mask := rand.Int63n(1 << m)
		o := bits.OnesCount(uint(mask))
		if o > p {
			continue
		}
		c := 0
		for _, v := range a {
			if v|mask == v {
				c++
			}
		}
		if c >= (n+1)/2 && o > bits.OnesCount(uint(ans)) {
			ans = mask
		}
	}
	Fprintf(out, "%*b", m, ans)
}

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


package main

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

func do(s string) string {
	if len(s)&1 == 1 {
		return s
	}
	s1 := do(s[:len(s)>>1])
	s2 := do(s[len(s)>>1:])
	if s1 < s2 {
		return s1 + s2
	}
	return s2 + s1
}

// github.com/EndlessCheng/codeforces-go
func Sol559B(reader io.Reader, writer io.Writer) {
	ifElse := func(cond bool, r1, r2 string) string {
		if cond {
			return r1
		}
		return r2
	}

	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var s, t string
	Fscan(in, &s, &t)
	Fprint(out, ifElse(do(s) == do(t), "YES", "NO"))
}

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

package main

import (
	"fmt"
	"os"
)

func smallest(sa string) string {
	if len(sa)%2 == 1 {
		return sa
	}
	var l = len(sa)
	var sfirst = smallest(sa[0 : l/2])
	var ssecond = smallest(sa[l/2 : l])
	if sfirst+ssecond < ssecond+sfirst {
		return sfirst + ssecond
	} else {
		return ssecond + sfirst
	}
}

func main() {
	// f, _ := os.Open("input.txt")
	f := os.Stdin
	var sa, sb string
	fmt.Fscanf(f, "%s\n%s", &sa, &sb)
	var equivalent = smallest(sa) == smallest(sb)
	if equivalent == true {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

func eqiv(a, b string) bool {
	n1 := len(a)
	n2 := len(b)
	if a == b {
		return true
	}
	if n1 != n2 {
		return false
	}
	if n1 == 1 {
		return false
	}
	if n1%2 == 1 {
		return false
	}
	n := n1 / 2
	a1 := a[:n]
	a2 := a[n:]
	b1 := b[:n]
	b2 := b[n:]
	return ((eqiv(a1, b2) && eqiv(a2, b1)) || (eqiv(a1, b1) && eqiv(a2, b2)))
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	a, _ := reader.ReadString('\n')
	b, _ := reader.ReadString('\n')
	a = strings.TrimSpace(a)
	b = strings.TrimSpace(b)
	if eqiv(a, b) == true {
		fmt.Printf("YES")
	} else {
		fmt.Printf("NO")
	}
}

package main

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

func sort(s string) string {
  if len(s)%2 != 0 {
    return s
  }

  mid := len(s)/2
  left, right := sort(s[:mid]), sort(s[mid:])
  if right < left {
    return right + left
  }
  return left + right
}

func main() {
    stdin := bufio.NewReader(os.Stdin)
    var a, b string
    fmt.Fscan(stdin, &a, &b)
    if sort(a) == sort(b) {
      fmt.Println("YES")
    } else {
      fmt.Println("NO")
    }
}

package main

import "fmt"

func foo(s string) string {
	if len(s)%2 == 1 {
		return s
	}

	s1 := s[:len(s)/2]
	s2 := s[len(s)/2:]

	s1 = foo(s1)
	s2 = foo(s2)

	if s1 < s2 {
		return s1 + s2
	} else {
		return s2 + s1
	}
}

func main() {
	var A, B string

	fmt.Scanf("%s\n%s", &A, &B)

	if foo(A) == foo(B) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

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

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

	var s, t string

	scan(&s, &t)

	if equal(s, t) {
		println("YES")
	} else {
		println("NO")
	}
}

func equal(s, t string) bool {
	if s == t {
		return true
	}

	// if (len(s) & 1) > 0 {
	// 	return false
	// }

	// h := len(s) >> 1

	if len(s)%2 != 0 {
		return false
	}

	h := len(s) / 2
	return (equal(s[:h], t[h:]) && equal(s[h:], t[:h])) || (equal(s[:h], t[:h]) && equal(s[h:], t[h:]))
}

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

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

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

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

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

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

package main

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

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

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

	var s, t string

	scan(&s, &t)

	if equal(s, t) {
		println("YES")
	} else {
		println("NO")
	}
}

func equal(s, t string) bool {
	if s == t {
		return true
	}

	if (len(s) & 1) > 0 {
		return false
	}

	h := len(s) >> 1

	return (equal(s[:h], t[h:]) && equal(s[h:], t[:h])) || (equal(s[:h], t[:h]) && equal(s[h:], t[h:]))
}

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

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

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

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

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

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

package main

import (
	"fmt"
	"os"
)

func smallest(sa string) string {
	if len(sa)%2 == 1 {
		return sa
	}
	var l = len(sa)
	var sfirst = smallest(sa[0 : l/2])
	var ssecond = smallest(sa[l/2 : l])
	if sfirst < ssecond {
		return sfirst + ssecond
	} else {
		return ssecond + sfirst
	}
}

func main() {
	// f, _ := os.Open("input.txt")
	f := os.Stdin
	var sa, sb string
	fmt.Fscanf(f, "%s\n%s", &sa, &sb)
	var equivalent = smallest(sa) == smallest(sb)
	if equivalent == true {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

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

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

	var s, t string

	scan(&s, &t)

	if equal(s, t) {
		println("YES")
	} else {
		println("NO")
	}
}

func equal(s, t string) bool {
	if s == t {
		return true
	}

	if (len(s) >> 1) > 0 {
		return false
	}

	h := len(s) >> 1

	return (equal(s[:h], t[:h]) && equal(s[h:], t[h:])) || (equal(s[:h], t[h:]) && equal(s[h:], t[:h]))
}

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

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

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

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

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

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

package main

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

func sort(s string) string {
  if len(s)%2 != 0 {
    return s
  }

  mid := len(s)/2
  left, right := sort(s[:mid]), sort(s[mid:])
  if right < left {
    return right + left
  }
  return left + right
}

func main() {
    stdin := bufio.NewReader(os.Stdin)
    var a, b string
    fmt.Fscan(stdin, &a, &b)
    fmt.Println(sort(a))

    if sort(a) == sort(b) {
      fmt.Println("YES")
    } else {
      fmt.Println("NO")
    }
}


package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	text := scanner.Text()
	str := strings.Split(text, " ")
	numBusRoutes, _ := strconv.Atoi(str[0])
	startTime, _ := strconv.Atoi(str[1])

	var busTaken, minWaitTime int

	for i := 1; i <= numBusRoutes; i++ {
		scanner.Scan()
		text := scanner.Text()
		str := strings.Split(text, " ")
		busArrival, _ := strconv.Atoi(str[0])
		busInterval, _ := strconv.Atoi(str[1])

		if busArrival == startTime {
			fmt.Println(i)
			return
		}

		waitTime := busArrival - startTime

		if busArrival < startTime {
			nextBus := busArrival
			for nextBus < startTime {
				nextBus += busInterval

				if nextBus == startTime {
					fmt.Println(i)
					return
				}
			}
			waitTime = nextBus - startTime
		}

		if minWaitTime == 0 || waitTime < minWaitTime {
			busTaken = i
			minWaitTime = waitTime
		}
	}
	fmt.Println(busTaken)
}

package main

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

func main() {
	buf := bufio.NewReader(os.Stdin)
	var n ,t int
	var s,d int
	fmt.Fscanf(buf, "%d %d\n", &n,&t)
	var maxw int = -1
	var maxt int = -1

	for i := 1; i <= n; i++ {
		fmt.Fscanf(buf, "%d %d\n", &s,&d)
		tmp := s
		if t > s{
			tmp =(1+ (t-s-1)/d)*d + s
		}
		if  maxt == -1|| tmp < maxt{
			maxt = tmp
			maxw = i
		}
	}
	fmt.Printf("%d\n",maxw)

}

package main

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

func main() {
    reader := bufio.NewReaderSize(os.Stdin, 1024 * 1024)

    arTemp := strings.Split(readLine(reader), " ")
    n, err := strconv.ParseInt(arTemp[0], 10, 64)
    checkError(err)
    t, err := strconv.ParseInt(arTemp[1], 10, 64)
    checkError(err)

    ans := 0
    min := int64(1000000)
    for i := 1; i <= int(n); i++ {
        arItemTemp := strings.Split(readLine(reader), " ")
        s, err := strconv.ParseInt(arItemTemp[0], 10, 64)
        checkError(err)
        d, err := strconv.ParseInt(arItemTemp[1], 10, 64)
        checkError(err)

        if t > s {
            cnt := (t - s) / d
            rem := (t - s) % d
            if rem != 0 {
                cnt++
            }
            s += d * cnt
        }
        diff := s - t
        if diff < min {
            min = diff
            ans = i
        }
    }

    fmt.Println(ans)
}

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

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

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

package main

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

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

	var n, t int
	fmt.Fscanln(in, &n, &t)

	minVal := -1
	minIndex := -1
	for i := 0; i < n; i++ {
		var s, d int
		fmt.Fscanln(in, &s, &d)

		earliest := s - t
		if earliest < 0 {
			times := (earliest * -1 - 1) / d + 1
			earliest += times * d
		}
		//fmt.Println("Earliest:", earliest, )
		if earliest < minVal || minVal == -1 {
			minVal = earliest
			minIndex = i
		}
	}

	fmt.Println(minIndex + 1)
}

package main

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

func main() {
	sc := NewScanner()
	N, T := sc.NextInt(), sc.NextInt()
	mn := int(1e9)
	index := 0
	for i := 0; i < N; i++ {
		s, d := sc.NextInt(), sc.NextInt()
		A := (d - (T-s)%d) % d
		if T-s < 0 {
			A = s - T
		}
		//fmt.Println(mn, A)
		if mn > A {
			mn = A
			index = i + 1
		}
	}
	fmt.Println(index)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	sc := NewScanner()
	N, T := sc.NextInt(), sc.NextInt()
	mn := int(1e9)
	index := 0
	for i := 0; i < N; i++ {
		s, d := sc.NextInt(), sc.NextInt()
		A := (d - (T-s)%d) % d
		//fmt.Println(mn, A)
		if mn > A {
			mn = A
			index = i + 1
		}
	}
	fmt.Println(index)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	sc := NewScanner()
	N, T := sc.NextInt(), sc.NextInt()
	mn := int(1e9)
	index := 0
	for i := 0; i < N; i++ {
		s, d := sc.NextInt(), sc.NextInt()
		A := (d - (T - s)) % d
		if T-s < 0 {
			A = s - T
		}
		//fmt.Println(mn, A)
		if mn > A {
			mn = A
			index = i + 1
		}
	}
	fmt.Println(index)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"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, k int
		Fscan(in, &n, &k)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		for i := range a {
			for a[i] > 0 && k > 0 {
				a[i]--
				k--
				a[n-1]++
			}
			if k == 0 {
				break
			}
		}
		for _, v := range a {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1516A
Date: 19/10/21
User: epradere
URL: https://codeforces.com/problemset/problem/1516/A
Problem: CF1516A
**/
func (in *CF1516A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n, k := in.NextInt(), in.NextInt()
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
		}
		index := 0
		for i := 0; i < k; i++ {
			for j := index; j < n; j++ {
				if arr[j] > 0 {
					index = j
					arr[index]--
					arr[n-1]++
					break
				}
			}
		}

		for i := 0; i < n; i++ {
			fmt.Print(arr[i], " ")
		}
		fmt.Println()
	}
}
func NewCF1516A(r *bufio.Reader) *CF1516A {
	return &CF1516A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

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

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,k int
		fmt.Fscan(in,&n,&k)
		list:= make([]int,n)
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list[j])
		}
		count:=0
		for j:=0;j<k;j++{
			if list[count] == 0 {
				count++
				j--
			} else {
				list[count]--
				list[n-1]++
			}
			if count > n-2{
				break
			}
		}
		for j:=0;j<len(list);j++{
			fmt.Fprintf(out,"%v ",list[j])
		}
		fmt.Fprintln(out,)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int

	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n int
		var k int
		fmt.Scan(&n)
		fmt.Scan(&k)

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

		j := 0
		for k > 0 {
			if j == n-1 {
				break
			}

			if a[j] == 0 {
				j++
				continue
			}

			k--
			a[j]--
			a[n-1]++
		}

		for i := 0; i < n; i++ {
			fmt.Print(a[i], " ")
		}
		fmt.Print("\n")
	}
}

package main

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

const REPEAT bool = true
const CASE   bool = false

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

  if REPEAT {
    var t int
    Fscan(in, &t);
    for i := 1; i <= t; i++ {
      if CASE {
        Fprintf(out, "Case #%d: ", i)
      }
      solve(in, out)
    }
  } else {
    solve(in, out)
  }
}

func solve(in io.Reader, out io.Writer) {
  var n, k int
  Fscan(in, &n, &k)
  arr := make([]int, n)
  for i := range arr {
    Fscan(in, &arr[i])
  }
  sum := 0
  for i := 0; i < n - 1 && k > 0; i++ {
    if k >= arr[i] {
      sum += arr[i]
      k -= arr[i]
      arr[i] = 0
    } else {
      sum += k
      arr[i] -= k
      k = 0
    }
  }
  arr[n-1] += sum
  for _, e := range arr {
    Fprintf(out, "%d ", e)
  }
  Fprintln(out)
}

package main

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

const maxN = 100023

func main() {
  in := bufio.NewReader(os.Stdin)
  out := bufio.NewWriter(os.Stdout)
  defer out.Flush()
  var tt int
  fmt.Fscan(in, &tt)
  for tc := 1; tc <= tt; tc++ {
    var n, k int
    fmt.Fscan(in, &n, &k)
    var a[maxN] int
    for i := 0; i < n; i++ {
      fmt.Fscan(in, &a[i])
    }
    i := 0
    for true {
      if i == n-1 || k == 0{
        break
      }
      if a[i] == 0 {
        i++
        continue
      }
      a[i]--
      a[n-1]++
      k--
    }
    for i = 0; i < n; i++ {
      fmt.Fprint(out, a[i], " ")
    }
    fmt.Fprintln(out)
  }
}

package main

import (
	"fmt"
)

func solve() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	l := 0
	r := n - 1
	for i := 0; i < k; i++ {
		for j := l; j < n; j++ {
			if a[j] > 0 {
				break
			}
			l++
		}

		if l <= r && a[l] > 0 {
			a[l]--
			a[r]++
		}
	}
	for i := 0; i < n; i++ {
		fmt.Print(a[i], " ")
	}
	fmt.Println()
}

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		solve()
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var buf bytes.Buffer
	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, k := readTwoNums(reader)
		A := readNNums(reader, n)
		solve(n, k, A)
		for i := 0; i < n; i++ {
			buf.WriteString(fmt.Sprintf("%d ", A[i]))
		}
		buf.WriteByte('\n')
	}
	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, k int, A []int) {
	i, j := 0, n-1

	for i < j && k > 0 {
		x := max(0, A[i]-k)
		k -= A[i] - x
		// want to decrease A[i] to x
		A[j] += A[i] - x
		A[i] = x
		i++
	}
}

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

package main

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

var fields []string

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, err := ioutil.ReadAll(bufio.NewReader(f))

	if err != nil {
		panic(err)
	}

	fields = strings.Fields(string(bytes))
}

func ScanString() string {
	for {
		field := fields[0]
		fields = fields[1:]

		if field != "" {
			return field
		}
	}
}

func ScanInt() int {
	n, err := strconv.Atoi(ScanString())

	if err != nil {
		panic(err)
	}

	return n
}

func ScanInt64() int64 {
	n, err := strconv.ParseInt(ScanString(), 10, 64)

	if err != nil {
		panic(err)
	}

	return n
}

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, k := ScanInt(), ScanInt()
		a := make([]int, n)
		ops := 0

		for i := range a {
			a[i] = ScanInt()

			if ops+a[i] < k {
				ops += a[i]
				a[i] = 0
			} else {
				a[i] -= k - ops
				ops = k
			}
		}

		a[n-1] += ops
		fmt.Println(strings.Trim(fmt.Sprint(a), "[]"))
	}
}

package main

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

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

	solve := func() {
		var n, k int
		fmt.Fscan(in, &n, &k)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		j := 0
		for i := 0; i < k; i++ {
			for j < n && a[j] < 1 {
				j++
			}
			if j >= n-1 {
				break
			}
			if a[j] > 0 {
				a[j]--
				a[len(a)-1]++
			}
		}
		for i := 0; i < n; 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 (
	"bufio"
	"fmt"
	"os"
)

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, k := 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &k)
		j, o, l := 0, make([]int, n), 0
		for q := 0; q < n; q++ {
			fmt.Fscan(f, &o[q])
		}
		for {
			if k <= 0 || j == n-1 {
				o[n-1] += l
				break
			} else {
				if o[j] <= k {
					o[j], k, l = 0, k-o[j], l+o[j]
				} else {
					o[j], k, l = o[j]-k, 0, l+k
				}
			}
			j++
		}
		for q := 0; q < n; q++ {
			fmt.Fprint(w, o[q], " ")
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

var (
	reader  = bufio.NewReader(os.Stdin)
	t, n, k int
)

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

func solve(n, k int, a []int) string {
	for i := 0; i < n-1 && k > 0; i++ {
		d := min(k, a[i])
		a[n-1] += d
		a[i] -= d
		k -= d
	}
	x := ""
	for i := 0; i < n; i++ {
		x += fmt.Sprintf("%d ", a[i])
	}
	return x
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &k)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(n, k, a))
	}
}

package main

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

var (
	reader *bufio.Reader = bufio.NewReader(os.Stdin)
	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 SplitToString(a []int, sep string) string {
	if len(a) == 0 {
		return ""
	}

	b := make([]string, len(a))
	for i, v := range a {
		b[i] = strconv.Itoa(v)
	}
	return strings.Join(b, sep)
}

func main() {
	defer writer.Flush()

	var t, n, k int
	scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		scanf("%d %d\n", &n, &k)
		a := make([]int, n)

		for i := 0; i < n; i++ {
			scanf("%d", &a[i])
		}
		scanf("\n")

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

		fmt.Printf("%s\n", SplitToString(a, " "))
	}
}

package main

import "fmt"

func code() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n, k int
		fmt.Scan(&n, &k)
		array := make([]int, n)
		for j := 0; j < n; j++{
			a := 0
			fmt.Scan(&a)
			array[j] = a
		}
		for p := 0; p < k; p++{
			for j := 0; j < n; j++{
				if (array[j] > 0){
					array[j] -= 1
					array[len(array)-1] += 1
					break
				} else {
				}
			}
		}
		for j := 0; j < len(array); j++{
			fmt.Print(array[j])
			fmt.Print(" ")
		}
		fmt.Println()
	}
}

func main(){
	code()
}

package main

import (
	"fmt"
	"math"
)

func main() {
	const N = 100

	var t, n, k int
	var a [N]int
	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scan(&n)
		fmt.Scanln(&k)
		for u := 0; u < n; u++ {
			fmt.Scan(&a[u])
		}
		for u := 0; u < n; u++ {
			var temp int
			if u < n-1 {
				temp = int(math.Min(float64(k), float64(a[u])))
			} else {
				temp = 0
			}
			a[u] -= temp
			k -= temp
			a[n-1] += temp
			fmt.Print(a[u], " ")
		}
		fmt.Println()
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var 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 t int
	scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n, k, a int
		scanf("%d %d\n", &n, &k)
		var numbers []int
		for j := 0; j < n-1; j++ {
			scanf("%d ", &a)
			numbers = append(numbers, a)
		}
		scanf("%d\n", &a)
		numbers = append(numbers, a)

		solution(numbers, k)
		for _, n := range numbers {
			printf("%d ", n)
		}
		printf("\n")
	}
}

func solution(numbers []int, k int) {
	l := len(numbers)
	for i := 0; i < l-1; i++ {
		if k > numbers[i] {
			k -= numbers[i]
			numbers[l-1] += numbers[i]
			numbers[i] = 0
			continue
		}

		numbers[l-1] += k
		numbers[i] -= k
		k = 0
		break
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N, K, a int
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N, &K)
		ns := make([]int, N)
		for i := 0; i < N; i++ {
			Fscan(in, &a)
			ns[i] = a
		}
		i := 0
		k := K
		for k > 0 && i < N {
			d := k - ns[i]
			if d <= 0 {
				ns[i] -= k
				ns[N-1] += k
				break
			}
			delta := ns[i]
			k -= delta
			ns[i] = 0
			ns[N-1] += delta
			i++
		}
		// Fprintln(out, N, K, ns)
		for idx := 0; idx < N; idx++ {
			Fprint(out, ns[idx], " ")
		}
		Fprint(out, "\n")
	}

}

package main

import (
	"fmt"
	"os"
)

func scanf(f string, args ...interface{})  { fmt.Fscanf(os.Stdin, f, args...) }
func printf(f string, args ...interface{}) { fmt.Fprintf(os.Stdout, f, args...) }

func main() {
	var l int
	fmt.Fscanf(os.Stdin, "%d\n", &l)
	for i := 0; i < l; i++ {
		var n, k int
		fmt.Fscan(os.Stdin, &n)
		fmt.Fscan(os.Stdin, &k)

		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(os.Stdin, &a[j])
		}
		r := fn(a, k)
		h := 0
		value := 0
		for h, value = range r {
			if h < n-1 {
				fmt.Fprintf(os.Stdout, "%d ", value)
			} else {
				fmt.Fprintf(os.Stdout, "%d\n", value)
			}
		}
	}
}

func fn(a []int, k int) []int {
	i := 0
	n := len(a) - 1
	for k > 0 {
		if a[i] > 0 {
			a[i]--
			a[n]++
			k--
		} else if i+1 < n {
			i++
		} else {
			break
		}
	}
	return a
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,k int
		fmt.Fscan(in,&n,&k)
		list:= make([]int,n)
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list[j])
		}
		count:=0
		for j:=0;j<k;j++{
			list[count]--
			list[n-1]++
			if list[count] == 0 {
				count++
			}
			if count > n-2{
				break
			}
		}
		for j:=0;j<len(list);j++{
			fmt.Fprintf(out,"%v ",list[j])
		}
		fmt.Fprintln(out,)
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,k int
		fmt.Fscan(in,&n,&k)
		list:= make([]int,n)
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list[j])
		}
		count:=0
		for j:=0;j<k;j++{
			list[count]--
			list[n-1]++
			if list[0] == 0 {
				count++
			}
			if count > n-2{
				break
			}
		}
		for j:=0;j<len(list);j++{
			fmt.Fprintf(out,"%v ",list[j])
		}
		fmt.Fprintln(out,)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int

	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n int
		var k int
		fmt.Scan(&n)
		fmt.Scan(&k)

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

		j := 0
		for ; k > 0; k-- {
			if a[j] == 0 {
				j++
			}

			if j == n-1 {
				break
			}

			a[j]--
			a[n-1]++
		}

		for i := 0; i < n; i++ {
			fmt.Print(a[i], " ")
		}
		fmt.Print("\n")
	}
}

package main

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

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

const maxN = 100023

func main() {
  defer writer.Flush()
  var tt int
  scanf("%d\n", &tt)
  for tc := 1; tc <= tt; tc++ {
    var n, k int
    scanf("%d %d\n", &n, &k)
    var a[maxN] int
    for i := 0; i < n; i++ {
      scanf("%d ", &a[i])
    }
    i := 0
    for true {
      if i == n-1 || k == 0{
        break
      }
      if a[i] == 0 {
        i++
        continue
      }
      a[i]--
      a[n-1]++
      k--
    }
    for i = 0; i < n; i++ {
      printf("%d ", a[i])
    }
    printf("\n")
  }
}

package main

import (
	"fmt"
)

func solve() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	l := 0
	r := n - 1
	for i := 0; i < k; i++ {
		for j := l; j < n; j++ {
			if a[j] > 0 {
				break
			}
		}

		if a[l] > 0 {
			a[l]--
			a[r]++
		}
	}
	for i := 0; i < n; i++ {
		fmt.Print(a[i], " ")
	}
	fmt.Println()
}

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		solve()
	}
}

package main

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

var fields []string

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, err := ioutil.ReadAll(bufio.NewReader(f))

	if err != nil {
		panic(err)
	}

	fields = strings.Fields(string(bytes))
}

func ScanString() string {
	for {
		field := fields[0]
		fields = fields[1:]

		if field != "" {
			return field
		}
	}
}

func ScanInt() int {
	n, err := strconv.Atoi(ScanString())

	if err != nil {
		panic(err)
	}

	return n
}

func ScanInt64() int64 {
	n, err := strconv.ParseInt(ScanString(), 10, 64)

	if err != nil {
		panic(err)
	}

	return n
}

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, k := ScanInt(), ScanInt()
		a := make([]int, n)
		ops := 0

		for i := range a {
			a[i] = ScanInt()

			if ops+a[i] < k {
				a[i] = 0
				ops += a[i]
			} else {
				a[i] -= k - ops
				ops = k
			}
		}

		a[n-1] += ops
		fmt.Println(strings.Trim(fmt.Sprint(a), "[]"))
	}
}

package main

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

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

	solve := func() {
		var n, k int
		fmt.Fscan(in, &n, &k)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		j := 0
		for i := 0; i < k; i++ {
			for j < n && a[j] > 1 {
				j++
			}
			if j == k-1 {
				break
			}
			if a[j] > 1 {
				a[j]--
				a[len(a)-1]++
			}
		}
		for i := 0; i < n; 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"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1129B(in io.Reader, out io.Writer) {
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	Fprint(out, "2000\n-1")
	var k int
	Fscan(in, &k)
	k += 2000
	for i := 1; i < 2000; i++ {
		v := min(1e6, k)
		Fprint(out, " ", v)
		k -= v
	}
}

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

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var k int
	fmt.Fscanf(reader, "%d", &k)
	n, s := 2000, 2000 + k
	fmt.Printf("2000\n-1")
	for i := 1;i < n;i ++ {
		if s >= 1000000 {
			fmt.Printf(" 1000000")
			s -= 1000000
		} else {
			fmt.Printf(" %d", s)
			s = 0
		}
	}
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var k int
	fmt.Fscanf(reader, "%d", &k)
	n, s := 2000, 2000 + k
	fmt.Printf("-1")
	for i := 1;i < n;i ++ {
		if s >= 1000000 {
			fmt.Printf(" 1000000")
			s -= 1000000
		} else {
			fmt.Printf(" %d", s)
			s = 0
		}
	}
}


package main

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

func z(arr *[]int, l int, r int) {
	if r == -1 {
		j := 1
		for i := l + 1; i < len((*arr)); i++ {
			(*arr)[i] = j
			j++
		}
	} else if l == -1 {
		j := 1
		for i := r - 1; i >= 0; i-- {
			(*arr)[i] = j
			j++
		}
	} else {
		tmp := (r - l) / 2
		for i := 1; i <= tmp; i++ {
			(*arr)[l+i] = i
			(*arr)[r-i] = i
		}
	}
}

func main() {
	var line string
	var n int
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	var zeropos []int
	line, _ = reader.ReadString('\n')
	n, _ = strconv.Atoi(strings.TrimSpace(line))
	answer := make([]int, n)
	line, _ = reader.ReadString('\n')
	for i, j := range strings.Split(strings.TrimSpace(line), " ") {
		if j == string('0') {
			zeropos = append(zeropos, i)
		}
	}
	z(&answer, -1, zeropos[0])
	z(&answer, zeropos[len(zeropos)-1], -1)
	if len(zeropos) > 1 {
		for i := 0; i < len(zeropos)-1; i++ {
			z(&answer, zeropos[i], zeropos[i+1])
		}
	}
	for _, j := range answer {
		writer.WriteString(strconv.Itoa(j) + " ")
	}
	writer.Flush()
}

package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	var n int
	for I(&n) == nil {
		solve(n)
	}
	w.Flush()
}

func solve(n int) {
	a := make([]int, n)
	b := make([]int, n)
	var z []int
	for i := range a {
		I(&a[i])
		if a[i] == 0 {
			z = append(z, i)
		}
	}
	for i := range a {
		f := sort.Search(len(z), func(o int) bool { return z[o] >= i })
		if f == 0 {
			b[i] = abs(z[0] - i)
		} else {
			if f != len(z) {
				t1 := abs(z[f-1] - i)
				t2 := abs(z[f] - i)
				b[i] = min(t1, t2)
			} else {
				b[i] = abs(z[f-1] - i)
			}
		}
	}
	for i := range b {
		O(b[i])
		if i != n-1 {
			O(" ")
		}
	}
	O("\n")
}

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

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

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	x := make([]int, n)
	r := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		x[i], _ = strconv.Atoi(scanner.Text())
	}

	if x[n-1] != 0 {
		r[n-1] = 1e6
	}
	for i := n - 2; i > -1; i-- {
		if x[i] == 0 {
			r[i] = 0
			continue
		}
		r[i] = r[i+1] + 1
	}

	l := int(1e6)
	for i := 0; i < n; i++ {
		l++
		if x[i] == 0 {
			l = 0
		}
		fmt.Printf("%d ", min(r[i], l))
	}
	fmt.Println()
}

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

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	x := make([]int, n)
	l := make([]int, n)
	r := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		x[i], _ = strconv.Atoi(scanner.Text())
	}

	if x[0] == 0 {
		l[0] = 0
	} else {
		l[0] = 1e6
	}
	for i := 1; i < n; i++ {
		if x[i] == 0 {
			l[i] = 0
			continue
		}
		l[i] = l[i-1] + 1
	}

	if x[n-1] == 0 {
		r[n-1] = 0
	} else {
		r[n-1] = 1e6
	}
	for i := n - 2; i >= 0; i-- {
		if x[i] == 0 {
			r[i] = 0
			continue
		}
		r[i] = r[i+1] + 1
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d ", min(l[i], r[i]))
	}
	fmt.Println()
}

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

package main

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

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

	var line string
	scanner := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 0, 13*200000)
	scanner.Buffer(buf, 13*200000)

	if scanner.Scan() {
		line = scanner.Text()
	}

	strList := strings.Split(line, " ")

	list := make([]int, n)
	for i := 0; i < n; i++ {
		list[i], _ = strconv.Atoi(strList[i])
	}

	var pos []int
	for i := 0; i < n; i++ {
		if list[i] == 0 {
			pos = append(pos, i)
		}
	}

	distance := make([]int, n)
	posIndex := 0
	posLen := len(pos)
	for i := 0; i < n; i++ {
		leftPos := pos[posIndex]
		var rightPos int
		if posIndex+1 < posLen {
			rightPos = pos[posIndex+1]
		} else {
			rightPos = leftPos
		}

		d1 := (int)(math.Abs((float64)(leftPos - i)))
		d2 := (int)(math.Abs((float64)(rightPos - i)))
		if d2 <= d1 {
			distance[i] = d2
			if posIndex+1 < posLen {
				posIndex++
			}
		} else {
			distance[i] = d1
		}
	}

	output := fmt.Sprint(distance)
	output = strings.Replace(output, "[", "", -1)
	output = strings.Replace(output, "]", "", -1)

	fmt.Println(output)
}

// Codeforces 803 B Distances to Zero
// doesn't work, need to count using binary intervals to speed up
package main

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

var in *bufio.Reader

func readFive() (int, int, int, int, int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i := 0; i < len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0], a[1], a[2], a[3], a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for j := 0; j < n; j++ {
		aa, err := strconv.Atoi(ss[j])
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[j] = aa
	}
	return a
}

var n int
var a []int
var d []int

func readData() {
	in = bufio.NewReader(os.Stdin)
	// read n, a
	n,_,_,_,_ = readFive()
	a = readLineNumbs(n)
}

func solve() {
	// calculating nv
	d = make([]int, n)
	// increase
	lastZero := -1
	for i:=0; i<n; i++ {
		if a[i]==0 {
			d[i] = 0
			lastZero = i
		} else {
			if lastZero >= 0 {
				d[i] = i - lastZero
			} else {
				d[i] = 100000000
			}
		}
	}
	// decrease
	lastZero = -1
	for i:=n-1; i>=0; i-- {
		if a[i]==0 {
			lastZero = i
		} else {
			if lastZero>=0 && (lastZero-i) < d[i] {
				d[i] = lastZero-i
			}
		}
	}
}

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

func main() {
	readData()
	solve()
	printRes()
}

package main

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

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

	var line string
	scanner := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 0, 13*200000)
	scanner.Buffer(buf, 13*200000)

	if scanner.Scan() {
		line = scanner.Text()
	}

	strList := strings.Split(line, " ")

	list := make([]int, n)
	for i := 0; i < n; i++ {
		list[i], _ = strconv.Atoi(strList[i])
	}

	pos := 0
	for i := 0; i < n; i++ {
		if list[i] == 0 {
			pos = i
			break
		}
	}

	distance := make([]int, n)
	for i := 0; i < n; i++ {
		if list[i] == 0 {
			pos = i
		}

		distance[i] = (int)(math.Abs((float64)(pos - i)))
	}

	output := fmt.Sprint(distance)
	output = strings.Replace(output, "[", "", -1)
	output = strings.Replace(output, "]", "", -1)

	fmt.Println(output)
}