This is the easy version of the problem. The difference is that in this version the array can not contain zeros. You can make hacks only if both versions of the problem are solved.You are given an array $$$[a_1, a_2, \ldots a_n]$$$ consisting of integers $$$-1$$$ and $$$1$$$. You have to build a partition of this array into the set of segments $$$[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]$$$ with the following property:  Denote the alternating sum of all elements of the $$$i$$$-th segment as $$$s_i$$$: $$$s_i$$$ = $$$a_{l_i} - a_{l_i+1} + a_{l_i+2} - a_{l_i+3} + \ldots \pm a_{r_i}$$$. For example, the alternating sum of elements of segment $$$[2, 4]$$$ in array $$$[1, 0, -1, 1, 1]$$$ equals to $$$0 - (-1) + 1 = 2$$$.  The sum of $$$s_i$$$ over all segments of partition should be equal to zero. Note that each $$$s_i$$$ does not have to be equal to zero, this property is about sum of $$$s_i$$$ over all segments of partition.The set of segments $$$[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]$$$ is called a partition of the array $$$a$$$ of length $$$n$$$ if $$$1 = l_1 \le r_1, l_2 \le r_2, \ldots, l_k \le r_k = n$$$ and $$$r_i + 1 = l_{i+1}$$$ for all $$$i = 1, 2, \ldots k-1$$$. In other words, each element of the array must belong to exactly one segment.You have to build a partition of the given array with properties described above or determine that such partition does not exist.Note that it is not required to minimize the number of segments in the partition.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10\,000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$a_i$$$ is $$$-1$$$ or $$$1$$$) — the elements of the given array. It's guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$200\,000$$$.

For each test case, if required partition does not exist, print $$$-1$$$. Otherwise, print an integer $$$k$$$ — the number of segments in the partition.  Then in the $$$i$$$-th of the following $$$k$$$ lines print two integers $$$l_i$$$ and $$$r_i$$$ — description of the $$$i$$$-th segment. The following conditions should be satisfied:   $$$l_i \le r_i$$$ for each $$$i$$$ from $$$1$$$ to $$$k$$$.  $$$l_{i + 1} = r_i + 1$$$ for each $$$i$$$ from $$$1$$$ to $$$(k - 1)$$$.  $$$l_1 = 1, r_k = n$$$.  If there are multiple correct partitions of the array, print any of them.

NoteIn the first test case we can build a partition of one segment of length $$$4$$$. The sum of this segment will be equal to $$$1 - 1 + 1 - 1 = 0$$$.In the second test case we can build a partition of two segments of length $$$3$$$. The sum of the first segment will be equal to $$$-1 -1 + 1 = -1$$$, and the sum of the second segment: $$$1 - 1 + 1 = 1$$$. So, the total sum will be equal to $$$-1 + 1 = 0$$$.In the third and in the fourth test cases it can be proved that there are no required partition.

package main

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

func integer_list(s string, sep string) []int {
	lst := strings.Split(s, sep)
	return conv(lst)
}

func conv(lst []string) []int {

	ret := []int{}
	for _, val := range lst {
		x, _ := strconv.Atoi(val)
		ret = append(ret, x)
	}
	return ret

}

func main() {
	// fmt.Println("hello")

	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	t, _ := strconv.Atoi(line[0 : len(line)-2])

	for j := 0; j < t; j++ {
		line, _ := reader.ReadString('\n')
		n, _ := strconv.Atoi(line[0 : len(line)-2])
		str, _ := reader.ReadString('\n')
		lst := integer_list(str[0:len(str)-2], " ")
		// fmt.Println(lst, line, str, t, "prikdf")
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)

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

		// ws.Flush()

	}

}

package main

import (
	"fmt"
)

var bytes []byte
var l, max int

func fastScan() int {
	b := bytes[l]

	// Check if the bytes is not a number
	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	result := 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > max {
			return result
		}
		b = bytes[l]
	}
	return result
}

func main() {
	// fmt.Println("hello")
	// bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	// max = len(bytes) - 1

	// ws := bufio.NewWriter(os.Stdout)
	var t int
	// t = fastScan()
	fmt.Scan(&t)
	var n int
	for j := 0; j < t; j++ {
		lst := []int{}
		// n = fastScan()
		fmt.Scan(&n)
		var x int
		for ele := 0; ele < n; ele++ {
			// x = fastScan()
			fmt.Scan(&x)
			lst = append(lst, x)
		}

		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)

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

		// ws.Flush()

	}

}

package main

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

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

type Segment struct {
	begin int
	end   int
}

func solve(n int, a []int) string {
	if n%2 == 1 {
		return "-1"
	}
	var list = []Segment{}
	count := 0
	for i := 0; i < n; i += 2 {
		if a[i] == a[i+1] {
			if count == 0 {
				list = append(list, Segment{i, i + 1})
				count++
			} else {
				list[count-1].end = i + 1
			}
		} else {
			list = append(list, Segment{i, i}, Segment{i + 1, i + 1})
			count += 2
		}
	}
	var s []string
	for _, x := range list {
		s = append(s, fmt.Sprintf("%d %d", x.begin+1, x.end+1))
	}
	return fmt.Sprintf("%d\n", count) + strings.Join(s, "\n")
}

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

package main

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

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

type Segment struct {
	begin int
	end   int
}

func (s Segment) String() string {
	return fmt.Sprintf("%d %d", s.begin+1, s.end+1)
}

func solve(n int, a []int) string {
	if n%2 == 1 {
		return "-1"
	}
	var list = []Segment{}
	count := 0
	for i := 0; i < n; i += 2 {
		if a[i] == a[i+1] {
			if count == 0 {
				list = append(list, Segment{i, i + 1})
				count++
			} else {
				list[count-1].end = i + 1
			}
		} else {
			list = append(list, Segment{i, i}, Segment{i + 1, i + 1})
			count += 2
		}
	}
	var s []string
	for _, x := range list {
		s = append(s, fmt.Sprint(x))
	}
	return fmt.Sprintf("%d\n", count) + strings.Join(s, "\n")
}

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

package main

import (
	."fmt"
	."os"
)

func solve(){
	var n int
	Fscan(Stdin, &n)
	sz := make([]int, n)
	for i := 0; i < n; i++ {
		Fscan(Stdin, &sz[i])
	}
	tot := 0
	last := 0
	break_arr := make([]int, n)
	for i := 0; i < n; i++{
		if last == 0{
			last = sz[i]
			tot = sz[i]
		}else{
			if sz[i] == last{
				if tot == 0{
					tot = sz[i]
				}else{
					tot = 0
				}
			}else{
				if tot == 0{
					break_arr[i - 1] = 1
					tot = sz[i]
					last = sz[i]
				}else{
					break_arr[i - 1] = 1
					break_arr[i] = 1
					tot = 0
					last = 0
				}
			}
		}
		// Fprintln(Stdout, "tot = ", tot)
	}
	// for i := 0; i < n; i ++{
	// 	Fprintln(Stdout, break_arr[i])
	// }
	if tot == 0{
		break_arr[n - 1] = 1
		out_n := 0
		for i := 0; i < n; i++{
			if break_arr[i] == 1{
				out_n ++
			}
		}
		Fprintln(Stdout, out_n)
		l := 1
		for i := 0; i < n; i++{
			if break_arr[i] == 1{
				Fprintln(Stdout, l, i + 1)
				l = i + 2
			}
		}
	}else{
		Fprintln(Stdout, -1)
	}
}

func main(){
	var t int
	Fscan(Stdin, &t)
	for ; t > 0; t--{
		solve()
	}
}

package main

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

type seg struct {
	l int
	r int
}

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, rsum int
		fmt.Fscan(r, &n)
		a := make([]int, n)

		for i := range a {
			fmt.Fscan(r, &a[i])
			rsum += (2 + a[i]) % 2
		}

		if rsum % 2 == 1 {
			fmt.Fprintln(w, -1)
		} else {
			segc := 0
			segs := make([]seg, n)
			for j := 0; j < n; j += 2 {
				if a[j] == a[j+1] {
					segs[segc] = seg{j+1, j+2}
					segc++
				} else {
					segs[segc] = seg{j+1, j+1}
					segs[segc+1] = seg{j+2, j+2}
					segc += 2
				}
			}

			fmt.Fprintln(w, segc)
			for j := 0; j < segc; j++ {
				fmt.Fprintln(w, segs[j].l, segs[j].r)
			}
		}
	}
}

package main

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

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

	var epochs int
	fmt.Fscan(r, &epochs)
	for ; epochs > 0; epochs-- {
		var n, n1, n2 int
		fmt.Fscan(r, &n)

		if n&1 == 1 {
			for i := 0; i < n; i++ {
				fmt.Fscan(r, &n1)
			}
			fmt.Fprintln(w, "-1")
		} else {
			list := []int{}
			flag := 0
			for i := 1; i <= n; i += 2 {
				fmt.Fscan(r, &n1, &n2)
				if n1 == n2 {
					if flag == 1 {
						//list[len(list)-1] = i + 1
					} else {
						list = append(list, i)
					}
					flag = 1
				} else {
					list = append(list, i, i+1)
					flag = 0
				}
			}
			list = append(list, n+1)

			fmt.Fprintln(w, len(list)-1)
			for i := 0; i < len(list)-1; i++ {
				fmt.Fprintln(w, list[i], list[i+1]-1)
			}
		}
	}
}

package main

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

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

	var epochs int
	fmt.Fscan(r, &epochs)
	for ; epochs > 0; epochs-- {
		var n, n1, n2 int
		fmt.Fscan(r, &n)

		if n&1 == 1 {
			for i := 0; i < n; i++ {
				fmt.Fscan(r, &n1)
			}
			fmt.Fprintln(w, "-1")
		} else {
			list := []int{}
			flag := 0
			for i := 1; i <= n; i += 2 {
				fmt.Fscan(r, &n1, &n2)
				if n1 == n2 {
					if flag == 1 {
						list[len(list)-1] = i + 1
					} else {
						list = append(list, i, i+1)
					}
					flag = 1
				} else {
					list = append(list, i, i, i+1, i+1)
					flag = 0
				}
			}

			fmt.Fprintln(w, len(list)>>1)
			for i := 0; i < len(list); i += 2 {
				fmt.Fprintln(w, list[i], list[i+1])
			}
		}
	}
}

package main

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

const cf = true

type pair struct {
	begin int
	end   int
}

func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := range arr {
		fmt.Fscan(in, &arr[i])
	}
	if n%2 == 1 {
		fmt.Fprintln(out, -1)
		return
	}
	lines := make([]pair, 0, n)
	for i := 0; i < n-1; i += 2 {
		if arr[i] == arr[i+1] {
			lines = append(lines, pair{i + 1, i + 2})
		} else {
			lines = append(lines, pair{i + 1, i + 1})
			lines = append(lines, pair{i + 2, i + 2})
		}
	}
	fmt.Fprintln(out, len(lines))
	for _, line := range lines {
		fmt.Fprintln(out, line.begin, line.end)
	}
}

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 a != b {
		if a > b {
			a -= b
		} else {
			b -= a
		}
	}

	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"
	"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.Fscan(reader, f) }
func main() {
	// fmt.Println("hello")
	// defer writer.Flush()
	var t int
	// fmt.Println("hello")
	fmt.Scan(&t)
	fmt.Println(t, "t")
	var n int
	for j := 0; j < t; j++ {
		scanf("%d\r\n", &n)
		var x int
		lst := []int{}
		for k := 0; k < n-1; j++ {
			scanf("%d", &x)
			lst = append(lst)

		}
		fmt.Println(lst, n)
		// fmt.Println(lst, line, str, t, "prikdf")
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)

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

		// ws.Flush()

	}

}

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.Fscan(reader, f) }
func main() {
	// fmt.Println("hello")
	// defer writer.Flush()
	var t int
	// fmt.Println("hello")
	fmt.Scan(&t)
	fmt.Println(t, "t")
	var n int
	for j := 0; j < t; j++ {
		scanf("%d\r\n", &n)
		var x int
		lst := []int{}
		for k := 0; k < n-1; j++ {
			scanf("%d", &x)
			lst = append(lst)

		}
		fmt.Println(lst)
		// fmt.Println(lst, line, str, t, "prikdf")
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)

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

		// ws.Flush()

	}

}

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.Fscan(reader, f) }
func main() {
	// fmt.Println("hello")
	// defer writer.Flush()
	var t int
	// fmt.Println("hello")
	scanf("%d\r\n", &t)
	fmt.Println(t, "t")
	var n int
	for j := 0; j < t; j++ {
		scanf("%d\r\n", &n)
		var x int
		lst := []int{}
		for k := 0; k < n; j++ {
			scanf("%d", &x)
			lst = append(lst)

		}
		fmt.Println(lst)
		// fmt.Println(lst, line, str, t, "prikdf")
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)

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

		// ws.Flush()

	}

}

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.Fscan(reader, f) }
func main() {
	// fmt.Println("hello")
	// defer writer.Flush()
	var t int
	// fmt.Println("hello")
	scanf("%d\r", &t)
	fmt.Println(t, "t")
	var n int
	for j := 0; j < t; j++ {
		scanf("%d", &n)
		var x int
		lst := []int{}
		for j := 0; j < n; j++ {
			scanf("%d", &x)
			lst = append(lst)

		}
		fmt.Println(lst)
		// fmt.Println(lst, line, str, t, "prikdf")
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)

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

		// ws.Flush()

	}

}

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.Fscan(reader, f) }
func main() {
	// fmt.Println("hello")
	// defer writer.Flush()
	var t int
	fmt.Println("hello")
	scanf("%d\r", &t)
	fmt.Println(t, "t")
	var n int
	for j := 0; j < t; j++ {
		scanf("%d", &n)
		var x int
		lst := []int{}
		for j := 0; j < n; j++ {
			scanf("%d", &x)
			lst = append(lst)

		}
		fmt.Println(lst)
		// fmt.Println(lst, line, str, t, "prikdf")
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)

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

		// ws.Flush()

	}

}

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.Fscan(reader, f) }
func main() {
	// fmt.Println("hello")
	// defer writer.Flush()
	var t int
	fmt.Println("hello")
	scanf("%d", &t)
	fmt.Println(t, "t")
	var n int
	for j := 0; j < t; j++ {
		scanf("%d", &n)
		var x int
		lst := []int{}
		for j := 0; j < n; j++ {
			scanf("%d", &x)
			lst = append(lst)

		}
		fmt.Println(lst)
		// fmt.Println(lst, line, str, t, "prikdf")
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)

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

		// ws.Flush()

	}

}

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.Fscan(reader, f) }
func main() {
	// fmt.Println("hello")
	// defer writer.Flush()
	var t int
	scanf("%d", &t)
	fmt.Println(t, "t")
	var n int
	for j := 0; j < t; j++ {
		scanf("%d", &n)
		var x int
		lst := []int{}
		for j := 0; j < n; j++ {
			scanf("%d", &x)
			lst = append(lst)

		}
		fmt.Println(lst)
		// fmt.Println(lst, line, str, t, "prikdf")
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)

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

		// ws.Flush()

	}

}

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.Fscan(reader, f) }
func main() {
	// fmt.Println("hello")
	// defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	fmt.Println(t, "t")
	var n int
	for j := 0; j < t; j++ {
		scanf("%d\n", &n)
		var x int
		lst := []int{}
		for j := 0; j < n; j++ {
			scanf("%d ", &x)
			lst = append(lst)

		}
		fmt.Println(lst)
		// fmt.Println(lst, line, str, t, "prikdf")
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)

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

		// ws.Flush()

	}

}

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.Fscan(reader, f) }
func main() {
	// fmt.Println("hello")
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	var n int
	for j := 0; j < t; j++ {
		scanf("%d\n", &n)
		var x int
		lst := []int{}
		for j := 0; j < n; j++ {
			scanf("%d ", &x)
			lst = append(lst)

		}
		// fmt.Println(lst, line, str, t, "prikdf")
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)

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

		// ws.Flush()

	}

}

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.Fscan(reader, f) }
func main() {
	// fmt.Println("hello")
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	fmt.Println(t, "t")
	var n int
	for j := 0; j < t; j++ {
		scanf("%d\n", &n)
		var x int
		lst := []int{}
		for j := 0; j < n; j++ {
			scanf("%d ", &x)
			lst = append(lst)

		}
		// fmt.Println(lst, line, str, t, "prikdf")
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)

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

		// ws.Flush()

	}

}

package main

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

func integer_list(s string, sep string) []int {
	lst := strings.Split(s, sep)
	return conv(lst)
}

func conv(lst []string) []int {

	ret := []int{}
	for _, val := range lst {
		x, _ := strconv.Atoi(val)
		ret = append(ret, x)
	}
	return ret

}

func main() {
	// fmt.Println("hello")

	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	t, _ := strconv.Atoi(line[0 : len(line)-2])

	for j := 0; j < t; j++ {
		line, _ := reader.ReadString('\n')
		n, _ := strconv.Atoi(line[0 : len(line)-2])
		str, _ := reader.ReadString('\n')
		lst := integer_list(str[0:len(str)-2], " ")
		fmt.Println(lst, line, str, t, "prikdf")
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)

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

		// ws.Flush()

	}

}

package main

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

func integer_list(s string, sep string) []int {
	lst := strings.Split(s, sep)
	return conv(lst)
}

func conv(lst []string) []int {

	ret := []int{}
	for _, val := range lst {
		x, _ := strconv.Atoi(val)
		ret = append(ret, x)
	}
	return ret

}

func main() {
	// fmt.Println("hello")

	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\r')
	t, errr := strconv.Atoi(line)
	fmt.Println(errr)
	for j := 0; j < t; j++ {
		line, _ := reader.ReadString('\r')
		n, _ := strconv.Atoi(line)
		str, _ := reader.ReadString('\n')
		lst := integer_list(str, " ")
		fmt.Print(lst)
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)

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

		// ws.Flush()

	}

}

package main

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

func integer_list(s string, sep string) []int {
	lst := strings.Split(s, sep)
	return conv(lst)
}

func conv(lst []string) []int {

	ret := []int{}
	for _, val := range lst {
		x, _ := strconv.Atoi(val)
		ret = append(ret, x)
	}
	return ret

}

func main() {
	// fmt.Println("hello")

	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\r')
	t, errr := strconv.Atoi(line)
	fmt.Println(errr)
	for j := 0; j < t; j++ {
		line, _ := reader.ReadString('\n')
		n, _ := strconv.Atoi(line)
		str, _ := reader.ReadString('\n')
		lst := integer_list(str, " ")
		fmt.Print(lst)
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)

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

		// ws.Flush()

	}

}

package main

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

func integer_list(s string, sep string) []int {
	lst := strings.Split(s, sep)
	return conv(lst)
}

func conv(lst []string) []int {

	ret := []int{}
	for _, val := range lst {
		x, _ := strconv.Atoi(val)
		ret = append(ret, x)
	}
	return ret

}

func main() {
	// fmt.Println("hello")

	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\r')
	t, err := strconv.Atoi(line)
	fmt.Println(err)
	for j := 0; j < t; j++ {
		line, _ := reader.ReadString('\n')
		n, _ := strconv.Atoi(line)
		str, _ := reader.ReadString('\n')
		lst := integer_list(str, " ")
		fmt.Print(lst)
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)

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

		// ws.Flush()

	}

}

package main

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

func integer_list(s string, sep string) []int {
	lst := strings.Split(s, sep)
	return conv(lst)
}

func conv(lst []string) []int {

	ret := []int{}
	for _, val := range lst {
		x, _ := strconv.Atoi(val)
		ret = append(ret, x)
	}
	return ret

}

func main() {
	// fmt.Println("hello")

	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	t, err := strconv.Atoi(line)
	fmt.Println(err)
	for j := 0; j < t; j++ {
		line, _ := reader.ReadString('\n')
		n, _ := strconv.Atoi(line)
		str, _ := reader.ReadString('\n')
		lst := integer_list(str, " ")
		fmt.Print(lst)
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)

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

		// ws.Flush()

	}

}

package main

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

func integer_list(s string, sep string) []int {
	lst := strings.Split(s, sep)
	return conv(lst)
}

func conv(lst []string) []int {

	ret := []int{}
	for _, val := range lst {
		x, _ := strconv.Atoi(val)
		ret = append(ret, x)
	}
	return ret

}

func main() {
	// fmt.Println("hello")

	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	t, _ := strconv.Atoi(line)

	for j := 0; j < t; j++ {
		line, _ := reader.ReadString('\n')
		n, _ := strconv.Atoi(line)
		str, _ := reader.ReadString('\n')
		lst := integer_list(str, " ")

		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)

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

		// ws.Flush()

	}

}

package main

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

func integer_list(s string, sep string) []int {
	lst := strings.Split(s, sep)
	return conv(lst)
}

func conv(lst []string) []int {

	ret := []int{}
	for _, val := range lst {
		x, _ := strconv.Atoi(val)
		ret = append(ret, x)
	}
	return ret

}

func main() {
	// fmt.Println("hello")

	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	t, _ := strconv.Atoi(line)

	for j := 0; j < t; j++ {
		line, _ := reader.ReadString('\n')
		n, _ := strconv.Atoi(line)
		str, _ := reader.ReadString('\n')
		lst := integer_list(str, " ")
		fmt.Println(lst, n, t)
		continue
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)
			for i := 0; i < len(ans)-1; i += 2 {
				fmt.Println(ans[i], ans[i+1])
			}
		}

		// ws.Flush()

	}

}

package main

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

var bytes []byte
var l, max int

func fastScan() int {
	b := bytes[l]

	// Check if the bytes is not a number
	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	result := 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > max {
			return result
		}
		b = bytes[l]
	}
	return result
}

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

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

func main() {
	// fmt.Println("hello")
	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	max = len(bytes) - 1
	// defer writer.Flush()
	// ws := bufio.NewWriter(os.Stdout)
	// scanf("%d %d\n", &a, &b)
	// printf("%d\n", a+b)
	var t int
	scanf("%d\n", &t)

	for j := 0; j < t; j++ {
		lst := []int{}
		var n int
		scanf("%d\n", &n)
		var x int
		for ele := 0; ele < n; ele++ {
			scanf("%d", &x)
			lst = append(lst, x)
		}
		lst = append(lst, x)
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)
			for i := 0; i < len(ans)-1; i += 2 {
				fmt.Println(ans[i], ans[i+1])
			}
		}

		// ws.Flush()

	}

}

package main

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

var bytes []byte
var l, max int

func fastScan() int {
	b := bytes[l]

	// Check if the bytes is not a number
	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	result := 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > max {
			return result
		}
		b = bytes[l]
	}
	return result
}

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

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

func main() {
	// fmt.Println("hello")
	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	max = len(bytes) - 1
	// defer writer.Flush()
	// ws := bufio.NewWriter(os.Stdout)
	// scanf("%d %d\n", &a, &b)
	// printf("%d\n", a+b)
	var t int
	scanf("%d\n", &t)

	for j := 0; j < t; j++ {
		lst := []int{}
		var n int
		scanf("%d\n", &n)
		var x int
		for ele := 0; ele < n-1; ele++ {
			scanf("%d ", &x)
			lst = append(lst, x)
		}
		scanf("%d\n", &x)
		lst = append(lst, x)
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)
			for i := 0; i < len(ans)-1; i += 2 {
				fmt.Println(ans[i], ans[i+1])
			}
		}

		// ws.Flush()

	}

}

package main

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

var bytes []byte
var l, max int

func fastScan() int {
	b := bytes[l]

	// Check if the bytes is not a number
	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	result := 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > max {
			return result
		}
		b = bytes[l]
	}
	return result
}

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

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

func main() {
	// fmt.Println("hello")
	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	max = len(bytes) - 1
	defer writer.Flush()
	// ws := bufio.NewWriter(os.Stdout)
	// scanf("%d %d\n", &a, &b)
	// printf("%d\n", a+b)
	var t int
	scanf("%d\n", &t)

	for j := 0; j < t; j++ {
		lst := []int{}
		var n int
		scanf("%d\n", &n)
		var x int
		for ele := 0; ele < n-1; ele++ {
			scanf("%d ", &x)
			lst = append(lst, x)
		}
		scanf("%d\n", &x)
		lst = append(lst, x)
		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)
			for i := 0; i < len(ans)-1; i += 2 {
				fmt.Println(ans[i], ans[i+1])
			}
		}

		// ws.Flush()

	}

}

package main

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

var bytes []byte
var l, max int

func fastScan() int {
	b := bytes[l]

	// Check if the bytes is not a number
	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	result := 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > max {
			return result
		}
		b = bytes[l]
	}
	return result
}

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

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

func main() {
	// fmt.Println("hello")
	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	max = len(bytes) - 1
	defer writer.Flush()
	// ws := bufio.NewWriter(os.Stdout)
	// scanf("%d %d\n", &a, &b)
	// printf("%d\n", a+b)
	var t int
	scanf("%d \n", &t)

	for j := 0; j < t; j++ {
		lst := []int{}
		var n int
		scanf("%d \n", &n)
		var x int
		for ele := 0; ele < n; ele++ {
			scanf("%d \n", &x)
			lst = append(lst, x)
		}

		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)
			for i := 0; i < len(ans)-1; i += 2 {
				fmt.Println(ans[i], ans[i+1])
			}
		}

		// ws.Flush()

	}

}

package main

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

var bytes []byte
var l, max int

func fastScan() int {
	b := bytes[l]

	// Check if the bytes is not a number
	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	result := 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > max {
			return result
		}
		b = bytes[l]
	}
	return result
}

func main() {
	// fmt.Println("hello")
	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	max = len(bytes) - 1

	// ws := bufio.NewWriter(os.Stdout)
	var t int
	t = fastScan()

	for j := 0; j < t; j++ {
		lst := []int{}
		n := fastScan()
		var x int
		for ele := 0; ele < n; ele++ {
			x = fastScan()
			lst = append(lst, x)
		}

		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)
			for i := 0; i < len(ans)-1; i += 2 {
				fmt.Println(ans[i], ans[i+1])
			}
		}

		// ws.Flush()

	}

}

package main

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

var bytes []byte
var l, max int

func fastScan() int {
	b := bytes[l]

	// Check if the bytes is not a number
	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	result := 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > max {
			return result
		}
		b = bytes[l]
	}
	return result
}

func main() {
	// fmt.Println("hello")
	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	max = len(bytes) - 1

	// ws := bufio.NewWriter(os.Stdout)
	t := fastScan()

	for j := 0; j < t; j++ {
		lst := []int{}
		n := fastScan()
		var x int
		for ele := 0; ele < n; ele++ {
			x = fastScan()
			lst = append(lst, x)
		}

		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)
			for i := 0; i < len(ans)-1; i += 2 {
				fmt.Println(ans[i], ans[i+1])
			}
		}

		// ws.Flush()

	}

}

package main

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

var bytes []byte
var l, max int

func fastScan() int {
	b := bytes[l]

	// Check if the bytes is not a number
	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	result := 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > max {
			return result
		}
		b = bytes[l]
	}
	return result
}

func main() {
	// fmt.Println("hello")
	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	max = len(bytes) - 1

	// ws := bufio.NewWriter(os.Stdout)
	t := fastScan()

	for j := 0; j < t; j++ {
		lst := []int{}
		n := fastScan()
		var x int
		for ele := 0; ele < n; ele++ {
			x = fastScan()
			lst = append(lst, x)
		}

		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)
			for i := 0; i < int(len(ans)/2-1); i += 2 {
				fmt.Println(ans[i], ans[i+1])
			}
		}

		// ws.Flush()

	}

}

package main

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

var bytes []byte
var l, max int

func fastScan() int {
	b := bytes[l]

	// Check if the bytes is not a number
	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	result := 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > max {
			return result
		}
		b = bytes[l]
	}
	return result
}

func main() {
	// fmt.Println("hello")
	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	max = len(bytes) - 1

	// ws := bufio.NewWriter(os.Stdout)
	t := fastScan()

	for j := 0; j < t; j++ {
		lst := []int{}
		n := fastScan()
		var x int
		for ele := 0; ele < n; ele++ {
			x = fastScan()
			lst = append(lst, x)
		}

		if n%2 == 1 {
			fmt.Println(-1)
		} else {
			ans := []int{}
			for i := 0; i < n-1; i += 2 {
				if lst[i] == lst[i+1] {
					ans = append(ans, i+1, i+2)
				} else {
					ans = append(ans, i+1, i+1, i+2, i+2)
				}
			}
			fmt.Println(len(ans) / 2)
			for i := 0; i < int(len(ans)/2); i += 2 {
				fmt.Println(ans[i], ans[i+1])
			}
		}

		// ws.Flush()

	}

}

package main

import (
	."fmt"
	."os"
)

func solve(){
	var n int
	Fscan(Stdin, &n)
	sz := make([]int, n)
	for i := 0; i < n; i++ {
		Fscan(Stdin, &sz[i])
	}
	tot := 0
	last := 0
	break_arr := make([]int, n)
	for i := 0; i < n; i++{
		if last == 0{
			last = sz[i]
			tot = sz[i]
		}else{
			if sz[i] == last{
				tot = 0
			}else{
				if tot == 0{
					break_arr[i - 1] = 1
					tot = sz[i]
					last = sz[i]
				}else{
					break_arr[i - 1] = 1
					break_arr[i] = 1
					tot = 0
					last = 0
				}
			}
		}
	}
	// for i := 0; i < n; i ++{
	// 	Fprintln(Stdout, break_arr[i])
	// }
	if tot == 0{
		break_arr[n - 1] = 1
		out_n := 0
		for i := 0; i < n; i++{
			if break_arr[i] == 1{
				out_n ++
			}
		}
		Fprintln(Stdout, out_n)
		l := 1
		for i := 0; i < n; i++{
			if break_arr[i] == 1{
				Fprintln(Stdout, l, i + 1)
				l = i + 2
			}
		}
	}else{
		Fprintln(Stdout, -1)
	}
}

func main(){
	var t int
	Fscan(Stdin, &t)
	for ; t > 0; t--{
		solve()
	}
}

package main

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

type seg struct {
	l int
	r int
}

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, rsum int
		fmt.Fscan(r, &n)
		a := make([]int, n)

		for i := range a {
			fmt.Fscan(r, &a[i])
			rsum += (2 + a[i]) % 2
		}

		if rsum % 2 == 1 {
			fmt.Fprintln(w, -1)
		} else {
			segc := 0
			segs := make([]seg, n)
			for j := 0; j < n; j += 2 {
				if a[j] == a[j+1] {
					segs[segc] = seg{j, j+1}
					segc++
				} else {
					segs[segc] = seg{j, j}
					segs[segc+1] = seg{j+1, j+1}
					segc += 2
				}
			}

			fmt.Fprintln(w, segc)
			for j := 0; j < segc; j++ {
				fmt.Fprintln(w, segs[j].l, segs[j].r)
			}
		}
	}
}

package main

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

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

	var epochs int
	fmt.Fscan(r, &epochs)
	for ; epochs > 0; epochs-- {
		var n, n1, n2 int
		fmt.Fscan(r, &n)

		if n&1 == 1 {
			for i := 0; i <= n; i++ {
				fmt.Fscan(r, &n1)
			}
			fmt.Fprintln(w, "-1")
		} else {
			list := []int{}
			flag := 0
			for i := 1; i <= n; i += 2 {
				fmt.Fscan(r, &n1, &n2)
				if n1 == n2 {
					if flag == 1 {
						list[len(list)-1] = i + 1
					} else {
						list = append(list, i, i+1)
					}
					flag = 1
				} else {
					list = append(list, i, i, i+1, i+1)
					flag = 0
				}
			}

			fmt.Fprintln(w, len(list)>>1)
			for i := 0; i < len(list); i += 2 {
				fmt.Fprintln(w, list[i], list[i+1])
			}
		}
	}
}

package main

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

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

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

		if n&1 == 1 {
			fmt.Fprintln(w, "-1")
		} else {
			list := []int{}
			flag := 0
			var n1, n2 int
			for i := 1; i <= n; i += 2 {
				fmt.Fscan(r, &n1)
				fmt.Fscan(r, &n2)
				if n1 == n2 {
					if flag == 1 {
						list[len(list)-1] = i + 1
					} else {
						list = append(list, i, i+1)
					}
					flag = 1
				} else {
					list = append(list, i, i, i+1, i+1)
					flag = 0
				}
			}

			fmt.Fprintln(w, len(list)>>1)
			for i := 0; i < len(list); i += 2 {
				fmt.Fprintln(w, list[i], list[i+1])
			}
		}
	}
}

package main

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

func main() {
	var epochs int
	fmt.Scanf("%d\n", &epochs)
	res := ""
	for ; epochs > 0; epochs-- {
		var n int
		fmt.Scanf("%d\n", &n)
		scanner := bufio.NewScanner(os.Stdin)
		scanner.Split(bufio.ScanWords)
		list := make([]int, 0, n)
		for i := n; i > 0 && scanner.Scan(); i-- {
			tmp, _ := strconv.Atoi(scanner.Text())
			list = append(list, tmp)
		}

		if n&1 == 1 {
			res += "-1\n"
		} else {
			k := 0
			line := ""
			for i := 0; i < len(list); i += 2 {
				if list[i] == list[i+1] {
					// + -
					line += fmt.Sprintf("%d %d\n", i+1, i+2)
					k++
				} else {
					// + +
					line += fmt.Sprintf("%d %d\n", i+1, i+1)
					line += fmt.Sprintf("%d %d\n", i+2, i+2)
					k++
					k++
				}
			}
			res += fmt.Sprintf("%d\n%s", k, line)
		}
	}
	fmt.Print(res)
}

package main

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

func main() {
	var epochs int
	fmt.Scanf("%d\n", &epochs)
	for ; epochs > 0; epochs-- {
		var n int
		fmt.Scanf("%d\n", &n)
		scanner := bufio.NewScanner(os.Stdin)
		scanner.Split(bufio.ScanWords)
		list := make([]int, 0, n)
		for i := n; i > 0 && scanner.Scan(); i-- {
			tmp, _ := strconv.Atoi(scanner.Text())
			list = append(list, tmp)
		}

		if n&1 == 1 {
			fmt.Println("-1")
		} else {
			k := 0
			res := ""
			for i := 0; i < len(list); i += 2 {
				if list[i] == list[i+1] {
					// + -
					res += fmt.Sprintf("%d %d\n", i+1, i+2)
					k++
				} else {
					// + +
					res += fmt.Sprintf("%d %d\n", i+1, i+1)
					res += fmt.Sprintf("%d %d\n", i+2, i+2)
					k++
					k++
				}
			}
			fmt.Printf("%d\n%s", k, res)
		}
	}
}

package main

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

func main() {
	var epochs int
	fmt.Scanln(&epochs)
	for ; epochs > 0; epochs-- {
		var n int
		fmt.Scanf("%d\n", &n)
		scanner := bufio.NewScanner(os.Stdin)
		scanner.Split(bufio.ScanWords)
		list := make([]int, 0, n)
		for i := n; i > 0 && scanner.Scan(); i-- {
			tmp, _ := strconv.Atoi(scanner.Text())
			list = append(list, tmp)
		}

		if n&1 == 1 {
			fmt.Println("-1")
		} else {
			m := 0
			res := ""
			for i := 0; i < len(list); i += 2 {
				if list[i] == list[i+1] {
					// + -
					res += fmt.Sprintf("%d %d\n", i+1, i+2)
					m++
				} else {
					// + +
					res += fmt.Sprintf("%d %d\n", i+1, i+1)
					res += fmt.Sprintf("%d %d\n", i+2, i+2)
					m++
					m++
				}
			}
			fmt.Printf("%d\n%s", m, res)
		}
	}
}

package main

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

func main() {
	var epochs int
	fmt.Scanln(&epochs)
	for ; epochs > 0; epochs-- {
		var n int
		fmt.Scanln(&n)
		scanner := bufio.NewScanner(os.Stdin)
		scanner.Split(bufio.ScanWords)
		list := make([]int, 0, n)
		for i := n; i > 0 && scanner.Scan(); i-- {
			tmp, _ := strconv.Atoi(scanner.Text())
			list = append(list, tmp)
		}

		if n&1 == 1 {
			fmt.Println("-1")
		} else {
			m := 0
			res := ""
			for i := 0; i < len(list); i += 2 {
				if list[i] == list[i+1] {
					// + -
					res += fmt.Sprintf("%d %d\n", i+1, i+2)
					m++
				} else {
					// + +
					res += fmt.Sprintf("%d %d\n", i+1, i+1)
					res += fmt.Sprintf("%d %d\n", i+2, i+2)
					m++
					m++
				}
			}
			fmt.Printf("%d\n%s", m, res)
		}
	}
}


You came to a local shop and want to buy some chocolate bars. There are $$$n$$$ bars in the shop, $$$i$$$-th of them costs $$$a_i$$$ coins (and you want to buy all of them).You have $$$m$$$ different coupons that allow you to buy chocolate bars. $$$i$$$-th coupon allows you to buy $$$q_i$$$ chocolate bars while you have to pay only for the $$$q_i - 1$$$ most expensive ones (so, the cheapest bar of those $$$q_i$$$ bars is for free).You can use only one coupon; if you use coupon $$$i$$$, you have to choose $$$q_i$$$ bars and buy them using the coupon, and buy all the remaining $$$n - q_i$$$ bars without any discounts.To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.

The first line contains one integer $$$n$$$ ($$$2 \le n \le 3 \cdot 10^5$$$) — the number of chocolate bars in the shop. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the cost of $$$i$$$-th chocolate bar. The third line contains one integer $$$m$$$ ($$$1 \le m \le n - 1$$$) — the number of coupons you have. The fourth line contains $$$m$$$ integers $$$q_1$$$, $$$q_2$$$, ..., $$$q_m$$$ ($$$2 \le q_i \le n$$$), where $$$q_i$$$ is the number of chocolate bars you have to buy using $$$i$$$-th coupon so that the least expensive of them will be for free. All values of $$$q_i$$$ are pairwise distinct.

Print $$$m$$$ integers, $$$i$$$-th of them should be the minimum amount of money you have to pay if you buy $$$q_i$$$ bars with $$$i$$$-th coupon, and all the remaining bars one by one for their full price.

NoteConsider the first example.If we use the first coupon, we may choose chocolate bars having indices $$$1$$$, $$$6$$$ and $$$7$$$, and we pay $$$18$$$ coins for them and $$$9$$$ coins for all other bars.If we use the second coupon, we may choose chocolate bars having indices $$$1$$$, $$$5$$$, $$$6$$$ and $$$7$$$, and we pay $$$25$$$ coins for them and $$$5$$$ coins for all other bars.

package main

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

type SA []int

func (s SA) Len() int {
	return len(s)
}

func (s SA) Swap(a, b int) {
	tmp := s[a]
	s[a] = s[b]
	s[b] = tmp
}
func (s SA) Less(i, j int) bool {
	if s[i] > s[j] {
		return true
	}
	return false
}
func main() {
	buf := bufio.NewReader(os.Stdin)

	var n int
	var sum int64 = 0
	fmt.Fscanf(buf, "%d\n", &n)

	mat := make(SA, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &mat[i])
		sum += int64(mat[i])
	}
	fmt.Fscanf(buf, "\n")
	sort.Sort(mat)
	var m int
	fmt.Fscanf(buf, "%d\n", &m)
	mp := make([]int, n)
	for i:= 0;i < m;i++{
		fmt.Fscanf(buf, "%d", &mp[i])
	}
	fmt.Fscanf(buf, "\n")
	for i:= 0;i < m;i++{
		fmt.Printf("%d\n", sum-int64(mat[mp[i]-1]))
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &a[i])
	}
	fmt.Fscanf(in, "\n")

	sum := int64(0)
	sort.Ints(a)
	b := make([]int, 0)
	for i := 0; i < n; i++ {
		b = append(b, a[n-1-i])
		sum += int64(b[i])
	}
	m := 0
	fmt.Fscanf(in, "%d\n", &m)
	//fmt.Println(m)
	q := 0
	for i := 0; i < m; i++ {
		fmt.Fscanf(in, "%d", &q)
		fmt.Fprintf(out, "%d\n", sum-int64(b[q-1]))
	}
	return
}

package main

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

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

func minll(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

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

func maxll(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

func main() {
	defer Flush()

	n := readi()
	a := make([]int64, n)
	for i := range a {
		a[i] = readll()
	}
	m := readi()
	q := make([]int, m)
	for i := range q {
		q[i] = readi()
	}

	sort.Slice(a, func(i, j int) bool { return a[i] > a[j] })
	var s int64
	for i := range a {
		s += a[i]
	}

	for _, v := range q {
		v--
		println(s - a[v])
	}

}

package main

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

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

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

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

func main() {
	defer writer.Flush()
	var n, m, t1 int

	var tot int64

	arr := []int{}

	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		scanf("%d", &t1)
		tot += int64(t1)
		arr = append(arr, t1)
	}

	sort.Ints(arr)

	scanf("\n%d\n", &m)

	for i := 0; i < m; i++ {
		scanf("%d", &t1)
		//t1--
		printf("%d\n", tot-int64(arr[n-t1]))
	}

}


You are given 2 arrays $$$a$$$ and $$$b$$$, both of size $$$n$$$. You can swap two elements in $$$b$$$ at most once (or leave it as it is), and you are required to minimize the value $$$$$$\sum_{i}|a_{i}-b_{i}|.$$$$$$Find the minimum possible value of this sum.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le {10^9}$$$).  The third line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le {10^9}$$$).

Output the minimum value of $$$\sum_{i}|a_{i}-b_{i}|$$$.

NoteIn the first example, we can swap the first and fifth element in array $$$b$$$, so that it becomes $$$[ 5, 2, 3, 4, 1 ]$$$.Therefore, the minimum possible value of this sum would be $$$|5-5| + |4-2| + |3-3| + |2-4| + |1-1| = 4$$$.In the second example, we can swap the first and second elements. So, our answer would be $$$2$$$.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1513F(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

	var n, d int
	Fscan(in, &n)
	type pair struct{ x, y, t int }
	a := make([]pair, n)
	for i := range a {
		Fscan(in, &a[i].x)
	}
	ans := int64(0)
	for i := range a {
		Fscan(in, &a[i].y)
		if a[i].x > a[i].y {
			a[i] = pair{a[i].y, a[i].x, 1}
		}
		ans += int64(a[i].y - a[i].x)
	}
	sort.Slice(a, func(i, j int) bool { a, b := a[i], a[j]; return a.x < b.x || a.x == b.x && a.y > b.y })
	mx := [2]int{}
	for _, p := range a {
		mx[p.t] = max(mx[p.t], p.y)
		d = max(d, min(p.y, mx[p.t^1])-p.x)
	}
	Fprint(out, ans-int64(d*2))
}
func main() { CF1513F(os.Stdin, os.Stdout) }

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	var n, d int
	Fscan(in, &n)
	type pair struct{ x, y, t int }
	a := make([]pair, n)
	for i := range a {
		Fscan(in, &a[i].x)
	}
	ans := int64(0)
	for i := range a {
		Fscan(in, &a[i].y)
		if a[i].x > a[i].y {
			a[i].t = 1
			a[i].x, a[i].y = a[i].y, a[i].x
		}
		ans += int64(a[i].y - a[i].x)
	}
	sort.Slice(a, func(i, j int) bool { a, b := a[i], a[j]; return a.x < b.x || a.x == b.x && a.y > b.y })
	mx := [2]int{}
	for _, p := range a {
		if p.y > mx[p.t] {
			mx[p.t] = p.y
		}
		if mx[p.t^1] < p.y {
			p.y = mx[p.t^1]
		}
		if p.y-p.x > d {
			d = p.y-p.x
		}
	}
	Print(ans - int64(d*2))
}

package main

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

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

	var n int
	Fscan(in, &n)
	a := make([]pair, n)
	for i := range a {
		Fscan(in, &a[i].x)
	}
	for i := range a {
		Fscan(in, &a[i].y)
	}
	sum := int64(0)
	for _, p := range a {
		sum += int64(abs(p.x - p.y))
	}
	ans := sum
	sort.Slice(a, func(i, j int) bool { return a[i].x < a[j].x })

	mi, mx := 0, 0
	for i := 1; i < n; i++ {
		p := a[i]
		if p.x > p.y {
			q := a[mx]
			old := abs(q.x-q.y) + abs(p.x-p.y)
			new := abs(q.x-p.y) + abs(p.x-q.y)
			ans = min(ans, sum-int64(old)+int64(new))
		} else {
			q := a[mi]
			old := abs(q.x-q.y) + abs(p.x-p.y)
			new := abs(q.x-p.y) + abs(p.x-q.y)
			ans = min(ans, sum-int64(old)+int64(new))
		}
		if a[i].y < a[mi].y {
			mi = i
		}
		if a[i].y > a[mx].y {
			mx = i
		}
	}
	Fprintln(out, ans)
}

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

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}


You are given an undirected tree consisting of $$$n$$$ vertices. An undirected tree is a connected undirected graph with $$$n - 1$$$ edges.Your task is to add the minimum number of edges in such a way that the length of the shortest path from the vertex $$$1$$$ to any other vertex is at most $$$2$$$. Note that you are not allowed to add loops and multiple edges.

The first line contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The following $$$n - 1$$$ lines contain edges: edge $$$i$$$ is given as a pair of vertices $$$u_i, v_i$$$ ($$$1 \le u_i, v_i \le n$$$). It is guaranteed that the given edges form a tree. It is guaranteed that there are no loops and multiple edges in the given edges.

Print a single integer — the minimum number of edges you have to add in order to make the shortest distance from the vertex $$$1$$$ to any other vertex at most $$$2$$$. Note that you are not allowed to add loops and multiple edges.

NoteThe tree corresponding to the first example:  The answer is $$$2$$$, some of the possible answers are the following: $$$[(1, 5), (1, 6)]$$$, $$$[(1, 4), (1, 7)]$$$, $$$[(1, 6), (1, 7)]$$$.The tree corresponding to the second example:  The answer is $$$0$$$.The tree corresponding to the third example:  The answer is $$$1$$$, only one possible way to reach it is to add the edge $$$(1, 3)$$$.

package main

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

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

var tree = make(map[int][]int)
var ans = 0

func main() {
	var n int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &n)

	var x, y int
	for i := 1; i < n; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d %d", &x, &y)
		add(x, y)
		add(y, x)
	}
	dfs(1, 1)
	fmt.Println(ans)
}
func dfs(node, father int) int {
	dis := 2
	for _, to := range tree[node] {
		if to == father {
			continue
		}
		dis = min(dis, dfs(to, node))
	}
	if dis == 0 && father != 1 {
		ans++
	}
	return (dis + 1) % 3
}
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func add(x, y int) {
	if _, ok := tree[x]; ok {
		tree[x] = append(tree[x], y)
	} else {
		tree[x] = []int{y}
	}
}

package main

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

type Node struct {
	v     int
	depth int
}

type NodeHeap []*Node

func (h NodeHeap) Len() int {
	return len(h)
}

func (h NodeHeap) Less(i, j int) bool {
	return h[i].depth > h[j].depth
}

func (h NodeHeap) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h *NodeHeap) Push(val interface{}) {
	*h = append(*h, val.(*Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	item := old[n-1]
	*h = old[0 : n-1]
	return item
}

var tree [][]int
var depth []int
var parent []int
var childrenCount []int
var cut []bool
var nodes int
var leaves NodeHeap
var ans int

func initialize() {
	sz := nodes + 1
	tree = make([][]int, sz)
	depth = make([]int, sz)
	parent = make([]int, sz)
	childrenCount = make([]int, sz)
	leaves = make(NodeHeap, 0)
	cut = make([]bool, sz)
	heap.Init(&leaves)
}

func readTree() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &nodes)

	initialize()

	for i := 0; i < nodes-1; i++ {
		var v1, v2 int
		fmt.Fscanf(buf, "%d %d\n", &v1, &v2)
		tree[v1] = append(tree[v1], v2)
		tree[v2] = append(tree[v2], v1)
	}
}

func dfs(v, d int) {
	depth[v] = d
	for _, child := range tree[v] {
		if parent[child] == 0 {
			parent[child] = v
			childrenCount[v]++
			dfs(child, d+1)
		}
	}
	if childrenCount[v] == 0 && d > 2 {
		heap.Push(&leaves, &Node{v, d})
	}
}

func main() {
	readTree()
	parent[1] = -1
	dfs(1, 0)
	for {
		if len(leaves) == 0 {
			break
		}
		top := heap.Pop(&leaves).(*Node)
		p1 := parent[top.v]
		if cut[p1] {
			continue
		}
		depth[p1] = 1
		cut[p1] = true
		childrenCount[p1] = 0
		for _, child := range tree[p1] {
			if depth[child] > 2 {
				depth[child] = 2
			}
		}
		p2 := parent[p1]
		if p2 != -1 {
			childrenCount[p2]--
			p3 := parent[p2]
			if p3 != -1 {
				if childrenCount[p2] == 0 {
					childrenCount[p3]--
				}
				if childrenCount[p2] == 0 && childrenCount[p3] == 0 && depth[p3] > 2 {
					heap.Push(&leaves, &Node{p3, depth[p3]})
				}
			}
		}
		ans++
	}
	fmt.Println(ans)
}

package main

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

type Node struct {
	v     int
	depth int
}

type NodeHeap []*Node

func (h NodeHeap) Len() int {
	return len(h)
}

func (h NodeHeap) Less(i, j int) bool {
	return h[i].depth > h[j].depth
}

func (h NodeHeap) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h *NodeHeap) Push(val interface{}) {
	*h = append(*h, val.(*Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	item := old[n-1]
	*h = old[0 : n-1]
	return item
}

var tree [][]int
var depth []int
var parent []int
var childrenCount []int
var cut []bool
var nodes int
var leaves NodeHeap
var ans int

func initialize() {
	sz := nodes + 1
	tree = make([][]int, sz)
	depth = make([]int, sz)
	parent = make([]int, sz)
	childrenCount = make([]int, sz)
	leaves = make(NodeHeap, 0)
	cut = make([]bool, sz)
	heap.Init(&leaves)
}

func readTree() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &nodes)

	initialize()

	for i := 0; i < nodes-1; i++ {
		var v1, v2 int
		fmt.Fscanf(buf, "%d %d\n", &v1, &v2)
		tree[v1] = append(tree[v1], v2)
		tree[v2] = append(tree[v2], v1)
	}
}

func dfs(v, d int) {
	depth[v] = d
	for _, child := range tree[v] {
		if parent[child] == 0 {
			parent[child] = v
			childrenCount[v]++
			dfs(child, d+1)
		}
	}
	if childrenCount[v] == 0 && d > 2 {
		heap.Push(&leaves, &Node{v, d})
	}
}

func main() {
	readTree()
	parent[1] = -1
	dfs(1, 0)
	for {
		if len(leaves) == 0 {
			break
		}
		top := heap.Pop(&leaves).(*Node)
		v, p := top.v, parent[top.v]
		if cut[p] {
			continue
		}
		if p != -1 {
			depth[p] = 1
			cut[p] = true
			for _, child := range tree[v] {
				if child != p {
					depth[child] = 2
					childrenCount[p]--
				}
			}
			p2 := parent[p]
			if p2 != -1 {
				childrenCount[p2]--
				if childrenCount[p2] == 0 && depth[p2] > 2 && !cut[p2] {
					heap.Push(&leaves, &Node{p2, depth[p2]})
				}
			}
		}
		ans++
	}
	fmt.Println(ans)
}

package main

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

type Node struct {
	v     int
	depth int
}

type NodeHeap []*Node

func (h NodeHeap) Len() int {
	return len(h)
}

func (h NodeHeap) Less(i, j int) bool {
	return h[i].depth > h[j].depth
}

func (h NodeHeap) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h *NodeHeap) Push(val interface{}) {
	*h = append(*h, val.(*Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	item := old[n-1]
	*h = old[0 : n-1]
	return item
}

var tree [][]int
var depth []int
var parent []int
var childrenCount []int
var cut []bool
var nodes int
var leaves NodeHeap
var ans int

func initialize() {
	sz := nodes + 1
	tree = make([][]int, sz)
	depth = make([]int, sz)
	parent = make([]int, sz)
	childrenCount = make([]int, sz)
	leaves = make(NodeHeap, 0)
	cut = make([]bool, sz)
	heap.Init(&leaves)
}

func readTree() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &nodes)

	initialize()

	for i := 0; i < nodes-1; i++ {
		var v1, v2 int
		fmt.Fscanf(buf, "%d %d\n", &v1, &v2)
		tree[v1] = append(tree[v1], v2)
		tree[v2] = append(tree[v2], v1)
	}
}

func dfs(v, d int) {
	depth[v] = d
	for _, child := range tree[v] {
		if parent[child] == 0 {
			parent[child] = v
			childrenCount[v]++
			dfs(child, d+1)
		}
	}
	if childrenCount[v] == 0 && d > 2 {
		heap.Push(&leaves, &Node{v, d})
	}
}

func main() {
	readTree()
	parent[1] = -1
	dfs(1, 0)
	for {
		if len(leaves) == 0 {
			break
		}
		top := heap.Pop(&leaves).(*Node)
		p1 := parent[top.v]
		if cut[p1] {
			continue
		}
		depth[p1] = 1
		cut[p1] = true
		childrenCount[p1] = 0
		for _, child := range tree[p1] {
			if depth[child] > 2 {
				depth[child] = 2
			}
		}
		p2 := parent[p1]
		if p2 != -1 {
			p3 := parent[p2]
			childrenCount[p2]--
			if p3 != -1 {
				if childrenCount[p2] == 0 {
					childrenCount[p3]--
				}
				if childrenCount[p2] == 0 && childrenCount[p3] == 1 && depth[p3] > 2 {
					heap.Push(&leaves, &Node{p3, depth[p3]})
				}
			}
		}
		ans++
	}
	fmt.Println(ans)
}

package main

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

type Node struct {
	v     int
	depth int
}

type NodeHeap []*Node

func (h NodeHeap) Len() int {
	return len(h)
}

func (h NodeHeap) Less(i, j int) bool {
	return h[i].depth > h[j].depth
}

func (h NodeHeap) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h *NodeHeap) Push(val interface{}) {
	*h = append(*h, val.(*Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	item := old[n-1]
	*h = old[0 : n-1]
	return item
}

var tree [][]int
var depth []int
var parent []int
var childrenCount []int
var cut []bool
var nodes int
var leaves NodeHeap
var ans int

func initialize() {
	sz := nodes + 1
	tree = make([][]int, sz)
	depth = make([]int, sz)
	parent = make([]int, sz)
	childrenCount = make([]int, sz)
	leaves = make(NodeHeap, 0)
	cut = make([]bool, sz)
	heap.Init(&leaves)
}

func readTree() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &nodes)

	initialize()

	for i := 0; i < nodes-1; i++ {
		var v1, v2 int
		fmt.Fscanf(buf, "%d %d\n", &v1, &v2)
		tree[v1] = append(tree[v1], v2)
		tree[v2] = append(tree[v2], v1)
	}
}

func dfs(v, d int) {
	depth[v] = d
	for _, child := range tree[v] {
		if parent[child] == 0 {
			parent[child] = v
			childrenCount[v]++
			dfs(child, d+1)
		}
	}
	if childrenCount[v] == 0 && d > 2 {
		heap.Push(&leaves, &Node{v, d})
	}
}

func main() {
	readTree()
	parent[1] = -1
	dfs(1, 0)
	for {
		if len(leaves) == 0 {
			break
		}
		top := heap.Pop(&leaves).(*Node)
		p := parent[top.v]
		if cut[p] {
			continue
		}
		if p != -1 {
			depth[p] = 1
			cut[p] = true
			for _, child := range tree[p] {
				if child != p {
					depth[child] = 2
					childrenCount[p]--
				}
			}
			p2 := parent[p]
			if p2 != -1 {
				p3 := parent[p2]
				childrenCount[p2]--
				if p3 != -1 && childrenCount[p2] == 0 && childrenCount[p3] == 1 && !cut[p3] && depth[p3] > 2 {
					heap.Push(&leaves, &Node{p3, depth[p3]})
				}
			}
		}
		ans++
	}
	fmt.Println(ans)
}

package main

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

type Node struct {
	v     int
	depth int
}

type NodeHeap []*Node

func (h NodeHeap) Len() int {
	return len(h)
}

func (h NodeHeap) Less(i, j int) bool {
	return h[i].depth > h[j].depth
}

func (h NodeHeap) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h *NodeHeap) Push(val interface{}) {
	*h = append(*h, val.(*Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	item := old[n-1]
	*h = old[0 : n-1]
	return item
}

var tree [][]int
var depth []int
var parent []int
var childrenCount []int
var cut []bool
var nodes int
var leaves NodeHeap
var ans int

func initialize() {
	sz := nodes + 1
	tree = make([][]int, sz)
	depth = make([]int, sz)
	parent = make([]int, sz)
	childrenCount = make([]int, sz)
	leaves = make(NodeHeap, 0)
	cut = make([]bool, sz)
	heap.Init(&leaves)
}

func readTree() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &nodes)

	initialize()

	for i := 0; i < nodes-1; i++ {
		var v1, v2 int
		fmt.Fscanf(buf, "%d %d\n", &v1, &v2)
		tree[v1] = append(tree[v1], v2)
		tree[v2] = append(tree[v2], v1)
	}
}

func dfs(v, d int) {
	depth[v] = d
	for _, child := range tree[v] {
		if parent[child] == 0 {
			parent[child] = v
			childrenCount[v]++
			dfs(child, d+1)
		}
	}
	if childrenCount[v] == 0 && d > 2 {
		heap.Push(&leaves, &Node{v, d})
	}
}

func main() {
	readTree()
	parent[1] = -1
	dfs(1, 0)
	for {
		if len(leaves) == 0 {
			break
		}
		top := heap.Pop(&leaves).(*Node)
		p := parent[top.v]
		if cut[p] {
			continue
		}
		if p != -1 {
			depth[p] = 1
			cut[p] = true
			for _, child := range tree[p] {
				if child != p {
					depth[child] = 2
					childrenCount[p]--
				}
			}
			p2 := parent[p]
			if p2 != -1 {
				p3 := parent[p2]
				childrenCount[p2]--
				if p3 != -1 && childrenCount[p2] == 0 && childrenCount[p3] == 1 && depth[p3] > 2 {
					heap.Push(&leaves, &Node{p3, depth[p3]})
				}
			}
		}
		ans++
	}
	fmt.Println(ans)
}


You are given an array a of size n, and q queries to it. There are queries of two types:   1 li ri — perform a cyclic shift of the segment [li, ri] to the right. That is, for every x such that li ≤ x < ri new value of ax + 1 becomes equal to old value of ax, and new value of ali becomes equal to old value of ari;  2 li ri — reverse the segment [li, ri].  There are m important indices in the array b1, b2, ..., bm. For each i such that 1 ≤ i ≤ m you have to output the number that will have index bi in the array after all queries are performed.

The first line contains three integer numbers n, q and m (1 ≤ n, q ≤ 2·105, 1 ≤ m ≤ 100).  The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).  Then q lines follow. i-th of them contains three integer numbers ti, li, ri, where ti is the type of i-th query, and [li, ri] is the segment where this query is performed (1 ≤ ti ≤ 2, 1 ≤ li ≤ ri ≤ n).  The last line contains m integer numbers b1, b2, ..., bm (1 ≤ bi ≤ n) — important indices of the array.

Print m numbers, i-th of which is equal to the number at index bi after all queries are done.

package main

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

func main() {
	bytes, _ := ioutil.ReadAll(bufio.NewReader(os.Stdin))

	lines := strings.Split(string(bytes), "\n")
	for i, _ := range lines {
		if i + 1 < len(lines) && len(lines[i]) > 0 {
			lines[i] = lines[i][:len(lines[i])-1]
		}
	}

	tokens := strings.Split(lines[0], " ")
	n, _ := strconv.Atoi(tokens[0])
	q, _ := strconv.Atoi(tokens[1])
	m, _ := strconv.Atoi(tokens[2])

	a := make([]int, n)
	tokens = strings.Split(lines[1], " ")
	for i, _ := range a {
		a[i], _ = strconv.Atoi(tokens[i])
	}

	t := make([]int, q)
	l := make([]int, q)
	r := make([]int, q)
	for i, _ := range t {
		tokens = strings.Split(lines[2+i], " ")
		t[i], _ = strconv.Atoi(tokens[0])
		l[i], _ = strconv.Atoi(tokens[1])
		r[i], _ = strconv.Atoi(tokens[2])
		l[i]--
		r[i]--
	}

	b := make([]int, m)
	tokens = strings.Split(lines[2+q], " ")
	for i, _ := range b {
		b[i], _ = strconv.Atoi(tokens[i])
		b[i]--
	}

	for i := q - 1; i >= 0; i-- {
		if t[i] == 1 {
			for j, _ := range b {
				if l[i] <= b[j] && b[j] <= r[i] {
					b[j]--
					if b[j] < l[i] {
						b[j] = r[i]
					}
				}
			}
		} else {
			for j, _ := range b {
				if l[i] <= b[j] && b[j] <= r[i] {
					b[j] = r[i] - (b[j] - l[i])
				}
			}
		}
	}

	for i, _ := range b {
		if i > 0 {
			fmt.Print(" ")
		}
		fmt.Print(a[b[i]])
	}
	fmt.Println()
}

package main

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

func main() {
	bytes, _ := ioutil.ReadAll(bufio.NewReader(os.Stdin))

	lines := strings.Split(string(bytes), "\n")

	tokens := strings.Split(lines[0], " ")
	n, _ := strconv.Atoi(tokens[0])
	q, _ := strconv.Atoi(tokens[1])
	m, _ := strconv.Atoi(tokens[2])

	a := make([]int, n)
	tokens = strings.Split(lines[1], " ")
	for i, _ := range a {
		a[i], _ = strconv.Atoi(tokens[i])
	}

	t := make([]int, q)
	l := make([]int, q)
	r := make([]int, q)
	for i, _ := range t {
		tokens = strings.Split(lines[2+i], " ")
		t[i], _ = strconv.Atoi(tokens[0])
		l[i], _ = strconv.Atoi(tokens[1])
		r[i], _ = strconv.Atoi(tokens[2])
		l[i]--
		r[i]--
	}

	b := make([]int, m)
	tokens = strings.Split(lines[2+q], " ")
	for i, _ := range b {
		b[i], _ = strconv.Atoi(tokens[i])
		b[i]--
	}

	for i := q - 1; i >= 0; i-- {
		if t[i] == 1 {
			for j, _ := range b {
				if l[i] <= b[j] && b[j] <= r[i] {
					b[j]--
					if b[j] < l[i] {
						b[j] = r[i]
					}
				}
			}
		} else {
			for j, _ := range b {
				if l[i] <= b[j] && b[j] <= r[i] {
					b[j] = r[i] - (b[j] - l[i])
				}
			}
		}
	}

	for i, _ := range b {
		if i > 0 {
			fmt.Print(" ")
		}
		fmt.Print(a[b[i]])
	}
	fmt.Println()
}


There is a grid, consisting of $$$n$$$ rows and $$$m$$$ columns. Each cell of the grid is either free or blocked. One of the free cells contains a lab. All the cells beyond the borders of the grid are also blocked.A crazy robot has escaped from this lab. It is currently in some free cell of the grid. You can send one of the following commands to the robot: "move right", "move down", "move left" or "move up". Each command means moving to a neighbouring cell in the corresponding direction.However, as the robot is crazy, it will do anything except following the command. Upon receiving a command, it will choose a direction such that it differs from the one in command and the cell in that direction is not blocked. If there is such a direction, then it will move to a neighbouring cell in that direction. Otherwise, it will do nothing.We want to get the robot to the lab to get it fixed. For each free cell, determine if the robot can be forced to reach the lab starting in this cell. That is, after each step of the robot a command can be sent to a robot such that no matter what different directions the robot chooses, it will end up in a lab.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. The first line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^6$$$; $$$n \cdot m \le 10^6$$$) — the number of rows and the number of columns in the grid. The $$$i$$$-th of the next $$$n$$$ lines provides a description of the $$$i$$$-th row of the grid. It consists of $$$m$$$ elements of one of three types:    '.' — the cell is free;  '#' — the cell is blocked;  'L' — the cell contains a lab.  The grid contains exactly one lab. The sum of $$$n \cdot m$$$ over all testcases doesn't exceed $$$10^6$$$.

For each testcase find the free cells that the robot can be forced to reach the lab from. Given the grid, replace the free cells (marked with a dot) with a plus sign ('+') for the cells that the robot can be forced to reach the lab from. Print the resulting grid.

NoteIn the first testcase there is no free cell that the robot can be forced to reach the lab from. Consider a corner cell. Given any direction, it will move to a neighbouring border grid that's not a corner. Now consider a non-corner free cell. No matter what direction you send to the robot, it can choose a different direction such that it ends up in a corner.In the last testcase, you can keep sending the command that is opposite to the direction to the lab and the robot will have no choice other than move towards the lab.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1613E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := []pair{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}

	var T, n, m int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m)
		x, y := 0, -1
		g := make([][]byte, n)
		for i := range g {
			Fscan(in, &g[i])
			if y < 0 {
				x, y = i, bytes.IndexByte(g[i], 'L')
			}
		}
		for _, d := range dir4 {
			x, y := x+d.x, y+d.y
			if 0 <= x && x < n && 0 <= y && y < m && g[x][y] == '.' {
			o:
				for {
					dir := pair{}
					for _, d := range dir4 {
						if x, y := x+d.x, y+d.y; 0 <= x && x < n && 0 <= y && y < m && g[x][y] == '.' {
							if dir != (pair{}) {
								break o
							}
							dir = d
						}
					}
					g[x][y] = '+'
					if dir == (pair{}) {
						break
					}
					x += dir.x
					y += dir.y
				}
			}
		}
		for _, r := range g {
			Fprintf(out, "%s\n", r)
		}
	}
}
func main() { CF1613E(os.Stdin, os.Stdout) }

package main

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

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

var dirx = []int{-1, 1, 0, 0}
var diry = []int{0, 0, -1, 1}

type Coord struct {
	x int
	y int
}

func (c *Coord) move(d int) Coord {
	return Coord{x: c.x + dirx[d], y: c.y + diry[d]}
}

var queue = [1e6 + 100]Coord{}
var queueHead int
var queueTail int

func queuePush(p Coord) {
	queue[queueTail] = p
	queueTail++
}

func queuePop() Coord {
	var r = queue[queueHead]
	queueHead++
	return r
}

func solveCase() {
	var h, w int
	fmt.Fscan(in, &h, &w)
	w += 2
	h += 2
	var g [][]byte = make([][]byte, h)
	g[0] = []byte(strings.Repeat("#", w))
	g[h-1] = g[0]

	queueHead = 0
	queueTail = 0
	for i := 1; i+1 < h; i++ {
		var s string
		fmt.Fscan(in, &s)
		g[i] = []byte("#" + s + "#")
		for j := 0; j < w; j++ {
			if g[i][j] == 'L' {
				queuePush(Coord{x: i, y: j})
			}
		}
	}

	for queueHead < queueTail {
		var p = queuePop()
		for d1 := 0; d1 < 4; d1++ {
			var p1 = p.move(d1)
			if g[p1.x][p1.y] != '.' {
				continue
			}
			var count = 0
			for d2 := 0; d2 < 4; d2++ {
				var p2 = p1.move(d2)
				if g[p2.x][p2.y] == '.' {
					count++
				}
			}
			if count <= 1 {
				g[p1.x][p1.y] = '+'
				queuePush(p1)
			}
		}
	}

	for i := 1; i+1 < h; i++ {
		fmt.Fprintln(out, string(g[i][1:w-1]))
	}
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		solveCase()
	}
	out.Flush()
}


In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?).A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't.You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not.You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO".   The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise).  The string s2 describes a group of soldiers 2 through k + 1.  And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example.Find and print any solution. It can be proved that there always exists at least one solution.

The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise.

Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them.

Adam Bob Bob Cpqepqwer Limak Adam Bob Adam

R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc

NoteIn the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output:  First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO".  Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO".  Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES".  ...,  Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO".

package main

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

func solve() {
	n := readInt()
	k := readInt()
	m := n - k + 1
	ok := make([]bool, m)
	for i := 0; i < m; i++ {
		ok[i] = readString() == "YES"
	}
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = i
	}
	name := []rune("Aaa")
	names := make([]string, n)
	for i := 0; i < n; i++ {
		names[i] = string(name)
		if name[2] == 'z' {
			name[1]++
			name[2] = 'a'
		} else {
			name[2]++
		}
	}
	for i := 0; i < m; i++ {
		if !ok[i] {
			res[i+k-1] = res[i]
		}
	}
	for i := 0; i < n; i++ {
		if i > 0 {
			fmt.Printf(" ")
		}
		fmt.Printf(names[res[i]])
	}
	fmt.Println()
}

func dfs(a []rune, ok []bool, pos int, k int) {
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

package main

import (
	"fmt"
	"strings"
)

var maxUnits = 50

func generateNames() []string {
	names := make([]string, maxUnits)
	for i := 0; i < maxUnits; i++ {
		var name string
		for j := 0; j < i/26; j++ {
			name += "a"
		}

		names[i] = strings.Title(name + string('a'+i%26))
	}

	return names
}

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)
	splits := make([]string, n-k+1)

	for i := 0; i < n-k+1; i++ {
		fmt.Scan(&splits[i])
	}

	names := make([]string, n)
	generated := generateNames()

	for i := 0; i < k-1; i++ {
		names[i] = generated[i]
	}

	for i := k - 1; i < n; i++ {
		if splits[i-k+1] == "YES" {
			names[i] = generated[i]
		} else {
			names[i] = names[i-k+1]
		}
	}

	fmt.Println(strings.Join(names, " "))
}

package main

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

func str(now int) string {
	return "A" + string('a'+now/10) + string('a'+now%10)

}
func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()

	ans := make([]string, N)
	now := 0
	ans[0] = str(now)

	for i := 1; i <= N-K+1; i++ {
		switch sc.Next() {
		case "NO":
			ans[i+K-2] = ans[i-1]
			fallthrough
		case "YES":
			for j := 0; j < K-1; j++ {
				if ans[i+j] == "" {
					now++
					ans[i+j] = str(now)
				}
			}
		}
	}

	for i := 0; i < N; i++ {
		if i > 0 {
			fmt.Print(" ")
		}
		fmt.Print(ans[i])
	}

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

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

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

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

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

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

	return mp
}

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

package main

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

func solve() {
	n := readInt()
	k := readInt()
	m := n - k + 1
	ok := make([]bool, m)
	for i := 0; i < m; i++ {
		ok[i] = readString() == "YES"
	}
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = i
	}
	for i := 0; i < m; i++ {
		if !ok[i] {
			if i+1 != m {
				if ok[i+1] {
					res[i] = res[i+1]
				} else {
					res[i+1] = res[i]
				}
			} else {
				res[len(res)-1] = res[len(res)-2]
			}
		}
	}
	prev := -1
	name := []rune("Aaa")
	for i := 0; i < n; i++ {
		if i > 0 {
			fmt.Printf(" ")
		}
		if prev != res[i] {
			prev = res[i]
			if name[2] == 'z' {
				name[1]++
				name[2] = 'a'
			} else {
				name[2]++
			}
		}
		fmt.Printf(string(name))
	}
	fmt.Println()
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

package main

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

func solve() {
	n := readInt()
	k := readInt()
	m := n - k + 1
	ok := make([]bool, m)
	for i := 0; i < m; i++ {
		ok[i] = readString() == "YES"
	}
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = i + 1
	}
	for i := 0; i < m; i++ {
		if !ok[i] {
			if i+1 != m {
				if ok[i+1] {
					res[i] = res[i+1]
				} else {
					res[i+1] = res[i]
				}
			} else {
				res[len(res)-1] = res[len(res)-2]
			}
		}
	}
	prev := 0
	name := ""
	for i := 0; i < n; i++ {
		if prev != res[i] {
			prev = res[i]
			num := res[i]
			name = "A"
			for num > 0 {
				name += string('a' + num)
				num /= 26
			}
		}
		if i > 0 {
			fmt.Printf(" ")
		}
		fmt.Printf(name)
	}
	fmt.Println()
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

package main

import (
	"fmt"
	"strings"
)

var maxUnits = 50

func generateNames() []string {
	names := make([]string, maxUnits)
	for i := 0; i < maxUnits; i++ {
		var name string
		for j := 0; j < i/26; j++ {
			name += "a"
		}

		names[i] = name + string('a'+i%26)
	}

	return names
}

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)
	splits := make([]string, n-k+1)

	for i := 0; i < n-k+1; i++ {
		fmt.Scan(&splits[i])
	}

	names := make([]string, n)
	generated := generateNames()

	for i := 0; i < k-1; i++ {
		names[i] = generated[i]
	}

	for i := k - 1; i < n; i++ {
		if splits[i-k+1] == "YES" {
			names[i] = generated[i]
		} else {
			names[i] = names[i-k+1]
		}
	}

	fmt.Println(strings.Join(names, " "))
}