To improve the boomerang throwing skills of the animals, Zookeeper has set up an $$$n \times n$$$ grid with some targets, where each row and each column has at most $$$2$$$ targets each. The rows are numbered from $$$1$$$ to $$$n$$$ from top to bottom, and the columns are numbered from $$$1$$$ to $$$n$$$ from left to right.  For each column, Zookeeper will throw a boomerang from the bottom of the column (below the grid) upwards. When the boomerang hits any target, it will bounce off, make a $$$90$$$ degree turn to the right and fly off in a straight line in its new direction. The boomerang can hit multiple targets and does not stop until it leaves the grid.   In the above example, $$$n=6$$$ and the black crosses are the targets. The boomerang in column $$$1$$$ (blue arrows) bounces $$$2$$$ times while the boomerang in column $$$3$$$ (red arrows) bounces $$$3$$$ times. The boomerang in column $$$i$$$ hits exactly $$$a_i$$$ targets before flying out of the grid. It is known that $$$a_i \leq 3$$$.However, Zookeeper has lost the original positions of the targets. Thus, he asks you to construct a valid configuration of targets that matches the number of hits for each column, or tell him that no such configuration exists. If multiple valid configurations exist, you may print any of them.

The first line contains a single integer $$$n$$$ $$$(1 \leq n \leq 10^5)$$$.  The next line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ $$$(0 \leq a_i \leq 3)$$$.

If no configuration of targets exist, print $$$-1$$$.  Otherwise, on the first line print a single integer $$$t$$$ $$$(0 \leq t \leq 2n)$$$: the number of targets in your configuration.   Then print $$$t$$$ lines with two spaced integers each per line. Each line should contain two integers $$$r$$$ and $$$c$$$ $$$(1 \leq r,c \leq n)$$$, where $$$r$$$ is the target's row and $$$c$$$ is the target's column. All targets should be different.   Every row and every column in your configuration should have at most two targets each.

NoteFor the first test, the answer configuration is the same as in the picture from the statement. For the second test, the boomerang is not supposed to hit anything, so we can place $$$0$$$ targets. For the third test, the following configuration of targets matches the number of hits, but is not allowed as row $$$3$$$ has $$$4$$$ targets.   It can be shown for this test case that no valid configuration of targets will result in the given number of target hits.

package main

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

func main() {
	defer _w.Flush()
	n := ReadInt()
	a := ReadInts(n)
	solve(n, a)
}

func solve(n int, a []int) {
	next := 0
	canPair := make([]bool, n)
	unpairedOnes := make([][]int, 0)
	ans := make([]string, 0)
	for i := n - 1; i >= 0; i-- {
		if a[i] == 0 {
			continue
		}
		if a[i] == 1 {
			if next == n {
				Println(-1)
				return
			}
			ans = append(ans, fmt.Sprintf("%d %d", n-next, i+1))
			canPair[i] = true
			unpairedOnes = append(unpairedOnes, []int{i, next})
			next++
			continue
		}
		if a[i] == 2 {
			for {
				if len(unpairedOnes) == 0 {
					Println(-1)
					return
				}
				id, _ := unpairedOnes[0][0], unpairedOnes[0][1]
				if !canPair[id] {
					unpairedOnes = unpairedOnes[1:]
					continue
				}
				break
			}
			id, u := unpairedOnes[0][0], unpairedOnes[0][1]
			canPair[id] = true
			unpairedOnes = unpairedOnes[1:]
			ans = append(ans, fmt.Sprintf("%d %d", n-u, i+1))
			canPair[i] = true
			continue
		}
		if a[i] == 3 {
			ok := false
			for j := i + 1; j < n; j++ {
				if canPair[j] {
					ans = append(ans, fmt.Sprintf("%d %d", n-next, i+1))
					ans = append(ans, fmt.Sprintf("%d %d", n-next, j+1))
					canPair[j] = false
					ok = true
					break
				}
			}
			canPair[i] = true
			next++
			if !ok {
				Println(-1)
				return
			}
		}
	}

	Println(len(ans))
	for i := 0; i < len(ans); i++ {
		Println(ans[i])
	}
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func Print(a ...interface{})            { fmt.Fprint(_w, a...) }
func Printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func Println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

/*
URL:
https://codeforces.com/contest/1428/problem/D
*/

package main

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

var (
	n int
	A []int

	B [5][]int
	C []int
	N []int
)

func main() {
	defer stdout.Flush()

	n = readi()
	A = readis(n)

	for i := 0; i < n; i++ {
		B[A[i]] = append(B[A[i]], i)
	}
	C = make([]int, n)
	for i := 0; i < n; i++ {
		C[i] = -1
	}
	for i := 0; i < n; i++ {
		// 現在のカラムID以下のものはマッチング対象から除外する
		for j := 0; j <= 3; j++ {
			for len(B[j]) > 0 {
				if B[j][0] <= i {
					B[j] = B[j][1:]
				} else {
					break
				}
			}
		}

		if A[i] == 3 {
			// 3,2,1の順で優先的に使う
			if len(B[3]) > 0 {
				C[i] = B[3][0]
				B[3] = B[3][1:]
			} else if len(B[2]) > 0 {
				C[i] = B[2][0]
				B[2] = B[2][1:]
			} else if len(B[1]) > 0 {
				C[i] = B[1][0]
				B[1] = B[1][1:]
			} else {
				// マッチング出来なかったら終了
				fmt.Println(-1)
				return
			}
		} else if A[i] == 2 {
			if len(B[1]) > 0 {
				C[i] = B[1][0]
				B[1] = B[1][1:]
			} else {
				// マッチング出来なかったら終了
				fmt.Println(-1)
				return
			}
		}
	}

	N = make([]int, n)
	ans := [][2]int{}
	for i := 0; i < n; i++ {
		if A[i] == 0 {
			continue
		}
		if A[i] == 1 {
			if N[i] == 0 {
				N[i]++
				ans = append(ans, [2]int{i + 1, i + 1})
			}
			continue
		}

		if A[i] == 2 {
			if N[i] == 0 {
				N[i]++
				ans = append(ans, [2]int{i + 1, i + 1})
			}

			tid := C[i]
			N[tid]++
			ans = append(ans, [2]int{i + 1, tid + 1})

			continue
		}

		if N[i] == 0 {
			N[i]++
			ans = append(ans, [2]int{i + 1, i + 1})
		}
		tid := C[i]
		N[tid] += 2
		ans = append(ans, [2]int{i + 1, tid + 1})
		// ans = append(ans, [2]int{i + 2, tid + 1})
		ans = append(ans, [2]int{tid + 1, tid + 1})
	}

	printf("%d\n", len(ans))
	for _, P := range ans {
		printf("%d %d\n", P[0], P[1])
	}
}

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

/********** 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
	EPS     = 1e-10
)

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

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

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

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

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

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

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

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

	return s
}

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

var reader = bufio.NewReader(os.Stdin)

type target struct {
	x, y int
}

func main() {
	var n int
	fmt.Fscan(reader, &n)

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

	var targets []target
	var ones []target
	var rest []target
	for i := n - 1; i >= 0; i-- {
		if a[i] == 0 {
			continue
		}

		t := target{i, i}

		if a[i] == 1 {
			targets = append(targets, t)
			ones = append(ones, t)
		} else if a[i] == 2 {
			if len(ones) == 0 {
				fmt.Println(-1)
				return
			}

			one := ones[0]
			ones = ones[1:]

			targets = append(targets, target{i, one.y})
			rest = append(rest, target{i, one.y})
		} else if a[i] == 3 {
			if len(ones) == 0 && len(rest) == 0 {
				fmt.Println(-1)
				return
			}

			var prev target
			if len(rest) == 0 {
				prev = ones[0]
				ones = ones[1:]
			} else {
				prev = rest[0]
				rest = rest[1:]
			}

			targets = append(targets, target{i, i})
			targets = append(targets, target{prev.x, i})
			rest = append(rest, target{i, i})
		}
	}

	fmt.Println(len(targets))
	for _, t := range targets {
		fmt.Println(t.y+1, t.x+1)
	}
}

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	ans := make([][2]int, 0)
	index := make([][]int, 3)
	for i := n - 1; i >= 0; i-- {
		switch aa[i] {
		case 1:
			ans = append(ans, [2]int{i + 1, i + 1})
			index[0] = append(index[0], i)
		case 2:
			if len(index[0]) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{index[0][0] + 1, i + 1})
			index[0] = index[0][1:]
			index[1] = append(index[1], i)
		case 3:
			ans = append(ans, [2]int{i + 1, i + 1})
			c := func() int {
				for j := 2; j >= 0; j-- {
					if len(index[j]) > 0 {
						x := index[j][0]
						index[j] = index[j][1:]
						return x
					}
				}
				return -1
			}()
			if c == -1 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{i + 1, c + 1})
			index[2] = append(index[2], i)
		}
	}
	fmt.Fprintln(writer, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}

package main

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

func main() {
	defer _w.Flush()
	n := ReadInt()
	a := ReadInts(n)
	solve(n, a)
}

func solve(n int, a []int) {
	next := 0
	canPair := make([]bool, n)
	unpairedOnes := make([][]int, 0)
	ans := make([][]int, 0)
	for i := n - 1; i >= 0; i-- {
		if a[i] == 0 {
			continue
		}
		if a[i] == 1 {
			if next == n {
				Println(-1)
				return
			}
			ans = append(ans, []int{i, next})
			canPair[i] = true
			unpairedOnes = append(unpairedOnes, []int{i, next})
			next++
			continue
		}
		if a[i] == 2 {
			for {
				if len(unpairedOnes) == 0 {
					Println(-1)
					return
				}
				id, _ := unpairedOnes[0][0], unpairedOnes[0][1]
				if !canPair[id] {
					unpairedOnes = unpairedOnes[1:]
					continue
				}
				break
			}
			id, u := unpairedOnes[0][0], unpairedOnes[0][1]
			canPair[id] = true
			unpairedOnes = unpairedOnes[1:]
			ans = append(ans, []int{i, u})
			canPair[i] = true
			continue
		}
		if a[i] == 3 {
			ok := false
			for j := i + 1; j < n; j++ {
				if canPair[j] {
					ans = append(ans, []int{i, next})
					ans = append(ans, []int{j, next})
					canPair[j] = false
					ok = true
					break
				}
			}
			canPair[i] = true
			if !ok {
				Println(-1)
				return
			}
		}
	}

	Println(len(ans))
	for i := 0; i < len(ans); i++ {
		Println(n-ans[i][1]-1, ans[i][0]+1)
	}
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func Print(a ...interface{})            { fmt.Fprint(_w, a...) }
func Printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func Println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

func main() {
	defer _w.Flush()
	n := ReadInt()
	a := ReadInts(n)
	solve(n, a)
}

func solve(n int, a []int) {
	next := 0
	canPair := make([]bool, n)
	unpairedOnes := make([][]int, 0)
	ans := make([]string, 0)
	for i := n - 1; i >= 0; i-- {
		if a[i] == 0 {
			continue
		}
		if a[i] == 1 {
			if next == n {
				Println(-1)
				return
			}
			ans = append(ans, fmt.Sprintf("%d %d", n-next, i+1))
			canPair[i] = true
			unpairedOnes = append(unpairedOnes, []int{i, next})
			next++
			continue
		}
		if a[i] == 2 {
			for {
				if len(unpairedOnes) == 0 {
					Println(-1)
					return
				}
				id, _ := unpairedOnes[0][0], unpairedOnes[0][1]
				if !canPair[id] {
					unpairedOnes = unpairedOnes[1:]
					continue
				}
				break
			}
			id, u := unpairedOnes[0][0], unpairedOnes[0][1]
			canPair[id] = true
			unpairedOnes = unpairedOnes[1:]
			ans = append(ans, fmt.Sprintf("%d %d", n-u, i+1))
			canPair[i] = true
			continue
		}
		if a[i] == 3 {
			ok := false
			for j := i + 1; j < n; j++ {
				if canPair[j] {
					ans = append(ans, fmt.Sprintf("%d %d", n-next, i+1))
					ans = append(ans, fmt.Sprintf("%d %d", n-next, j+1))
					canPair[j] = false
					ok = true
					break
				}
			}
			canPair[i] = true
			if !ok {
				Println(-1)
				return
			}
		}
	}

	Println(len(ans))
	for i := 0; i < len(ans); i++ {
		Println(ans[i])
	}
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func Print(a ...interface{})            { fmt.Fprint(_w, a...) }
func Printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func Println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

/*
URL:
https://codeforces.com/contest/1428/problem/D
*/

package main

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

var (
	n int
	A []int

	B [5][]int
	C []int
	N []int
)

func main() {
	defer stdout.Flush()

	n = readi()
	A = readis(n)

	for i := 0; i < n; i++ {
		B[A[i]] = append(B[A[i]], i)
	}
	C = make([]int, n)
	for i := 0; i < n; i++ {
		C[i] = -1
	}
	for i := 0; i < n; i++ {
		// 現在のカラムID以下のものはマッチング対象から除外する
		for j := 0; j <= 3; j++ {
			for len(B[j]) > 0 {
				if B[j][0] <= i {
					B[j] = B[j][1:]
				} else {
					break
				}
			}
		}

		if A[i] == 3 {
			// 2の列を優先的に使う
			if len(B[2]) > 0 {
				C[i] = B[2][0]
				B[2] = B[2][1:]
			} else if len(B[1]) > 0 {
				C[i] = B[1][0]
				B[1] = B[1][1:]
			} else {
				// マッチング出来なかったら終了
				fmt.Println(-1)
				return
			}
		} else if A[i] == 2 {
			if len(B[1]) > 0 {
				C[i] = B[1][0]
				B[1] = B[1][1:]
			} else {
				// マッチング出来なかったら終了
				fmt.Println(-1)
				return
			}
		}
	}

	N = make([]int, n)
	ans := [][2]int{}
	for i := 0; i < n; i++ {
		if A[i] == 0 {
			continue
		}
		if A[i] == 1 {
			if N[i] == 0 {
				N[i]++
				ans = append(ans, [2]int{i + 1, i + 1})
			}
			continue
		}

		if A[i] == 2 {
			if N[i] == 0 {
				N[i]++
				ans = append(ans, [2]int{i + 1, i + 1})
			}

			tid := C[i]
			N[tid]++
			ans = append(ans, [2]int{i + 1, tid + 1})

			continue
		}

		if N[i] == 0 {
			N[i]++
			ans = append(ans, [2]int{i + 1, i + 1})
		}
		tid := C[i]
		N[tid] += 2
		ans = append(ans, [2]int{i + 1, tid + 1})
		ans = append(ans, [2]int{i + 2, tid + 1})
	}

	printf("%d\n", len(ans))
	for _, P := range ans {
		printf("%d %d\n", P[0], P[1])
	}
}

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

/********** 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
	EPS     = 1e-10
)

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

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

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

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

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

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

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

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

	return s
}

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

var reader = bufio.NewReader(os.Stdin)

type target struct {
	x, y int
}

func main() {
	var n int
	fmt.Fscan(reader, &n)

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

	var targets []target
	var ones []target
	var rest []target
	for i := n - 1; i >= 0; i-- {
		if a[i] == 0 {
			continue
		}

		t := target{i, i}

		if a[i] == 1 {
			targets = append(targets, t)
			ones = append(ones, t)
			continue
		}

		if a[i] == 2 {
			if len(ones) == 0 {
				fmt.Println(-1)
				return
			}

			one := ones[0]
			ones = ones[1:]

			targets = append(targets, target{i, one.y})
			rest = append(rest, target{i, one.y})
			continue
		}

		if a[i] == 3 {
			if len(ones) == 0 && len(rest) == 0 {
				fmt.Println(-1)
				return
			}

			var prev target
			if len(rest) == 0 {
				prev = ones[0]
				ones = ones[1:]
			} else {
				prev = rest[0]
				rest = rest[1:]
			}

			targets = append(targets, target{i, i})
			targets = append(targets, target{prev.x, i})
			rest = append(rest, target{i, i})
		}
	}

	fmt.Println(len(targets))
	for _, t := range targets {
		fmt.Println(t.x+1, t.y+1)
	}
}

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	enablev := make([]int, 0)
	enableh := make([]int, 0)
	ans := make([][2]int, 0)
	r := n
	for i := n - 1; i >= 0; i-- {
		if aa[i] == 0 {
			continue
		}
		if aa[i] == 1 {
			ans = append(ans, [2]int{r, i + 1})
			enablev = append(enablev, r)
			enableh = append(enableh, i)
			r--
			continue
		}
		if aa[i] == 3 {
			if len(enableh) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{r, i + 1})
			ans = append(ans, [2]int{r, enableh[0] + 1})
			r--
			enableh = enableh[1:]
			if len(enablev) > 0 {
				enablev = enablev[1:]
			}
			continue
		}
		if len(enablev) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		ans = append(ans, [2]int{enablev[0], i + 1})
		enablev = enablev[1:]
		enableh = append(enableh, i)
	}
	fmt.Fprintln(writer, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	enablev := make([]int, 0)
	enableh := make([]int, 0)
	ans := make([][2]int, 0)
	r := n
	for i := n - 1; i >= 0; i-- {
		if aa[i] == 0 {
			continue
		}
		enableh = append(enableh, i)
		if aa[i] == 1 {
			ans = append(ans, [2]int{r, i + 1})
			enablev = append(enablev, r)
			r--
			continue
		}
		if aa[i] == 3 {
			if len(enableh) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{r, i + 1})
			ans = append(ans, [2]int{r, enableh[0] + 1})
			r--
			enableh = enableh[1:]
			if len(enablev) > 0 {
				enablev = enablev[1:]
			}
			continue
		}
		if len(enablev) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		ans = append(ans, [2]int{enablev[0], i + 1})
		enablev = enablev[1:]
		if len(enableh) > 0 {
			enableh = enableh[1:]
		}
	}
	fmt.Fprintln(writer, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	enablev := make([]int, 0)
	enableh := make([]int, 0)
	ans := make([][2]int, 0)
	r := n
	for i := n - 1; i >= 0; i-- {
		if aa[i] == 0 {
			continue
		}
		if aa[i] == 1 {
			ans = append(ans, [2]int{r, i + 1})
			enablev = append(enablev, r)
			enableh = append(enableh, i)
			r--
			continue
		}
		if aa[i] == 3 {
			if len(enableh) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{r, i + 1})
			ans = append(ans, [2]int{r, enableh[0] + 1})
			r--
			enableh = enableh[1:]
			continue
		}
		if len(enableh) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		if len(enablev) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		ans = append(ans, [2]int{enablev[0], i + 1})
		enableh = enableh[1:]
		enablev = enablev[1:]
		enableh = append(enableh, i)
	}
	fmt.Fprintln(writer, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	enablev := make([]int, 0)
	enableh := make([]int, 0)
	ans := make([][2]int, 0)
	for i := n - 1; i >= 0; i-- {
		if aa[i] == 0 {
			continue
		}
		if aa[i] == 1 {
			ans = append(ans, [2]int{i + 1, i + 1})
			enablev = append(enablev, i)
			enableh = append(enableh, i)
			continue
		}
		if aa[i] == 3 {
			if len(enableh) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{i + 1, i + 1})
			ans = append(ans, [2]int{i + 1, enableh[0] + 1})
			enableh = enableh[1:]
			continue
		}
		if len(enablev) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		ans = append(ans, [2]int{enablev[0] + 1, i + 1})
		enablev = enablev[1:]
	}
	fmt.Fprintln(writer, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	enablev := make([]int, 0)
	enableh := make([]int, 0)
	ans := make([][2]int, 0)
	r := n
	for i := n - 1; i >= 0; i-- {
		if aa[i] == 0 {
			continue
		}
		if aa[i] == 1 {
			ans = append(ans, [2]int{r, i + 1})
			enablev = append(enablev, r)
			enableh = append(enableh, i)
			r--
			continue
		}
		if aa[i] == 3 {
			if len(enableh) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			if len(enablev) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{r, i + 1})
			ans = append(ans, [2]int{r, enableh[0] + 1})
			r--
			enableh = enableh[1:]
			enablev = enablev[1:]
			continue
		}
		if len(enablev) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		ans = append(ans, [2]int{enablev[0], i + 1})
		enablev = enablev[1:]
	}
	fmt.Fprintln(writer, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	enablev := make([]int, 0)
	enableh := make([]int, 0)
	ans := make([][2]int, 0)
	r := n
	for i := n - 1; i >= 0; i-- {
		if aa[i] == 0 {
			continue
		}
		enablev = append(enablev, r)
		enableh = append(enableh, i)
		if aa[i] == 1 {
			ans = append(ans, [2]int{r, i + 1})
			r--
			continue
		}
		if aa[i] == 3 {
			if len(enableh) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{r, i + 1})
			ans = append(ans, [2]int{r, enableh[0] + 1})
			r--
			enableh = enableh[1:]
			if len(enablev) > 0 {
				enablev = enablev[1:]
			}
			continue
		}
		if len(enablev) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		ans = append(ans, [2]int{enablev[0], i + 1})
		enablev = enablev[1:]
		if len(enableh) > 0 {
			enableh = enableh[1:]
		}
	}
	fmt.Fprintln(writer, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	enablev := make([]int, 0)
	enableh := make([]int, 0)
	ans := make([][2]int, 0)
	r := n - 1
	for i := n - 1; i >= 0; i-- {
		if aa[i] == 0 {
			continue
		}
		if r == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		if aa[i] == 1 {
			ans = append(ans, [2]int{r, i + 1})
			enablev = append(enablev, r)
			enableh = append(enableh, i)
			r--
			continue
		}
		if aa[i] == 3 {
			if len(enableh) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{r, i + 1})
			ans = append(ans, [2]int{r, enableh[0] + 1})
			r--
			enableh = enableh[1:]
			continue
		}
		if len(enablev) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		ans = append(ans, [2]int{enablev[0], i + 1})
		enablev = enablev[1:]
	}
	fmt.Fprintln(writer, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	enablev := make([]int, 0)
	enableh := make([]int, 0)
	ans := make([][2]int, 0)
	r := n
	for i := n - 1; i >= 0; i-- {
		if aa[i] == 0 {
			continue
		}
		if aa[i] == 1 {
			ans = append(ans, [2]int{r, i + 1})
			enablev = append(enablev, r)
			enableh = append(enableh, i)
			r--
			continue
		}
		if aa[i] == 3 {
			if len(enableh) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{r, i + 1})
			ans = append(ans, [2]int{r, enableh[0] + 1})
			r--
			enableh = enableh[1:]
			if len(enablev) > 0 {
				enablev = enablev[1:]
			}
			continue
		}
		if len(enablev) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		ans = append(ans, [2]int{enablev[0], i + 1})
		enablev = enablev[1:]
		if len(enableh) > 0 {
			enableh = enableh[1:]
		}
		enableh = append(enableh, i)
	}
	fmt.Fprintln(writer, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	enablev := make([]int, 0)
	enableh := make([]int, 0)
	ans := make([][2]int, 0)
	r := n - 1
	for i := n - 1; i >= 0; i-- {
		if aa[i] == 0 {
			continue
		}
		if r == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		if aa[i] == 1 {
			ans = append(ans, [2]int{r, i + 1})
			enablev = append(enablev, r)
			enableh = append(enableh, i)
			r--
			continue
		}
		if aa[i] == 3 {
			if len(enableh) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{r, i + 1})
			ans = append(ans, [2]int{r, enableh[0] + 1})
			r--
			enableh = enableh[1:]
			continue
		}
		if len(enablev) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		ans = append(ans, [2]int{enablev[0], i + 1})
		enablev = enablev[1:]
	}
	fmt.Fprintln(writer, len(ans))
	sort.Slice(ans, func(i, j int) bool {
		if ans[i][0] == ans[j][0] {
			return ans[i][1] < ans[j][1]
		}
		return ans[i][0] < ans[j][0]
	})
	for i := 0; i < len(ans); i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}


You are given a set Y of n distinct positive integers y1, y2, ..., yn.Set X of n distinct positive integers x1, x2, ..., xn is said to generate set Y if one can transform X to Y by applying some number of the following two operation to integers in X:  Take any integer xi and multiply it by two, i.e. replace xi with 2·xi.  Take any integer xi, multiply it by two and add one, i.e. replace xi with 2·xi + 1. Note that integers in X are not required to be distinct after each operation.Two sets of distinct integers X and Y are equal if they are equal as sets. In other words, if we write elements of the sets in the array in the increasing order, these arrays would be equal.Note, that any set of integers (or its permutation) generates itself.You are given a set Y and have to find a set X that generates Y and the maximum element of X is mininum possible.

The first line of the input contains a single integer n (1 ≤ n ≤ 50 000) — the number of elements in Y. The second line contains n integers y1, ..., yn (1 ≤ yi ≤ 109), that are guaranteed to be distinct.

Print n integers — set of distinct integers that generate Y and the maximum element of which is minimum possible. If there are several such sets, print any of them.

package main

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

func I(t interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, t)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

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

type Node struct {
	Left  *Node
	Value int64
	Index int
	Right *Node
}

func insert(node *Node, value int64, index int) *Node {
	if node == nil {
		return &Node{nil, value, index, nil}
	}
	if node.Value > value {
		node.Left = insert(node.Left, value, index)
		return node
	}
	node.Right = insert(node.Right, value, index)
	return node
}

func max(node *Node) *Node {
	if node == nil || node.Right == nil || node.Right.Index == -1 {
		return node
	}
	return max(node.Right)
}

func search(node *Node, value int64) *Node {
	if node == nil {
		return nil
	}
	if node.Value == value {
		return node
	}
	if node.Value > value {
		return search(node.Left, value)
	}
	return search(node.Right, value)
}

func deleteMax(node *Node) {
	node = max(node)
	if node.Left == nil {
		*node = Node{nil, -1, -1, nil}
	} else {
		*node = *node.Left
	}
}

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

	var node *Node
	var n int
	I(&n, "\n")
	y := make([]int64, n)
	for i := 0; i < n; i++ {
		I(&y[i], " ")
		node = insert(node, y[i], i)
	}
	count := n
	for count > 0 {
		maxNode := max(node)
		for i := maxNode.Value; i >= 1; i /= 2 {
			f := search(node, i)
			if f == nil {
				node = insert(node, i, maxNode.Index)
				deleteMax(node)
				count++
				break
			}
		}
		count--
	}
	for node.Index != -1 {
		O(max(node).Value, " ")
		deleteMax(node)
	}
}

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

type Node struct {
	value int
	index int
}

type NodeList []*Node

func (nodes NodeList) Len() int {
	return len(nodes)
}

func (nodes NodeList) Less(i int, j int) bool {
	return nodes[i].value > nodes[j].value
}

func (nodes NodeList) Swap(i int, j int) {
	nodes[i], nodes[j] = nodes[j], nodes[i]
	nodes[i].index = i
	nodes[j].index = j
}

func (nodes *NodeList) Push(x interface{}) {
	node := x.(*Node)
	node.index = len(*nodes)
	*nodes = append(*nodes, node)
}

func (nodes *NodeList) Pop() interface{} {
	s := *nodes
	last := len(s) - 1
	r := s[last]
	*nodes = s[:last]
	r.index = -1
	return r
}

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	var n int
	fmt.Fscanf(bufin, "%d\n", &n)

	var h NodeList
	var y int

	has := make(map[int]bool)
	for i := 0; i < n; i++ {
		fmt.Fscanf(bufin, "%d\n", &y)
		heap.Push(&h, &Node{value: y})
		has[y] = true
	}

	for h.Len() > 0 {
		node := heap.Pop(&h).(*Node)
		y = node.value
		has[y] = false
		x := y
		for y >= 2 {
			y /= 2
			if has[y] == false {
				x = y
				break
			}
		}
		has[x] = true
		heap.Push(&h, &Node{value: x})
		if x == node.value {
			break
		}
	}

	for h.Len() > 0 {
		node := heap.Pop(&h).(*Node)
		fmt.Fprintf(bufout, "%d ", node.value)
	}
	fmt.Fprintf(bufout, "\n")
}

package main

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

func I(t interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, t)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

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

type Node struct {
	Left  *Node
	Value int64
	Index int
	Right *Node
}

func insert(node *Node, value int64, index int) *Node {
	if node == nil {
		return &Node{nil, value, index, nil}
	}
	if node.Value > value {
		node.Left = insert(node.Left, value, index)
		return node
	}
	node.Right = insert(node.Right, value, index)
	return node
}

func max(node *Node) *Node {
	if node == nil || node.Right == nil || node.Right.Index == -1 {
		return node
	}
	return max(node.Right)
}

func search(node *Node, value int64) *Node {
	if node == nil {
		return nil
	}
	if node.Value == value {
		return node
	}
	if node.Value > value {
		return search(node.Left, value)
	}
	return search(node.Right, value)
}

func deleteMax(node *Node) {
	node = max(node)
	if node.Left == nil {
		*node = Node{nil, -1, -1, nil}
	} else {
		*node = *node.Left
	}
}

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

	var node *Node
	var n int
	I(&n, "\n")
	y := make([]int64, n)
	for i := 0; i < n; i++ {
		I(&y[i], " ")
		node = insert(node, y[i], i)
	}
	count := n
	for count > 0 {
		maxNode := max(node)
		for i := maxNode.Value; i >= 1; i /= 2 {
			f := search(node, i)
			if f == nil {
				idx := maxNode.Index
				deleteMax(node)
				node = insert(node, i, idx)
				count++
				break
			}
		}
		count--
	}
	for node.Index != -1 {
		O(max(node).Value, " ")
		deleteMax(node)
	}
}


You are given an array $$$a$$$ consisting of $$$n$$$ integers. You want to distribute these $$$n$$$ integers into two groups $$$s_1$$$ and $$$s_2$$$ (groups can be empty) so that the following conditions are satisfied:  For each $$$i$$$ $$$(1 \leq i \leq n)$$$, $$$a_i$$$ goes into exactly one group. The value $$$|sum(s_1)| - |sum(s_2)|$$$ is the maximum possible among all such ways to distribute the integers.Here $$$sum(s_1)$$$ denotes the sum of the numbers in the group $$$s_1$$$, and $$$sum(s_2)$$$ denotes the sum of the numbers in the group $$$s_2$$$.Determine the maximum possible value of $$$|sum(s_1)| - |sum(s_2)|$$$.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 2 \cdot 10^4)$$$  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 10^5)$$$  — the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2 \ldots a_n$$$ $$$(-10^9 \leq a_i \leq 10^9)$$$  — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.

For each test case, output a single integer  — the maximum possible value of $$$|sum(s_1)| - |sum(s_2)|$$$.

package main

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

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

	defer writer.Flush()

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

	for ; t > 0; t-- {
		var n int
		fmt.Fscan(reader, &n)

		var ans int64
		for ; n > 0; n-- {
			var x int64
			fmt.Fscan(reader, &x)
			ans += x
		}

		if ans < 0 {
			fmt.Fprintln(writer, -ans)
		} else {
			fmt.Fprintln(writer, ans)
		}
	}
}

package main

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

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

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

	for ; t > 0; t-- {
		var n int
		fmt.Fscan(reader, &n)

		var ans int64
		for ; n > 0; n-- {
			var x int64
			fmt.Fscan(reader, &x)
			ans += x
		}

		if ans < 0 {
			fmt.Println(-ans)
		} else {
			fmt.Println(ans)
		}
	}
}

package main

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

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

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

	for ; t > 0; t-- {
		var n int
		fmt.Fscan(reader, &n)

		var ans int64
		for ; n > 0; n-- {
			var x int64
			fmt.Fscan(reader, &x)
			ans += x
		}

		fmt.Println(int64(math.Abs(float64(ans))))
	}
}

package main

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

func main() {
	var n int
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)

	defer writer.Flush()
	fmt.Fscan(reader, &n)
	for i := 0; i < n; i++ {
		var qn int
		fmt.Fscan(reader, &qn)
		var gr1 int64
		var gr2 int64
		var x int64
		gr1 = 0
		gr2 = 0
		for j := 0; j < qn; j++ {
			fmt.Fscan(reader, &x)
			if x > 0 {
				gr1 += x
			} else {
				gr2 -= x
			}
		}
		s := gr1 - gr2
		if s < 0 {
			s = -s
		}
		fmt.Fprintln(writer, s)
	}
}

package main

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

func main() {
	var testCases int

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

	defer writer.Flush()
	fmt.Fscan(reader, &testCases)

	for testCase := 1; testCase <= testCases; testCase++ {

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

		// nSum := 0
		var sum int64
		for i := 0; i < n; i++ {
			var jj int64
			fmt.Fscan(reader, &jj)

			sum += jj
			// if jj < 0 {
			// } else {
			// 	pSum += (jj)
			// }
		}

		// d := math.Abs(math.Abs(float64(nSum)) - math.Abs(float64(pSum)))

		fmt.Fprintln(writer, int64(math.Abs(float64(sum))))
	}
}

package main
// github.com/jamesgrimard/codeforces
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 int
		fmt.Fscan(in,&n)
		var largest,smallest int
		for j:=0;j<n;j++{
			var x int
			fmt.Fscan(in,&x)
			if x < 0 {
				smallest+=x
				continue
			}
			largest+=x
		}
		fmt.Fprintln(out, abs(abs(largest)-abs(smallest)))
	}
}
func abs(x int) int {
	if x<0{
		return x*-1
	}
	return x
}

package main

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

var (
	tot int64
)

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int64) {
		in.Scan()
		t := in.Bytes()
		if t[0] == '-' {
			for _, b := range t[1:] {
				x = x*10 + int64(b&15)
			}
			return -x
		}
		for _, b := range t {
			x = x*10 + int64(b&15)
		}
		return
	}
	tot = read()
	for i := int64(1); i <= tot; i++ {
		l := read()
		var sum int64 = 0
		for j := int64(1); j <= l; j++ {
			sum += read()
		}
		Fprintln(out, abs(sum))
	}
}

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

package main

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

var (
	tot int64
)

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

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int64) {
		in.Scan()
		t := in.Bytes()
		if t[0] == '-' {
			for _, b := range t[1:] {
				x = x*10 + int64(b&15)
			}
			return -x
		}
		for _, b := range t {
			x = x*10 + int64(b&15)
		}
		return
	}
	tot = read()
	for i := int64(1); i <= tot; i++ {
		l := read()
		var s1, s2 int64 = 0, 0
		for j := int64(1); j <= l; j++ {
			if t := read(); t < 0 {
				s1 -= t
			} else {
				s2 += t
			}
		}
		Fprintln(out, abs(s1-s2))
	}
}

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

package main

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

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

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

	return num
}

func sol(nums []int) int {
	sort.Ints(nums)
	sumLeft, sumRight :=  nums[len(nums) - 1], 0
	for i := len(nums) -2; i >= 0; i --{
		if absInt(sumLeft + nums[i]) > absInt(sumRight + nums[i]) {
			sumLeft += nums[i]
		} else {
			sumRight += nums[i]
		}
	}

	return absInt(absInt(sumLeft) - absInt(sumRight))
}

func main() {
	writer.Flush()
	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for t > 0 {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		nums := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &nums[i])
		}
		fmt.Fscanf(reader, "\n")
		fmt.Println(sol(nums))
		t--
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t, n int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var po, ne int64
		fmt.Fscan(in, &n)
		for j := 0; j < n; j++ {
			var x int64
			fmt.Fscan(in, &x)
			if x >= 0 {
				po += x
			} else {
				ne += x
			}
		}
		ne *= -1
		if po > ne {
			fmt.Println(po - ne)
		} else {
			fmt.Println(ne - po)
		}
	}
}

package main

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

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

//void find_min_diff( uint32_t sum_heap1 = 0, uint32_t sum_heap2 = 0, uint8_t i = 0 )
//{
//if (i != size)
//{
//find_min_diff(sum_heap1 + rocks[i], sum_heap2, i + 1);
//find_min_diff(sum_heap1, sum_heap2 + rocks[i], i + 1);
//}
//else
//min_diff = min_diff < sum_heap1 - sum_heap2 ? min_diff : sum_heap1 - sum_heap2;
//}

func solve() {
	_, arr := _readArr()
	s1, s2 := 0, 0
	sort.Ints(arr)
	for _, x := range arr {
		if _abs(s1+x)-s2 > s1-_abs(s2+x) {
			s1 += x
		} else {
			s2 += x
		}
	}

	_print(_abs(s1 - s2))
}

//func solve() {
//	n, arr := _readArr()
//	res := math.MinInt
//	var util func(s1, s2, i int)
//	util = func(s1, s2, i int) {
//		if i != n {
//			util(s1+arr[i], s2, i+1)
//			util(s1, s2+arr[i], i+1)
//		} else {
//			if x := _abs(s1) - _abs(s2); res < x {
//				res = x
//			}
//		}
//	}
//	util(0, 0, 0)
//	_print(res)
//}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		solve()
	}
}

// ====
func _readInt() int {
	var x int
	fmt.Fscan(in, &x)
	return x
}
func _readStr() string {
	var x string
	fmt.Fscan(in, &x)
	return x
}
func _readArr(x ...int) (int, []int) {
	var n int
	if len(x) == 0 {
		fmt.Fscan(in, &n)
	} else {
		n = x[0]
	}
	var v = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &v[i])
	}
	return n, v
}
func _print(x ...any) {
	fmt.Fprintln(out, x...)
}
func _max(x ...int) int {
	mi := 0
	for i := 1; i < len(x); i++ {
		if x[i] > x[mi] {
			mi = i
		}
	}
	return x[mi]
}
func _min(x ...int) int {
	mi := 0
	for i := 1; i < len(x); i++ {
		if x[i] < x[mi] {
			mi = i
		}
	}
	return x[mi]
}
func _sum(x ...int) int {
	res := 0
	for _, i := range x {
		res += i
	}
	return res
}
func _abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func _sortStr(x string) string {
	r := []rune(x)
	sort.Slice(r, func(i, j int) bool {
		return r[i] < r[j]
	})
	return string(r)
}
func _reverseInts(x []int) {
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
}
func _reverseStr(s string) string {
	x := []rune(s)
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
	return string(x)
}
func _makeMatrix(n, m int) [][]int {
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, m)
	}
	return x
}

package main

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

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

func (in *CF1747A) 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 *CF1747A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1747A
Date: 5/11/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1747/A
Problem: CF1747A
**/
func (in *CF1747A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		pos := 0
		neg := 0
		all := 0
		for i := 0; i < n; i++ {
			val := in.NextInt()
			if val > 0 {
				pos += val
			} else {
				neg += val
			}
			all += val
		}

		max := int(math.Max(float64(all), math.Min(-float64(neg)-float64(pos), -float64(pos)-float64(neg))))
		fmt.Println(max)
	}
}

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

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

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	pos, neg := 0, 0
	var num int
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &num)
		if num >= 0 {
			pos += num
		} else {
			neg -= num
		}
	}
	fmt.Fprintln(out, abs(pos-neg))
}

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

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

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

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

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

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

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

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

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

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

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

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

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

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

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

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

var exists = struct{}{}

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

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

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

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

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

type Ordered interface {
	Integer | Float | ~string
}

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

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

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

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

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

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

package main

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

func main() {
	var testCases int

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

	defer writer.Flush()
	fmt.Fscan(reader, &testCases)

	for testCase := 1; testCase <= testCases; testCase++ {

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

		var sum int64
		for i := 0; i < n; i++ {
			var temp int64
			fmt.Fscan(reader, &temp)

			sum += temp

		}

		ans := int64(math.Abs((float64(sum))))

		fmt.Fprintln(writer, ans)
	}
}

package main

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

func solve(reader *bufio.Reader, writer *bufio.Writer) {
	n := readInt(reader)
	a := readArrayInt64(reader)

	var sum1, sum2 int64 = 0, 0
	for i := 0; i < n; i++ {
		if a[i] < 0 {
			sum1 += a[i]
		} else {
			sum2 += a[i]
		}
	}
	sum1 *= -1

	if sum1 > sum2 {
		fmt.Fprintln(writer, sum1-sum2)
	} else {
		fmt.Fprintln(writer, sum2-sum1)
	}
}

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

	t := readInt(reader)

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

	writer.Flush()
}

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

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

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

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

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

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

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

	return value
}

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

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

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

	var ar []int

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

	return ar
}

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

	var ar []int64

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

	return ar
}

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

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

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

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

func gcd(x, y int64) int64 {
	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func lcm(x int64, y int64) int64 {
	return x * y / gcd(x, y)
}

package main

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

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

const (
	DEBUG = false
)

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

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

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

func solve(tt int) {
	var n int
	scanf("%d\n", &n)
	arr := make([]int64, n)
	res1 := int64(0)
	res2 := int64(0)
	for i:=0; i<n; i++ {
		scanf("%d ", &arr[i])
		if arr[i] > 0 {
			res1 += arr[i]
		} else {
			res2 += arr[i]
		}
	}
	scanf("\n")

	res := res1 + res2
	if res < 0 {
		res = -res
	}
	printf("%d\n", res)
}

func main() {
	defer writer.Flush()

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

package main

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

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

func main() {
	defer out.Flush()

	var tc int
	for fmt.Fscan(in, &tc); tc > 0; tc-- {
		var n int
		var a, s int64
		for fmt.Fscan(in, &n); n > 0; n-- {
			fmt.Fscan(in, &a)
			s += a
		}
		if s < 0 {
			s = -s
		}
		fmt.Fprintln(out, s)
	}
}

package main

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

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

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

	for ; t > 0; t-- {
		var n int
		fmt.Fscan(reader, &n)

		var ans int64
		for ; n > 0; n-- {
			var x int64
			fmt.Fscan(reader, &x)
			ans += x
		}

		if ans < 0 {
			fmt.Fprintln(writer, -ans)
		} else {
			fmt.Fprintln(writer, ans)
		}
	}
}

package main

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

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

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

	for ; t > 0; t-- {
		var n int
		fmt.Fscan(reader, &n)

		var ans int
		for ; n > 0; n-- {
			var x int
			fmt.Fscan(reader, &x)
			ans += x
		}

		fmt.Println(math.Abs(float64(ans)))
	}
}

package main

import (
	"fmt"
	"math"
)

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

	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%d", &n)

		var ans int
		for ; n > 0; n-- {
			var x int
			fmt.Scanf("%d", &x)
			ans += x
		}

		fmt.Println(math.Abs(float64(ans)))
	}
}

package main

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

func main() {
	var testCases int

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

	defer writer.Flush()
	fmt.Fscan(reader, &testCases)

	for testCase := 1; testCase <= testCases; testCase++ {

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

		// nSum := 0
		var sum int64
		for i := 0; i < n; i++ {
			var jj int64
			fmt.Fscan(reader, &jj)

			sum += jj
			// if jj < 0 {
			// } else {
			// 	pSum += (jj)
			// }
		}

		// d := math.Abs(math.Abs(float64(nSum)) - math.Abs(float64(pSum)))

		fmt.Fprintln(writer, math.Abs(float64(sum)))
	}
}

package main

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

func main() {
	var testCases int

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

	defer writer.Flush()
	fmt.Fscan(reader, &testCases)

	for testCase := 1; testCase <= testCases; testCase++ {

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

		// nSum := 0
		var sum float64
		for i := 0; i < n; i++ {
			var jj float64
			fmt.Fscan(reader, &jj)

			sum += jj
			// if jj < 0 {
			// } else {
			// 	pSum += (jj)
			// }
		}

		// d := math.Abs(math.Abs(float64(nSum)) - math.Abs(float64(pSum)))

		fmt.Fprintln(writer, math.Abs((sum)))
	}
}

package main

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

func main() {
	var testCases int

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

	defer writer.Flush()
	fmt.Fscan(reader, &testCases)

	for testCase := 1; testCase <= testCases; testCase++ {

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

		// nSum := 0
		sum := 0
		for i := 0; i < n; i++ {
			var jj int
			fmt.Fscan(reader, &jj)

			sum += jj
			// if jj < 0 {
			// } else {
			// 	pSum += (jj)
			// }
		}

		// d := math.Abs(math.Abs(float64(nSum)) - math.Abs(float64(pSum)))

		fmt.Fprintln(writer, math.Abs(float64(sum)))
	}
}

package main

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

func main() {
	var testCases int

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

	defer writer.Flush()
	fmt.Fscan(reader, &testCases)

	for testCase := 1; testCase <= testCases; testCase++ {

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

		nSum := 0
		pSum := 0
		for i := 0; i < n; i++ {
			var jj int
			fmt.Fscan(reader, &jj)

			if jj < 0 {
				nSum += int(math.Abs(float64(jj)))
			} else {
				pSum += int(math.Abs(float64(jj)))
			}
		}

		d := math.Abs(float64(nSum) - float64(pSum))

		fmt.Fprintln(writer, d)
	}
}

package main

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

func main() {
	var testCases int

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

	defer writer.Flush()
	fmt.Fscan(reader, &testCases)

	for testCase := 1; testCase <= testCases; testCase++ {

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

		nSum := 0
		pSum := 0
		for i := 0; i < n; i++ {
			var i int
			fmt.Fscan(reader, &i)

			if i < 0 {
				nSum += int(math.Abs(float64(i)))
			} else {
				pSum += int(math.Abs(float64(i)))
			}
		}

		d := math.Abs(float64(nSum) - float64(pSum))

		fmt.Fprintln(writer, d)
	}
}

package main

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

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

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

	return num
}

func sol(nums []int) int {
	sort.Ints(nums)
	pos, sumLeft, sumRight := 0, 0, 0

	for i := 0; i < len(nums); i++ {
		if absInt(sumLeft + nums[i]) < absInt(sumLeft) {
			pos = i
			break
		} else {
			sumLeft += nums[i]
		}
	}

	if pos != 0 {
		for i := pos; i < len(nums); i++ {
			sumRight += nums[i]
		}
	}

	return absInt(sumLeft) - absInt(sumRight)
}

func main() {
	writer.Flush()
	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for t > 0 {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		nums := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &nums[i])
		}
		fmt.Fscanf(reader, "\n")
		fmt.Println(sol(nums))
		t--
	}
}


You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any number chosen in the first array is strictly less than any number chosen in the second array.

The first line contains two integers nA, nB (1 ≤ nA, nB ≤ 105), separated by a space — the sizes of arrays A and B, correspondingly. The second line contains two integers k and m (1 ≤ k ≤ nA, 1 ≤ m ≤ nB), separated by a space. The third line contains nA numbers a1, a2, ... anA ( - 109 ≤ a1 ≤ a2 ≤ ... ≤ anA ≤ 109), separated by spaces — elements of array A. The fourth line contains nB integers b1, b2, ... bnB ( - 109 ≤ b1 ≤ b2 ≤ ... ≤ bnB ≤ 109), separated by spaces — elements of array B.

Print "YES" (without the quotes), if you can choose k numbers in array A and m numbers in array B so that any number chosen in array A was strictly less than any number chosen in array B. Otherwise, print "NO" (without the quotes).

NoteIn the first sample test you can, for example, choose numbers 1 and 2 from array A and number 3 from array B (1 < 3 and 2 < 3).In the second sample test the only way to choose k elements in the first array and m elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in A will be less than all the numbers chosen in B: .

package main
import (
  "bufio"
  "fmt"
  "os"
)

const maxN = 100005
var a,b [maxN]int

func main() {
  var nA, nB, k, m int
  stdin := bufio.NewReader(os.Stdin)

  fmt.Fscanf(stdin, "%d %d\n", &nA, &nB)
  fmt.Fscanf(stdin, "%d %d\n", &k, &m)

  for i := 0; i < nA; i++ {
    if i != nA - 1 {
      fmt.Fscanf(stdin, "%d ", &a[i])
    } else {
      fmt.Fscanf(stdin, "%d\n", &a[i])
    }
  }
  for i := 0; i < nB; i++ {
    if i != nB - 1 {
      fmt.Fscanf(stdin, "%d ", &b[i])
    } else {
      fmt.Fscanf(stdin, "%d\n", &b[i])
    }
  }
  if (a[k-1] < b[nB-m]) {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}

package main

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

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() {
	defer w.Flush()
	var n, nn int
	for I(&n, &nn) == nil {
		solve(n, nn)
	}
}

func solve(n, nn int) {
	var k, m int
	I(&k, &m)
	ak, am := make([]int, n), make([]int, nn)
	for i := 0; i < n; i++ {
		I(&ak[i])
	}
	for i := 0; i < nn; i++ {
		I(&am[i])
	}
	ak = ak[:k]
	am = am[len(am)-m:]
	if am[0] > ak[len(ak)-1] {
		O("YES", "\n")
	} else {
		O("NO", "\n")
	}
}

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)

	na, nb := nextInt(), nextInt()
	k, m := nextInt(), nextInt()
	a, maxa, minb := 0, 0, 0

	// a := make([]int, na)
	// b := make([]int, nb)

	for i := 0; i < na; i++ {
		a = nextInt()

		if i == k-1 {
			maxa = a
		}
	}

	for i := 0; i < nb; i++ {
		a = nextInt()

		if i == nb-m {
			minb = a
		}
	}

	if maxa < minb {
		println("YES")
	} else {
		println("NO")
	}

}

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)

	na, nb := nextInt(), nextInt()
	k, m := nextInt(), nextInt()
	maxa, minb := 0, 0

	// a := make([]int, na)
	// b := make([]int, nb)

	for i := 0; i < na; i++ {
		if i == k-1 {
			maxa = nextInt()
			continue
		}
		nextInt()
	}

	for i := 0; i < nb; i++ {
		if i == nb-m {
			minb = nextInt()
			continue
		}
		nextInt()
	}

	if maxa < minb {
		println("YES")
	} else {
		println("NO")
	}

}

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 main() {
	r := bufio.NewReader(os.Stdin)
	var n1, n2, m, k int
	fmt.Fscanf(r, "%d %d\n", &n1, &n2)
	fmt.Fscanf(r, "%d %d\n", &m, &k)

	min := make([]int, n1)
	max := make([]int, n2)

	for i := range min {
		fmt.Fscanf(r, "%d", &min[i])
	}
	fmt.Fscanf(r, "\n")
	for i := range max {
		fmt.Fscanf(r, "%d", &max[i])
	}
	result := "NO"
	if min[m-1] < max[n2-k] {
		result = "YES"
	}
	fmt.Fprint(os.Stdout, result)
}

package main

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

const N = 1e5 + 5

var a, b [N]int

func main() {
  stdin := bufio.NewReader(os.Stdin)
  var na, nb int
  fmt.Fscanf(stdin, "%d %d\n", &na, &nb)
  var k, m int
  fmt.Fscanf(stdin, "%d %d\n", &k, &m)
  for i := 1; i <= na; i++ {
    if i != na {
      fmt.Fscanf(stdin, "%d ", &a[i])
    } else {
      fmt.Fscanf(stdin, "%d\n", &a[i])
    }
  }
  for i := 1; i <= nb; i++ {
    if i != nb {
      fmt.Fscanf(stdin, "%d ", &b[i])
    } else {
      fmt.Fscanf(stdin, "%d\n", &b[i])
    }
  }
  if a[k] < b[nb - m + 1] {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var lenA, lenB, k, m int
	fmt.Fscanf(r, "%d %d\n", &lenA, &lenB)
	fmt.Fscanf(r, "%d %d\n", &k, &m)
	a := make([]int, lenA)
	b := make([]int, lenB)

	for i := range a {
		if i == lenA-1 {
			fmt.Fscanf(r, "%d\n", &a[i])
		} else {
			fmt.Fscanf(r, "%d", &a[i])
		}

	}
	for i := range b {
		fmt.Fscanf(r, "%d", &b[i])
	}
	if a[k-1] < b[len(b)-m] {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}

package main

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

func solve(a []int, b []int, k int, m int) string {
	if a[k-1] < b[len(b)-m] {
		return "YES"
	}
	return "NO"
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var lenA, lenB, k, m int
	fmt.Fscanf(r, "%d %d\n", &lenA, &lenB)
	fmt.Fscanf(r, "%d %d\n", &k, &m)
	a := make([]int, lenA)
	b := make([]int, lenB)

	for i := range a {
		if i == lenA-1 {
			fmt.Fscanf(r, "%d\n", &a[i])
		} else {
			fmt.Fscanf(r, "%d", &a[i])
		}

	}
	for i := range b {
		fmt.Fscanf(r, "%d", &b[i])
	}

	fmt.Fprintf(os.Stdout, "%s\n", solve(a, b, k, m))
}

package main

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

func main() {
	reader := NewStdReader(os.Stdin)

	na, nb, k, m := reader.ReadInt(), reader.ReadInt(), reader.ReadInt(), reader.ReadInt()

	var a, b, t int

	for i := 1; i <= na; i++ {
		t = reader.ReadInt()
		if i == k {
			a = t
		}
	}

	for i := 0; i < nb; i++ {
		t = reader.ReadInt()
		if i == nb-m {
			b = t
		}
	}

	if a < b {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 16*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

package main
import (
  "bufio"
  "fmt"
  "os"
)

const maxN = 100005
var a,b [maxN]int

func main() {
  var nA, nB, k, m int
  stdin := bufio.NewReader(os.Stdin)

  fmt.Fscanf(stdin, "%d %d\n", &nA, &nB)
  fmt.Fscanf(stdin, "%d %d\n", &k, &m)

  for i := 0; i < nA; i++ {
    if i != nA - 1 {
      fmt.Scanf("%d ", &a[i])
    } else {
      fmt.Scanf("%d\n", &a[i])
    }
  }
  for i := 0; i < nB; i++ {
    if i != nB - 1 {
      fmt.Scanf("%d ", &b[i])
    } else {
      fmt.Scanf("%d\n", &b[i])
    }
  }
  if (a[k-1] < b[nB-m]) {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}

package main

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

const N = 1e5 + 5

var a, b [N]int

func main() {
  stdin := bufio.NewReader(os.Stdin)
  var na, nb int
  fmt.Fscanf(stdin, "%d %d\n", &na, &nb)
  var k, m int
  fmt.Fscanf(stdin, "%d %d\n", &k, &m)
  for i := 1; i <= na; i++ {
    if i != na {
      fmt.Fscanf(stdin, "%d ", &a[i])
    } else {
      fmt.Fscanf(stdin, "%d\n", &a[i])
    }
  }
  fmt.Fscanf(stdin, "\n")
  for i := 1; i <= nb; i++ {
    if i != nb {
      fmt.Fscanf(stdin, "%d ", &b[i])
    } else {
      fmt.Fscanf(stdin, "%d\n", &b[i])
    }
  }
  if a[k] > b[nb - m + 1] {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}

package main

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

const N = 1e5 + 5

var a, b [N]int

func main() {
  stdin := bufio.NewReader(os.Stdin)
  var na, nb int
  fmt.Fscanf(stdin, "%d %d\n", &na, &nb)
  var k, m int
  fmt.Fscanf(stdin, "%d %d\n", &k, &m)
  for i := 1; i <= na; i++ {
    if i != na {
      fmt.Fscanf(stdin, "%d ", &a[i])
    } else {
      fmt.Fscanf(stdin, "%d\n", &a[i])
    }
  }
  for i := 1; i <= nb; i++ {
    if i != nb {
      fmt.Fscanf(stdin, "%d ", &b[i])
    } else {
      fmt.Fscanf(stdin, "%d\n", &b[i])
    }
  }
  if a[k] > b[nb - m + 1] {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}

package main

import "fmt"

const N = 1e5 + 5;

var a, b [N]int

func main() {
  var na, nb int
  fmt.Scan(&na, &nb)
  var k, m int
  fmt.Scan(&k, &m)
  for i := 1; i <= na; i++ {
    fmt.Scan(&a[i])
  }
  for i := 1; i <= nb; i++ {
    fmt.Scan(&b[i])
  }
  if a[na] < b[nb - m + 1] {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}

package main

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

func solve(a []int, b []int, k int, m int) string {
	if a[k-1] < b[len(b)-m] {
		return "YES"
	}
	return "NO"
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var lenA, lenB, k, m int
	fmt.Fscanf(r, "%d %d\n", &lenA, &lenB)
	fmt.Fscanf(r, "%d %d\n", &k, &m)
	a := make([]int, lenA)
	b := make([]int, lenB)

	for i := range a {
		fmt.Fscanf(r, "%d", &a[i])
	}

	for i := range b {
		fmt.Fscanf(r, "%d", &b[i])
	}

	fmt.Fprintf(os.Stdout, "%s\n", solve(a, b, k, m))
}

package main

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

func solve(a []int, b []int, k int, m int) string {
	fmt.Println(a, b, k, m)
	if a[k-1] < b[len(b)-m] {
		return "YES"
	}
	return "NO"
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var lenA, lenB, k, m int
	fmt.Fscanf(r, "%d %d\n", &lenA, &lenB)
	fmt.Fscanf(r, "%d %d\n", &k, &m)
	a := make([]int, lenA)
	b := make([]int, lenB)

	for i := range a {
		if i == lenA-1 {
			fmt.Fscanf(r, "%d\n", &a[i])
		} else {
			fmt.Fscanf(r, "%d", &a[i])
		}

	}
	for i := range b {
		fmt.Fscanf(r, "%d", &b[i])
	}

	fmt.Fprintf(os.Stdout, "%s\n", solve(a, b, k, m))

}

package main

import (
	"fmt"
)

func main() {
	var na, nb, k, m int
	fmt.Scan(&na, &nb, &k, &m)

	var a, b, t int

	for i := 1; i <= na; i++ {
		fmt.Scanf("%d", &t)
		if i == k {
			a = t
			var s string
			fmt.Scanln(&s)
			break
		}
	}

	for i := 0; i < nb; i++ {
		fmt.Scanf("%d", &t)
		if i == nb-m {
			b = t
			var s string
			fmt.Scanln(&s)
			break
		}
	}

	if a < b {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

package main

import (
	"os"
)

func main() {
	na, nb, k, m := getInt(), getInt(), getInt(), getInt()

	var a, b, t int

	for i := 1; i <= na; i++ {
		t = getInt()
		if i == k {
			a = t
		}
	}

	for i := 0; i < nb; i++ {
		t = getInt()
		if i == nb-m {
			b = t
		}
	}

	if a < b {
		print("YES")
	} else {
		print("NO")
	}
}

func getInt() int {
	b := []byte{0}
	r := 0
	ok := false

	for {
		_, e := os.Stdin.Read(b)
		if e != nil {
			break
		}
		if b[0] >= '0' && b[0] <= '9' {
			r = r*10 + int(b[0]-'0')
			ok = true
		} else {
			if ok {
				break
			}
		}
	}

	return r
}

package main

import (
	"fmt"
)

func main() {
	var na, nb, k, m int
	fmt.Scanf("%d", &na)
	fmt.Scanf("%d", &nb)
	fmt.Scanf("%d", &k)
	fmt.Scanf("%d", &m)

	var a, b, t int

	for i := 1; i <= na; i++ {
		fmt.Scanf("%d", &t)
		if i == k {
			a = t
		}
	}

	for i := 0; i < nb; i++ {
		fmt.Scanf("%d", &t)
		if i == nb-m {
			b = t
		}
	}

	if a < b {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

package main

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

func main() {
	reader := NewStdReader(os.Stdin)

	na, nb, k, m := reader.ReadInt(), reader.ReadInt(), reader.ReadInt(), reader.ReadInt()

	var a, b, t int

	for i := 1; i <= na; i++ {
		t = reader.ReadInt()
		if i == k {
			a = t
		}
	}

	for i := 0; i < nb; i++ {
		t = reader.ReadInt()
		if i == nb-m {
			b = t
		}
	}

	if a < b {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 10*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			}
		}
	}

	return r
}

package main

import (
	"fmt"
)

func main() {
	var na, nb, k, m int
	fmt.Scan(&na, &nb, &k, &m)

	var a, b, t int

	for i := 1; i <= na; i++ {
		fmt.Scanf("%d", &t)
		if i == k {
			a = t
		}
	}

	for i := 0; i < nb; i++ {
		fmt.Scanf("%d", &t)
		if i == nb-m {
			b = t
		}
	}

	if a < b {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

package main

import (
	"fmt"
)

func main() {
	var na, nb, k, m int64
	fmt.Scanf("%d", &na)
	fmt.Scanf("%d", &nb)
	fmt.Scanf("%d", &k)
	fmt.Scanf("%d", &m)

	var a, b, t, i int64

	for i = 1; i <= na; i++ {
		fmt.Scanf("%d", &t)
		if i == k {
			a = t
		}
	}

	for i = 0; i < nb; i++ {
		fmt.Scanf("%d", &t)
		if i == nb-m {
			b = t
		}
	}

	if a < b {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}


Kleofáš is participating in an n-thlon - a tournament consisting of n different competitions in n different disciplines (numbered 1 through n). There are m participants in the n-thlon and each of them participates in all competitions.In each of these n competitions, the participants are given ranks from 1 to m in such a way that no two participants are given the same rank - in other words, the ranks in each competition form a permutation of numbers from 1 to m. The score of a participant in a competition is equal to his/her rank in it.The overall score of each participant is computed as the sum of that participant's scores in all competitions.The overall rank of each participant is equal to 1 + k, where k is the number of participants with strictly smaller overall score.The n-thlon is over now, but the results haven't been published yet. Kleofáš still remembers his ranks in each particular competition; however, he doesn't remember anything about how well the other participants did. Therefore, Kleofáš would like to know his expected overall rank.All competitors are equally good at each discipline, so all rankings (permutations of ranks of everyone except Kleofáš) in each competition are equiprobable.

The first line of the input contains two space-separated integers n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ 1000) — the number of competitions and the number of participants respectively. Then, n lines follow. The i-th of them contains one integer xi (1 ≤ xi ≤ m) — the rank of Kleofáš in the i-th competition.

Output a single real number – the expected overall rank of Kleofáš. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

NoteIn the first sample, Kleofáš has overall score 6. Nobody else can have overall score less than 6 (but it's possible for one other person to have overall score 6 as well), so his overall rank must be 1.

package main

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

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

	n, m := io.nextInt(), io.nextInt()
	x := io.nextInts(n)

	sum := 0
	dp := make([][]float64, n+1)

	getsum := func(i, l, r int) float64 {
		if l < 0 {
			l = 0
		}
		if r >= len(dp[i]) {
			r = len(dp[i]) - 1
		}
		if l > r {
			return 0
		}
		sum := dp[i][r]
		if l > 0 {
			sum -= dp[i][l-1]
		}
		return sum
	}

	dp[0] = make([]float64, 1)
	dp[0][0] = float64(m - 1)
	for i := 1; i <= n; i++ {
		cur := x[i-1] - 1
		sum += cur
		dp[i] = make([]float64, m*i)
		for j := 0; j < len(dp[i]); j++ {
			bad := j - cur
			dp[i][j] = (getsum(i-1, j-m+1, j) - getsum(i-1, bad, bad)) / float64(m-1)
			if j > 0 {
				dp[i][j] += dp[i][j-1]
			}
		}
	}

	fmt.Fprintf(io, "%.10f\n", 1+getsum(n, 0, sum-1))
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	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) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, 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()
}