Petya loves computer games. Finally a game that he's been waiting for so long came out!The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values of  for all i from 1 to n. The expression ⌊ x⌋ denotes the result of rounding the number x down to the nearest integer.At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.

The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-th skill of the character.

The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units.

NoteIn the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to  lfloor frac{100}{10} rfloor +  lfloor frac{100}{10} rfloor = 10 + 10 =  20.In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is .In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to .

package main

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

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

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

	n, k := nextInt(), nextInt()
	a := make([]int, n)
	sum := 0

	for i := range a {
		a[i] = nextInt()
		sum += a[i] / 10
		a[i] %= 10
	}

	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	for i := 0; i < len(a) && k > 0; i++ {
		if a[i] == 0 {
			break
		}

		if k+a[i] >= 10 {
			sum += 1
			k -= 10 - a[i]
		}
	}

	for sum < n*10 && k >= 10 {
		sum += 1
		k -= 10
	}

	println(sum)
}

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

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

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

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

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

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

package main

import (
	"fmt"
	"sort"
)

type slice []int

func (a slice) Len() int           { return len(a) }
func (a slice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a slice) Less(i, j int) bool { return a[j]%10 < a[i]%10 }

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make(slice, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	sort.Sort(a)
	for i := range a {
		if a[i] == 100 {
			continue
		}
		r := 10 - a[i]%10
		if k -= r; k > -1 {
			a[i] += r
		}
	}
	for i := range a {
		r := 100 - a[i]
		if k > r {
			a[i] += r
			k -= r
		} else if k > 0 {
			a[i] += k
			break
		}
	}
	ans := 0
	for _, v := range a {
		ans += v / 10
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
	"sort"
)

type slice []int

func (a slice) Len() int           { return len(a) }
func (a slice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a slice) Less(i, j int) bool { return a[j]%10 < a[i]%10 }

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make(slice, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	sort.Sort(a)
	for i := range a {
		r := 10 - a[i]%10
		if k -= r; k > -1 {
			a[i] += r
		}
		if a[i] > 100 {
			r = a[i] - 100;
			a[i] = 100
			k += r
		}
	}
	for i := range a {
		r := 100 - a[i]
		if k > r {
			a[i] += r
			k -= r
		} else if k > 0 {
			a[i] += k
			break
		}
	}
	ans := 0
	for _, v := range a {
		ans += v / 10
	}
	fmt.Println(ans)
}

package main

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

func getCost(n uint8) uint8 {
	if n == 100 {
		return 0
	}
	return (n/10+1)*10 - n
}

type byCost []uint8

func (this byCost) Len() int           { return len(this) }
func (this byCost) Swap(i, j int)      { this[i], this[j] = this[j], this[i] }
func (this byCost) Less(i, j int) bool { return getCost(this[i]) < getCost(this[j]) }

func main() {
	//defer profile.Start(profile.ProfilePath(".")).Stop()
	defer flush()

	n, k := nextInt(), nextInt()
	a := make([]uint8, n)
	for i := 0; i < n; i++ {
		a[i] = uint8(nextInt())
	}

	sort.Sort(byCost(a))
	for i := 0; i < n; i++ {
		if cost := getCost(a[i]); k >= int(cost) {
			k -= int(cost)
			a[i] += cost
		} else {
			break
		}
	}
	for i := 0; i < n; i++ {
		if l := k / 10; l > 0 {
			r := int((100 - a[i]) / 10)
			if l < r {
				k -= l * 10
				a[i] += uint8(l * 10)
			} else {
				k -= r * 10
				a[i] += uint8(r * 10)
			}
		} else {
			break
		}
	}
	sum := 0
	for _, ai := range a {
		sum += int(ai / 10)
	}
	printn(sum)
}

func init() {
	scanner.Split(bufio.ScanWords)
}

var scanner = bufio.NewScanner(os.Stdin)

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

func nextWord() string {
	return next()
}

func nextLine() string {
	defer scanner.Split(bufio.ScanWords)
	scanner.Split(bufio.ScanLines)
	return strings.TrimSpace(next())
}

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

var stdout = bufio.NewWriter(os.Stdout)

func printa(a ...interface{}) (int, error) {
	return fmt.Fprint(stdout, a...)
}

func printn(a ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, a...)
}

func printf(format string, a ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, format, a...)
}

func flush() error {
	return stdout.Flush()
}

package main

import "sort"
import "fmt"

type Slice []int

func (a Slice) Len() int {
	return len(a)
}

func (a Slice) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func (a Slice) Less(i, j int) bool {
	return a[i]%10 < a[j]%10
}

func main() {
	var n, k int

	fmt.Scan(&n, &k)
	a := make(Slice, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	sort.Sort(sort.Reverse(a))
	ans := 0
	for i := 0; i < n; i++ {
		need := 10 - a[i]%10
		if need <= k {
			k -= need
			ans += (a[i] + need) / 10
		} else {
			ans += a[i] / 10
		}
		//fmt.Printf("%d %d\n", i, ans)
	}
	if k/10 > 0 {
		ans += k / 10
	}
	if ans >= n*10 {
		ans = n * 10
	}
	fmt.Println(ans)
}

package main

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

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

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

	n, k := nextInt(), nextInt()
	a := make([]int, n)
	sum := 0

	for i := range a {
		a[i] = nextInt()
		sum += a[i] / 10
		a[i] %= 10
	}

	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	for i := 0; i < len(a) && k > 0; i++ {
		if k+a[i] >= 10 {
			sum += 1
			k -= 10 - a[i]
		}
	}

	for sum < n*10 && k >= 10 {
		sum += 1
		k -= 10
	}

	println(sum)
}

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

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

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

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

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

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

package main

import (
	"fmt"
	"sort"
)

type slice []int

func (a slice) Len() int           { return len(a) }
func (a slice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a slice) Less(i, j int) bool { return a[j]%10 < a[i]%10 }

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make(slice, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	sort.Sort(a)
	for i := range a {
		r := 10 - a[i]%10
		if k -= r; k > -1 {
			a[i] += r
		}
	}
	if k > 0 {
		a[0] += k
	}
	ans := 0
	for _, v := range a {
		ans += v / 10
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
	"sort"
)

type slice []int

func (a slice) Len() int           { return len(a) }
func (a slice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a slice) Less(i, j int) bool { return a[j]%10 < a[i]%10 }

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make(slice, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	sort.Sort(a)
	for i := range a {
		r := 10 - a[i]%10
		if k -= r; k > -1 {
			a[i] += r
		}
	}
	for i := range a {
		r := 100 - a[i]
		if k > r {
			a[i] += r
			k -= r
		} else if k > 0 {
			a[i] += k
			break
		}
	}
	ans := 0
	for _, v := range a {
		ans += v / 10
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
	"sort"
)

type slice []int

func (a slice) Len() int           { return len(a) }
func (a slice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a slice) Less(i, j int) bool { return a[j]%10 < a[i]%10 }

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make(slice, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	sort.Sort(a)
	for i := range a {
		r := 10 - a[i]%10
		if k -= r; k > -1 {
			a[i] += r
		}
		if a[i] > 100 {
			r = a[i] - 100;
			a[i] = 100
			k += r
		}
	}
	for i := range a {
		r := 100 - a[i]
		if k > r {
			a[i] += r
			k -= r
		} else {
			a[i] += k
		}
	}
	ans := 0
	for _, v := range a {
		ans += v / 10
	}
	fmt.Println(ans)
}

package main

import "sort"
import "fmt"

type Slice []int

func (a Slice) Len() int {
	return len(a)
}

func (a Slice) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func (a Slice) Less(i, j int) bool {
	return a[i]%10 < a[j]%10
}

func main() {
	var n, k int

	fmt.Scanf("%d %d", &n, &k)
	a := make(Slice, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}
	sort.Sort(sort.Reverse(a))
	ans := 0
	for i := 0; i < n; i++ {
		need := 10 - a[i]%10
		if need <= k {
			k -= need
			ans += (a[i] + need) / 10
		} else {
			ans += a[i] / 10
		}
	}
	fmt.Println(ans)
}

package main

import "sort"
import "fmt"

type Slice []int

func (a Slice) Len() int {
	return len(a)
}

func (a Slice) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func (a Slice) Less(i, j int) bool {
	return a[i]%10 < a[j]%10
}

func main() {
	var n, k int

	fmt.Scan(&n, &k)
	a := make(Slice, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	sort.Sort(sort.Reverse(a))
	ans := 0
	for i := 0; i < n; i++ {
		need := 10 - a[i]%10
		if need <= k {
			k -= need
			ans += (a[i] + need) / 10
		} else {
			ans += a[i] / 10
		}
	}
	fmt.Println(ans)
}


$$$2^k$$$ teams participate in a playoff tournament. The tournament consists of $$$2^k - 1$$$ games. They are held as follows: first of all, the teams are split into pairs: team $$$1$$$ plays against team $$$2$$$, team $$$3$$$ plays against team $$$4$$$ (exactly in this order), and so on (so, $$$2^{k-1}$$$ games are played in that phase). When a team loses a game, it is eliminated, and each game results in elimination of one team (there are no ties). After that, only $$$2^{k-1}$$$ teams remain. If only one team remains, it is declared the champion; otherwise, $$$2^{k-2}$$$ games are played: in the first one of them, the winner of the game "$$$1$$$ vs $$$2$$$" plays against the winner of the game "$$$3$$$ vs $$$4$$$", then the winner of the game "$$$5$$$ vs $$$6$$$" plays against the winner of the game "$$$7$$$ vs $$$8$$$", and so on. This process repeats until only one team remains.For example, this picture describes the chronological order of games with $$$k = 3$$$:  Let the string $$$s$$$ consisting of $$$2^k - 1$$$ characters describe the results of the games in chronological order as follows:  if $$$s_i$$$ is 0, then the team with lower index wins the $$$i$$$-th game;  if $$$s_i$$$ is 1, then the team with greater index wins the $$$i$$$-th game;  if $$$s_i$$$ is ?, then the result of the $$$i$$$-th game is unknown (any team could win this game). Let $$$f(s)$$$ be the number of possible winners of the tournament described by the string $$$s$$$. A team $$$i$$$ is a possible winner of the tournament if it is possible to replace every ? with either 1 or 0 in such a way that team $$$i$$$ is the champion.You are given the initial state of the string $$$s$$$. You have to process $$$q$$$ queries of the following form:   $$$p$$$ $$$c$$$ — replace $$$s_p$$$ with character $$$c$$$, and print $$$f(s)$$$ as the result of the query.

The first line contains one integer $$$k$$$ ($$$1 \le k \le 18$$$). The second line contains a string consisting of $$$2^k - 1$$$ characters — the initial state of the string $$$s$$$. Each character is either ?, 0, or 1. The third line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Then $$$q$$$ lines follow, the $$$i$$$-th line contains an integer $$$p$$$ and a character $$$c$$$ ($$$1 \le p \le 2^k - 1$$$; $$$c$$$ is either ?, 0, or 1), describing the $$$i$$$-th query.

For each query, print one integer — $$$f(s)$$$.

package main

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

var (
	N, M      int
	resultNew []byte
	fn        []int
)

func compute(i int) {
	if i >= M>>1 {
		fn[i] = 1
		if resultNew[i] == '?' {
			fn[i] = 2
		}
	} else {
		if resultNew[i] == '0' {
			fn[i] = fn[i<<1]
		} else if resultNew[i] == '1' {
			fn[i] = fn[i<<1|1]
		} else {
			fn[i] = fn[i<<1] + fn[i<<1|1]
		}
	}
}

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

	N = sc.NextInt()
	M = 1 << N

	resultOld := make([]byte, M)
	copy(resultOld[1:], []byte(sc.Next()))
	idxMap := make([]int, M)
	resultNew = make([]byte, M)
	curIdx := 1
	for i := N - 1; i >= 0; i-- {
		for j := 0; j < (1 << i); j++ {
			newIdx := (1 << i) + j
			idxMap[curIdx] = newIdx
			resultNew[newIdx] = resultOld[curIdx]
			curIdx++
		}
	}

	fn = make([]int, M)
	for i := M - 1; i >= 1; i-- {
		compute(i)
	}

	Q := sc.NextInt()
	for q := 0; q < Q; q++ {
		p := sc.NextInt()
		c := sc.Next()

		idx := idxMap[p]
		resultNew[idx] = c[0]
		for idx > 0 {
			compute(idx)
			idx >>= 1
		}
		fmt.Fprintln(wr, fn[1])
	}

}

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) Next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) NextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt()
	}
	return res
}
func (s *Scanner) NextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt64()
	}
	return res
}
func Min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func Max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func InitInts1D(n int, val int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = val
	}
	return res
}
func InitInts2D(n, m int, val int) [][]int {
	res := make([][]int, n)
	for i := 0; i < n; i++ {
		res[i] = InitInts1D(m, val)
	}
	return res
}
func InitInts3D(n, m, k int, val int) [][][]int {
	res := make([][][]int, n)
	for i := 0; i < n; i++ {
		res[i] = InitInts2D(m, k, val)
	}
	return res
}

type StepState struct {
	step, dist int
}
type PriorityQueue []*StepState

func (pq PriorityQueue) Len() int { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool {
	if pq[i].step != pq[j].step {
		return pq[i].step < pq[j].step
	}
	return pq[i].dist < pq[j].dist
}
func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}
func (pq *PriorityQueue) Push(x interface{}) {
	item := x.(*StepState)
	*pq = append(*pq, item)
}
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

package main

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

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

	var k int
	fmt.Fscan(in, &k)
	var str string
	fmt.Fscan(in, &str)
	n := 1 << k
	tree := make([]int, 2*n)
	for i := range tree {
		tree[i] = 1
	}
	s := reverse([]byte(str))
	for i := n - 2; i >= 0; i-- {
		upd(s, tree, i)
	}
	var q, p int
	var c string
	fmt.Fscan(in, &q)
	for i := 0; i < q; i++ {
		fmt.Fscan(in, &p)
		fmt.Fscan(in, &c)
		p = n - 1 - p
		s[p] = c[0]
		for i := p; i != 0; i = (i - 1) / 2 {
			upd(s, tree, i)
		}
		upd(s, tree, 0)
		fmt.Fprintln(out, tree[0])
	}

}

func upd(s []byte, tree []int, i int) {
	left, right := 0, 0
	if s[i] != '0' {
		left = tree[2*i+1]
	}
	if s[i] != '1' {
		right += tree[2*i+2]
	}
	tree[i] = left + right
}

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

func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

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

package main

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

func main() {
	cin := bufio.NewReader(os.Stdin)
	var k int
	fmt.Fscan(cin, &k)
	var s string
	fmt.Fscan(cin, &s)
	a := make([]int, 4*len(s))
	for i := 0; i < len(a); i++ {
		a[i] = 1
	}
	runes := []rune(s)
	for j, i := 0, len(s)-1; i >= 0; i-- {
		if s[i] == '1' {
			runes[j] = '0'
		} else if s[i] == '0' {
			runes[j] = '1'
		} else {
			runes[j] = '?'
		}
		j++
	}
	for i := len(s) - 1; i >= 0; i-- {
		if runes[i] == '1' {
			a[i] = a[2*i+2]
		} else if runes[i] == '0' {
			a[i] = a[2*i+1]
		} else {
			a[i] = a[2*i+1] + a[2*i+2]
		}
	}
	var q, x int
	var c string
	fmt.Fscan(cin, &q)
	for i := 0; i < q; i++ {
		fmt.Fscan(cin, &x)
		fmt.Fscan(cin, &c)
		x = len(s) - x
		ch := c[0]
		if ch != '?' {
			ch = '1' - c[0]
		}
		runes[x] = rune(ch + '0')
		for j := x; j > 0; j = (j - 1) / 2 {
			if runes[j] == '1' {
				a[j] = a[2*j+2]
			} else if runes[j] == '0' {
				a[j] = a[2*j+1]
			} else {
				a[j] = a[2*j+1] + a[2*j+2]
			}
		}
		if runes[0] == '1' {
			a[0] = a[2]
		} else if runes[0] == '0' {
			a[0] = a[1]
		} else {
			a[0] = a[1] + a[2]
		}
		fmt.Println(a[0])
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
type pair struct {
	b byte
	i int
}
type seg []struct {
	l, r int
	val  int
	pair
	//id   int
}

var mp []int

var a [][]pair

func (t seg) build(o, l, r, d int) {
	t[o].l, t[o].r = l, r
	if l == r {
		b := a[d][0]
		a[d] = a[d][1:]
		if b.b == '?' {
			t[o].val = 2
		} else {
			t[o].val = 1
		}
		t[o].pair = b
		mp[b.i] = o
		return
	}
	m := (l + r) >> 1
	t.build(o<<1, l, m, d+1)
	t.build(o<<1|1, m+1, r, d+1)

	lo, ro := t[o<<1], t[o<<1|1]
	b := a[d][0]
	a[d] = a[d][1:]
	if b.b == '?' {
		t[o].val = lo.val + ro.val
	} else if b.b == '0' {
		t[o].val = lo.val
	} else {
		t[o].val = ro.val
	}
	t[o].pair = b
	mp[b.i] = o

}

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

	var k, q int
	var s []byte
	Fscan(in, &k, &s, &q)
	tmp := append([]byte(nil), s...)
	j := len(tmp)
	for l := 1; l <= len(tmp); l <<= 1 {
		s := tmp[len(tmp)-l:]
		tmp = tmp[:len(tmp)-l]
		b := make([]pair, len(s))
		for i := len(s) - 1; i >= 0; i-- {
			ch := s[i]
			b[i] = pair{ch, j}
			j--
		}
		a = append(a, b)
	}
	//for _, s := range a {
	//	Println(string(s))
	//}

	mp = make([]int, len(s)+10)

	t := make(seg, len(s)+1)
	t.build(1, 1, len(s)>>1+1, 0)
	for qi := 1; qi <= q; qi++ {
		var p int
		var c string
		Fscan(in, &p, &c)
		b := c[0]
		o := mp[p]
		cur := true
		for {
			if o<<1 >= len(t) || t[o<<1].l==0 {
				if cur {
					t[o].b = b
					cur =false
				}
				if b == '?' {
					t[o].val = 2
				} else {
					t[o].val = 1
				}
			} else {
				if cur {
					t[o].b = b
					cur =false
				}
				b = t[o].b
				lo, ro := t[o<<1], t[o<<1|1]
				if b == '?' {
					t[o].val = lo.val + ro.val
				} else if b == '0' {
					t[o].val = lo.val
				} else {
					t[o].val = ro.val
				}
			}

			if o == 1 {
				break
			}
			o>>=1
		}

		res := t[1].val
		Fprintln(out, res)
	}
}

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


You are given $$$n$$$ strings $$$a_1, a_2, \ldots, a_n$$$: all of them have the same length $$$m$$$. The strings consist of lowercase English letters.Find any string $$$s$$$ of length $$$m$$$ such that each of the given $$$n$$$ strings differs from $$$s$$$ in at most one position. Formally, for each given string $$$a_i$$$, there is no more than one position $$$j$$$ such that $$$a_i[j] \ne s[j]$$$.Note that the desired string $$$s$$$ may be equal to one of the given strings $$$a_i$$$, or it may differ from all the given strings.For example, if you have the strings abac and zbab, then the answer to the problem might be the string abab, which differs from the first only by the last character, and from the second only by the first.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case starts with a line containing two positive integers $$$n$$$ ($$$1 \le n \le 10$$$) and $$$m$$$ ($$$1 \le m \le 10$$$) — the number of strings and their length. Then follow $$$n$$$ strings $$$a_i$$$, one per line. Each of them has length $$$m$$$ and consists of lowercase English letters.

Print $$$t$$$ answers to the test cases. Each answer (if it exists) is a string of length $$$m$$$ consisting of lowercase English letters. If there are several answers, print any of them. If the answer does not exist, print "-1" ("minus one", without quotes).

5
2 4
abac
zbab
2 4
aaaa
bbbb
3 3
baa
aaa
aab
2 2
ab
bb
3 1
a
b
c

NoteThe first test case was explained in the statement.In the second test case, the answer does not exist.

package main

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

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

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

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

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

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

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

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

	return i
}

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		S := make([][]byte, n)
		for i := 0; i < n; i++ {
			S[i], _ = reader.ReadBytes('\n')
		}
		res := solve(n, m, S)
		if len(res) == 0 {
			fmt.Println("-1")
		} else {
			fmt.Println(res)
		}
	}
}

func solve(n, m int, A [][]byte) string {
	buf := make([]byte, m)

	var dfs func(flag int, i int) bool

	dfs = func(flag int, i int) bool {
		if i == m {
			return true
		}

		set := make(map[byte]bool)

		for j := 0; j < n; j++ {
			set[A[j][i]] = true
		}

		for k := range set {
			var flag2 int

			for j := 0; j < n; j++ {
				if A[j][i] != k {
					flag2 |= 1 << j
				}
			}
			if flag2&flag > 0 {
				continue
			}
			buf[i] = k
			if dfs(flag|flag2, i+1) {
				return true
			}
		}
		return false
	}

	res := dfs(0, 0)

	if res {
		return string(buf)
	}

	return ""
}

package main

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

func ok(b []int) bool {
	for i := range b {
		if b[i] > 1 {
			return false
		}
	}

	return true
}

func isOk(i, m int, a []string, b []int,  s []byte) bool {
	if i == m {
		if ok(b) {
			return true
		}
		return false
	}

	if !ok(b) {
		return false
	}

	l := make(map[byte]bool)

	for j := range a {
		l[a[j][i]] = true
	}

	// fmt.Println(i, l)

	for k := range l {

		s[i] = k

		for j := range a {
			if a[j][i] != k {
				b[j]++
			}
		}

		if isOk(i+1, m, a, b, s) {
			// fmt.Println(s, b)
			return true
		}

		for j := range a {
			if a[j][i] != k {
				b[j]--
			}
		}
	}

	return false
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	ini := func() int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	ins := func() string {
		sc.Scan()
		return sc.Text()
	}

	for t := ini(); t > 0; t-- {
		n, m := ini(), ini()

		a := make([]string, n)
		s := make([]byte, m)

		for i := range a {
			a[i] = ins()
		}

		b := make([]int, n)

		if !isOk(0, m, a, b, s) {
			fmt.Println(-1)
			// fmt.Println(string(s))
			continue
		}

		fmt.Println(string(s))
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
  	"strings"
  	"strconv"
  	"math"

)

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n,m:= reader.NextInt(),reader.NextInt()
		aa := make([][]rune, n)
		for i:=range aa {
			aa[i]=make([]rune,m)
		}
		for i := 0; i <n; i++ {
			s:=reader.NextString()
			aa[i]=[]rune(s)
		}
		sol(aa)
	}
}

func sol(aa [][]rune) {
	ans:=aa[0]
	// fmt.Println(ans)
	if(isValid(ans,aa)){
		writer.Printf("%s\n",string(ans))
		return
	}else{
		for i:=0;i<len(aa[0]);i++ {
			prevLetter:=ans[i]
			for c:='a';c<='z';c++ {
				ans[i]=c
				if(isValid(ans,aa)){
					writer.Printf("%s\n",string(ans))
					return
				}
			}
			ans[i]=prevLetter
		}
	}
	writer.Printf("-1\n")

}

func isValid(benchmark []rune, aa [][]rune) bool{
	for i:=1;i<len(aa);i++ {
		cnt:=0
		for j:=0;j<len(aa[0]);j++ {
			if(benchmark[j]!=aa[i][j]){
				cnt++
			}
		}
		if(cnt>1){
			return false
		}
	}
	return true
}

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

func LevenshteinDistance(a, b string) int {
	// Write your code here.
	rows:=len(a)
	cols:=len(b)
	dp:=make([][]int,rows+1)
	for i:=range dp{
		dp[i]=make([]int,cols+1)
	}
	for i:=0;i<=rows;i++{
		dp[i][0]=i
	}
	for i:=0;i<=cols;i++{
		dp[0][i]=i
	}
	for i:=1;i<=rows;i++{
		for j:=1;j<=cols;j++{
			if(a[i-1]==b[j-1]){
				dp[i][j]=dp[i-1][j-1]
			}else{
				dp[i][j] = 1 + min(dp[i-1][j],dp[i][j-1],dp[i-1][j-1])
			}
		}
	}

	return dp[rows][cols]
}
func min(a,b,c int) int{
	if(a<=b && a<=c){
		return a
	}
	if(b<=a && b<=c){
		return b
	}else{
		return c
	}
}

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

/*
URL:
https://codeforces.com/contest/1360/problem/F
*/

package main

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

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

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

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

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

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

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

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

var (
	t    int
	n, m int
	S    [][]rune
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, m = ReadInt2()
		S = [][]rune{}
		for j := 0; j < n; j++ {
			S = append(S, ReadRuneSlice())
		}

		solve(n, m, S)
	}
}

func solve(n, m int, S [][]rune) {
	// 1番目の文字列のi番目のみをすべての文字に変えて試す
	for i := 0; i < m; i++ {
		for r := 'a'; r <= 'z'; r++ {
			str := make([]rune, len(S[0]))
			copy(str, S[0])

			str[i] = r

			if check(str, S) {
				fmt.Println(string(str))
				return
			}
		}
	}
	fmt.Println(-1)
}

func check(target []rune, S [][]rune) bool {
	for i := 0; i < n; i++ {
		if diff(target, S[i]) >= 2 {
			return false
		}
	}
	return true
}

func diff(s, t []rune) int {
	res := 0
	for i := 0; i < m; i++ {
		if s[i] != t[i] {
			res++
			if res >= 2 {
				return res
			}
		}
	}
	return res
}

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

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

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

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

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

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

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

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

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

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

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

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

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

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

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var t, n, m int
o:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		a := make([][]byte, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		ans := make([]byte, m)
		copy(ans, a[0])
		for i, b := range a[0] {
		o2:
			for c := byte('a'); c <= 'z'; c++ {
				ans[i] = c
				for _, s := range a {
					d := 0
					for j, b := range s {
						if ans[j] != b {
							d++
							if d > 1 {
								continue o2
							}
						}
					}
				}
				Fprintln(out, string(ans))
				continue o
			}
			ans[i] = b
		}
		Fprintln(out, -1)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var t, n, m int
o:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		a := make([][]byte, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		for _, s := range a {
			ans := make([]byte, m)
			copy(ans, s)
			for i, b := range s {
			o2:
				for c := byte('a'); c <= 'z'; c++ {
					ans[i] = c
					for _, s := range a {
						d := 0
						for j, b := range s {
							if ans[j] != b {
								d++
								if d > 1 {
									continue o2
								}
							}
						}
					}
					Fprintln(out, string(ans))
					continue o
				}
				ans[i] = b
			}
		}
		Fprintln(out, -1)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for tc := 0; tc < t; tc++ {
        var n, m int
        var a [][]byte
		fmt.Scan(&n, &m)
		a = make([][]byte, n)
		for i := 0; i < n; i++ {
		    fmt.Scan(&a[i])
		}
		res := "-1"
		flag := true
		for j := 0; flag && j < m; j++ {
		    for c := 'a'; flag && c <= 'z'; c++ {
		        cur := make([]byte, m)
		        copy(cur, a[0])
		        cur[j] = byte(c)
		        valid := true
		        for i := 1; valid && i < n; i++ {
		            cnt := 0
		            for k := 0; k < m; k++ {
		                if (cur[k] == a[i][k]) {
		                    cnt++
		                }
		            }
		            if (cnt < m - 1) {
		                valid = false
		            }
		        }
		        if (valid) {
		            res = string(cur)
		            flag = false
		        }
		    }
		}
		fmt.Println(res)
	}
}

package main

import (
	"fmt"
)

func is_good(txt []rune, G [][]rune, n int, m int) bool {
	for i := 0; i < n; i++ {
		dist := 0
		for j := 0; j < m; j++ {
			if txt[j] != G[i][j] {
				dist++
			}
			if dist > 1 {
				return false
			}
		}
	}
	return true
}

func main(){
	var T int
	fmt.Scan(&T)
	for t := 0; t < T; t++ {
		var n, m int
		fmt.Scan(&n, &m)
		G := make([][]rune, n)
		for i := 0; i < n; i++ {
			var s string
			fmt.Scan(&s)
			G[i] = []rune(s)
		}
		ans := "-1"
		found := false
		for i := 0; i < n && !found; i++ {
			cand := make([]rune, m)
			copy(cand, G[i])
			for k := 0; k < m && !found; k++ {
				for c := 'a'; c <= 'z'; c++ {
					cand[k] = c
					if is_good(cand, G, n, m) {
						ans = string(cand)
						found = true
						break
					}
				}
				cand[k] = G[i][k]
			}
		}
		fmt.Println(ans)
	}

}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	Int64() int64
	UInt64() uint64
	String() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

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

func (impl *wordScannerImpl) String() string {
	impl.Scan()
	return impl.Text()
}

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

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

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

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

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

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

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.Int64()
	for ; t > 0; t-- {
		n := reader.Int64()
		m := reader.Int64()
		a := make([]string, n)
		for i := range a {
			a[i] = reader.String()
		}
		writer.Printf("%s\n", sol(a, m))
	}
}

func sol(a []string, m int64) string {
	first := []byte(a[0])
	for i := range first {
		curr := first[i]
		for j := byte(0); j < 27; j++ {
			nxtPos := curr + j
			if nxtPos > 'z' {
				nxtPos -= 26
			}
			first[i] = nxtPos
			if isValid(string(first), a[1:]) {
				return string(first)
			}
		}
	}
	return "-1"
}

func isValid(res string, rem []string) bool {
	for _, s := range rem {
		diff := false
		for i := range res {
			if res[i] != s[i] {
				if diff {
					return false
				} else {
					diff = true
				}
			}
		}
	}
	return true
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	ini := func() int64 {
		sc.Scan()
		i, _ := strconv.ParseInt(sc.Text(), 10, 64)
		return i
	}

	ins := func() string {
		sc.Scan()
		return sc.Text()
	}

	for t := ini(); t > 0; t-- {
		n, m := ini(), ini()

		a := make([]string, n)
		s := make([]byte, m)

		for i := range a {
			a[i] = ins()
		}

		b := make([]int, n)

		var i int64
		for i = 0; i < m; i++ {
			// fmt.Println(b)
			m := make(map[byte]int)
			var l byte

			for j := range a {
				if b[j] == 0 {
					m[a[j][i]]++
				} else {
					m[a[j][i]] += 2
				}
			}

			mx := -1
			for k, v := range m {
				if v > mx {
					l = k
					mx = v
				}
			}

			s[i] = l

			for j := range b {
				if a[j][i] != l {
					b[j]++
				}
			}

			// fmt.Println(b)
		}

		ok := true

		for i := range b {
			if b[i] > 1 {
				ok = false
				break
			}
		}

		if !ok {
			fmt.Println(-1)
			// fmt.Println(string(s))
			continue
		}

		fmt.Println(string(s))
	}
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	ini := func() int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	ins := func() string {
		sc.Scan()
		return sc.Text()
	}

	for t := ini(); t > 0; t-- {
		n, m := ini(), ini()

		a := make([]string, n)
		s := make([]byte, m)

		for i := range a {
			a[i] = ins()
		}

		b := make([]int, n)

		for i := 0; i < m; i++ {
			// fmt.Println(b)
			m := make(map[byte]int)
			var l byte

			for j := range a {
				if b[j] == 0 {
					m[a[j][i]]++
				} else {
					m[a[j][i]] += 2
				}
			}

			mx := -1
			for k, v := range m {
				if v > mx {
					l = k
					mx = v
				}
			}

			s[i] = l

			for j := range b {
				if a[j][i] != l {
					b[j]++
				}
			}

			// fmt.Println(b)
		}

		ok := true

		for i := range b {
			if b[i] > 1 {
				ok = false
				break
			}
		}

		if !ok {
			fmt.Println(-1)
			// fmt.Println(string(s))
			continue
		}

		fmt.Println(string(s))
	}
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	ini := func() int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	ins := func() string {
		sc.Scan()
		return sc.Text()
	}

	for t := ini(); t > 0; t-- {
		n, m := ini(), ini()

		a := make([]string, n)
		s := make([]byte, m)

		for i := range a {
			a[i] = ins()
		}

		b := make([]int, n)

		for i := 0; i < m; i++ {
			m := make(map[byte]int)
			found := false
			var l byte

			for j := range a {
				if b[j] == 0 {
					m[a[j][i]]++
				} else {
					found = true
					l = a[j][i]
					break
				}
			}

			if found == false {
				mx := 0
				for k, v := range m {
					if v > mx {
						l = k
						mx = v
					}
				}
			}

			s[i] = l

			for j := range b {
				if a[j][i] != l {
					b[j]++
				}
			}
		}

		ok := true

		for i := range b {
			if b[i] > 1 {
				ok = false
				break
			}
		}

		if !ok {
			fmt.Println(-1)
			continue
		}

		fmt.Println(string(s))
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
  	"strings"
  	"strconv"
  	"math"

)

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n,m:= reader.NextInt(),reader.NextInt()
		aa := make([][]rune, n)
		for i:=range aa {
			aa[i]=make([]rune,m)
		}
		for i := 0; i <n; i++ {
			s:=reader.NextString()
			aa[i]=[]rune(s)
		}
		sol(aa)
	}
}

func sol(aa [][]rune) {
	ans:=aa[0]
	// fmt.Println(ans)
	if(isValid(ans,aa)){
		writer.Printf("%s \n",string(ans))
		return
	}else{
		for i:=0;i<len(aa[0]);i++ {
			prevLetter:=ans[i]
			for c:='a';c<='z';c++ {
				ans[i]=c
				if(isValid(ans,aa)){
					writer.Printf("%s\n",string(ans))
					return
				}
			}
			ans[i]=prevLetter
		}
	}
	writer.Printf("-1 \n")

}

func isValid(benchmark []rune, aa [][]rune) bool{
	for i:=1;i<len(aa);i++ {
		cnt:=0
		for j:=0;j<len(aa[0]);j++ {
			if(benchmark[j]!=aa[i][j]){
				cnt++
			}
		}
		if(cnt>1){
			return false
		}
	}
	return true
}

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

func LevenshteinDistance(a, b string) int {
	// Write your code here.
	rows:=len(a)
	cols:=len(b)
	dp:=make([][]int,rows+1)
	for i:=range dp{
		dp[i]=make([]int,cols+1)
	}
	for i:=0;i<=rows;i++{
		dp[i][0]=i
	}
	for i:=0;i<=cols;i++{
		dp[0][i]=i
	}
	for i:=1;i<=rows;i++{
		for j:=1;j<=cols;j++{
			if(a[i-1]==b[j-1]){
				dp[i][j]=dp[i-1][j-1]
			}else{
				dp[i][j] = 1 + min(dp[i-1][j],dp[i][j-1],dp[i-1][j-1])
			}
		}
	}

	return dp[rows][cols]
}
func min(a,b,c int) int{
	if(a<=b && a<=c){
		return a
	}
	if(b<=a && b<=c){
		return b
	}else{
		return c
	}
}

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
  	"strings"
  	"strconv"
  	"math"

)

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n,m:= reader.NextInt(),reader.NextInt()
		aa := make([][]rune, n)
		for i:=range aa {
			aa[i]=make([]rune,m)
		}
		for i := 0; i <n; i++ {
			s:=reader.NextString()
			aa[i]=[]rune(s)
		}
		sol(aa)
	}
}

func sol(aa [][]rune) {
	ans:=aa[0]
	// fmt.Println(ans)
	if(isValid(ans,aa)){
		writer.Printf("%s \n",string(ans))
		return
	}else{
		for i:=0;i<len(aa[0]);i++ {
			prevLetter:=ans[i]
			for c:='a';c<='z';c++ {
				ans[i]=c
				if(isValid(ans,aa)){
					writer.Printf("%s\n",string(ans))
					return
				}
			}
			ans[i]=prevLetter
		}
	}
	writer.Printf("-1\n")

}

func isValid(benchmark []rune, aa [][]rune) bool{
	for i:=1;i<len(aa);i++ {
		cnt:=0
		for j:=0;j<len(aa[0]);j++ {
			if(benchmark[j]!=aa[i][j]){
				cnt++
			}
		}
		if(cnt>1){
			return false
		}
	}
	return true
}

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

func LevenshteinDistance(a, b string) int {
	// Write your code here.
	rows:=len(a)
	cols:=len(b)
	dp:=make([][]int,rows+1)
	for i:=range dp{
		dp[i]=make([]int,cols+1)
	}
	for i:=0;i<=rows;i++{
		dp[i][0]=i
	}
	for i:=0;i<=cols;i++{
		dp[0][i]=i
	}
	for i:=1;i<=rows;i++{
		for j:=1;j<=cols;j++{
			if(a[i-1]==b[j-1]){
				dp[i][j]=dp[i-1][j-1]
			}else{
				dp[i][j] = 1 + min(dp[i-1][j],dp[i][j-1],dp[i-1][j-1])
			}
		}
	}

	return dp[rows][cols]
}
func min(a,b,c int) int{
	if(a<=b && a<=c){
		return a
	}
	if(b<=a && b<=c){
		return b
	}else{
		return c
	}
}

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
  	"strings"
  	"strconv"
  	"math"

)

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n,m:= reader.NextInt(),reader.NextInt()
		aa := make([][]rune, n)
		for i:=range aa {
			aa[i]=make([]rune,m)
		}
		for i := 0; i <n; i++ {
			s:=reader.NextString()
			aa[i]=[]rune(s)
		}
		sol(aa)
	}
}

func sol(aa [][]rune) {
	ans:=aa[0]
	// fmt.Println(ans)
	if(isValid(ans,aa)){
		writer.Printf("%s \n",string(ans))
		return
	}else{
		for i:=0;i<len(aa[0]);i++ {
			prevLetter:=ans[i]
			for c:='a';c<='z';c++ {
				ans[i]=c
				if(isValid(ans,aa)){
					writer.Printf("%s \n",string(ans))
					return
				}
			}
			ans[i]=prevLetter
		}
	}
	writer.Printf("-1 \n")

}

func isValid(benchmark []rune, aa [][]rune) bool{
	for i:=1;i<len(aa);i++ {
		cnt:=0
		for j:=0;j<len(aa[0]);j++ {
			if(benchmark[j]!=aa[i][j]){
				cnt++
			}
		}
		if(cnt>1){
			return false
		}
	}
	return true
}

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

func LevenshteinDistance(a, b string) int {
	// Write your code here.
	rows:=len(a)
	cols:=len(b)
	dp:=make([][]int,rows+1)
	for i:=range dp{
		dp[i]=make([]int,cols+1)
	}
	for i:=0;i<=rows;i++{
		dp[i][0]=i
	}
	for i:=0;i<=cols;i++{
		dp[0][i]=i
	}
	for i:=1;i<=rows;i++{
		for j:=1;j<=cols;j++{
			if(a[i-1]==b[j-1]){
				dp[i][j]=dp[i-1][j-1]
			}else{
				dp[i][j] = 1 + min(dp[i-1][j],dp[i][j-1],dp[i-1][j-1])
			}
		}
	}

	return dp[rows][cols]
}
func min(a,b,c int) int{
	if(a<=b && a<=c){
		return a
	}
	if(b<=a && b<=c){
		return b
	}else{
		return c
	}
}

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

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

	var t, n, m int
o:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		a := make([][]byte, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		ans := make([]byte, m)

		if n == 2 {
			cnt:=0
			for i := 0; i < m; i++ {
				if a[0][i] == a[1][i] {
					ans[i] = a[0][i]
				} else {
					if cnt ==2 {
						Fprintln(out, -1)
						continue o
					}
					ans[i] = a[cnt][i]
					cnt++
				}
			}
			Fprintln(out, string(ans))
			continue
		}

		//if m == 1 {
		//	Fprintln(out, "a")
		//	continue
		//}
		pos3 := []int{}
		pos2 := []pair{}
		for j := 0; j < m; j++ {
			cntMp := map[byte]int{}
			for _, s := range a {
				cntMp[s[j]]++
			}
			if len(cntMp) > 2 {
				pos3 = append(pos3, j)
			} else if len(cntMp) == 2 {
				bs := make([]byte, 0, len(cntMp))
				for k := range cntMp {
					bs = append(bs, k)
				}
				if cntMp[bs[0]] == 1 {
					pos2 = append(pos2, pair{j, bs[1]})
				} else if cntMp[bs[1]] == 1 {
					pos2 = append(pos2, pair{j, bs[0]})
				} else {
					Fprintln(out, -1)
					continue o
				}
			} else {
				for b := range cntMp {
					ans[j] = b
				}
			}
		}
		if len(pos3) > 1 {
			Fprintln(out, -1)
			continue
		} else if len(pos3) == 1 {
			if len(pos2) > 0 {
				Fprintln(out, -1)
				continue
			}
			ans[pos3[0]] = 'z'
		} else {
			for _, p := range pos2 {
				ans[p.p] = p.b
			}
		}
		for _, s := range a {
			cnt:=0
			for j, b := range s {
				if ans[j] != b{
					cnt++
					if cnt > 1 {
						Fprintln(out, -1)
						continue o
					}
				}
			}
		}
		Fprintln(out, string(ans))
	}
}

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

package main

import (
	"fmt"
)

func is_good(txt []rune, G [][]rune, n int, m int) bool {
	for i := 0; i < n; i++ {
		dist := 0
		for j := 0; j < m; j++ {
			if txt[j] != G[i][j] {
				dist++
			}
			if dist > 1 {
				return false
			}
		}
	}
	return true
}

func main(){
	var T int
	fmt.Scan(&T)
	for t := 0; t < T; t++ {
		var n, m int
		fmt.Scan(&n, &m)
		G := make([][]rune, n)
		for i := 0; i < n; i++ {
			var s string
			fmt.Scan(&s)
			G[i] = []rune(s)
		}
		ans := "-1"
		found := false
		for i := 0; i < n && !found; i++ {
			cand := make([]rune, m)
			copy(cand, G[i])
			for k := 0; k < m && !found; k++ {
				for c := 'a'; c <= 'z'; c++ {
					cand[k] = c
					if is_good(cand, G, n, m) {
						ans = string(cand)
						found = true
						break
					}
				}
			}
		}
		fmt.Println(ans)
	}

}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	Int64() int64
	UInt64() uint64
	String() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

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

func (impl *wordScannerImpl) String() string {
	impl.Scan()
	return impl.Text()
}

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

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

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

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

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

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

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.Int64()
	for ; t > 0; t-- {
		n := reader.Int64()
		m := reader.Int64()
		a := make([]string, n)
		for i := range a {
			a[i] = reader.String()
		}
		writer.Printf("%s\n", sol(a, m))
	}
}

func sol(a []string, m int64) string {
	first := []byte(a[0])
	for i := range first {
		curr := first[i]
		for j := byte(0); j < 27; j++ {
			nxtPos := curr + j
			if nxtPos > 'z' {
				nxtPos -= 26
			}
			first[i] = nxtPos
			if isValid(string(first), a[1:]) {
				return string(first)
			}
		}
	}
	return "-1"
}

func isValid(res string, rem []string) bool {
	diff := false
	for i := range res {
		for _, s := range rem {
			if res[i] != s[i] {
				if diff {
					return false
				} else {
					diff = true
					break
				}
			}
		}
	}
	return true
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	Int64() int64
	UInt64() uint64
	String() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

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

func (impl *wordScannerImpl) String() string {
	impl.Scan()
	return impl.Text()
}

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

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

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

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

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

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

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.Int64()
	for ; t > 0; t-- {
		n := reader.Int64()
		m := reader.Int64()
		a := make([]string, n)
		for i := range a {
			a[i] = reader.String()
		}
		writer.Printf("%s\n", sol(a, m))
	}
}

func sol(a []string, m int64) string {
	first := []byte(a[0])
	for i := range first {
		curr := first[i]
		for j := byte(0); j < 26; j++ {
			nxtPos := curr + j
			if nxtPos > 'z' {
				nxtPos -= 26
			}
			first[i] = nxtPos
			if isValid(string(first), a[1:]) {
				return string(first)
			}
		}
	}
	return "-1"
}

func isValid(res string, rem []string) bool {
	diff := false
	for i := range res {
		for _, s := range rem {
			if res[i] != s[i] {
				if diff {
					return false
				} else {
					diff = true
				}
			}
		}
	}
	return true
}


You're given a tree with $$$n$$$ vertices.Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) denoting the size of the tree.  The next $$$n - 1$$$ lines contain two integers $$$u$$$, $$$v$$$ ($$$1 \le u, v \le n$$$) each, describing the vertices connected by the $$$i$$$-th edge. It's guaranteed that the given edges form a tree.

Output a single integer $$$k$$$ — the maximum number of edges that can be removed to leave all connected components with even size, or $$$-1$$$ if it is impossible to remove edges in order to satisfy this property.

NoteIn the first example you can remove the edge between vertices $$$1$$$ and $$$4$$$. The graph after that will have two connected components with two vertices in each.In the second example you can't remove edges in such a way that all components have even number of vertices, so the answer is $$$-1$$$.

package main

import "fmt"
import "bufio"
import "os"

var n int
var m [][]int
var used []int
var ans int

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	if n % 2 == 1 {
		fmt.Println(-1)
		return
	}
	m = make([][]int, n)
	used = make([]int, n)
	for i := 0; i < n - 1; i++ {
		var v1, v2 int
		fmt.Fscanf(buf, "%d %d\n", &v1, &v2)
		m[v1-1] = append(m[v1-1], v2-1)
		m[v2-1] = append(m[v2-1], v1-1)
	}
	getMaxEdges(0, -1)
	fmt.Println(ans)
	return
}

func getMaxEdges(x, y int) int {
	cnt := 0
	for _, v := range m[x] {
		if v != y {
			cnt += getMaxEdges(v, x)
		}
	}
	cnt++
	used[x] = cnt

	for _, v := range m[x] {
		if v != y && used[v]%2 == 0 {
			ans++
		}
	}

	return cnt
}

package main

import "fmt"
import "bufio"
import "os"

type edge struct {
	v, e int
}

const nmax int = 100000
const mmax int = 200000

var edges [2*mmax + 1]edge
var adj [nmax + 1]int
var visited [nmax + 1]bool
var res int

func dfs(s int) int {
	nfii := 0

	for i := adj[s]; i != 0; i = edges[i].e {
		if !visited[edges[i].v] {
			nfii++
			visited[edges[i].v] = true
			nfii -= dfs(edges[i].v)
		}
	}

	if nfii&1 == 1 {
		res++
		return 1
	}

	return 0
}

func main() {
	n := 0

	in := bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &n)

	if n&1 == 1 {
		fmt.Print("-1")
		return
	}

	for i := 1; i < n; i++ {
		var v, u int
		fmt.Fscan(in, &v)
		fmt.Fscan(in, &u)

		edges[2*i].v = u
		edges[2*i].e = adj[v]
		adj[v] = 2 * i

		edges[2*i+1].v = v
		edges[2*i+1].e = adj[u]
		adj[u] = 2*i + 1
	}

	visited[1] = true
	dfs(1)

	fmt.Print(res - 1)
}

package main

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

var n int
var tree [][]int
var used []int
var ans int

func dfs(v, p int) int {
	cnt := 0
	for _, next := range tree[v] {
		if next != p {
			cnt += dfs(next, v)
		}
	}
	cnt++
	used[v] = cnt
	for _, next := range tree[v] {
		if next != p && used[next] % 2 == 0 {
			ans++
		}
	}
	return cnt
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	if n % 2 == 1 {
		fmt.Println(-1)
		return
	}
	tree = make([][]int, n)
	used = make([]int, n)
	for i := 0; i < n - 1; i++ {
		var v1, v2 int
		fmt.Fscanf(buf, "%d %d\n", &v1, &v2)
		tree[v1-1] = append(tree[v1-1], v2-1)
		tree[v2-1] = append(tree[v2-1], v1-1)
	}
	dfs(0, -1)
	fmt.Println(ans)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF982C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	var n, v, w, ans int
	Fscan(in, &n)
	if n&1 == 1 {
		Fprint(_w, -1)
		return
	}
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	var f func(int, int) int
	f = func(v, fa int) int {
		sz := 1
		for _, w := range g[v] {
			if w != fa {
				sz += f(w, v)
			}
		}
		if fa != -1 && sz&1 == 0 {
			ans++
		}
		return sz
	}
	f(0, -1)
	Fprint(_w, ans)
}

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


Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.

The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.

If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).

package main

import (
    "fmt"
    "sort"
)

func main() {
    var sz int
    fmt.Scanf("%d\n", &sz)
    arr := make([]int, sz)
    for i := range arr {
        fmt.Scanf("%d", &arr[i])
    }

    // fmt.Println(sz)
    // fmt.Println(arr)

    if sz == 1 {
        fmt.Println(-1)
        return
    }

    allEqual := true
    for i := range arr {
        if i > 0 && arr[i] != arr[i-1] {
            allEqual = false
            break
        }
    }

    if allEqual {
        fmt.Printf("1\n%d\n", arr[0])
        return
    }

    sort.Ints(arr)

    if sz == 2 {
        d := arr[1] - arr[0]
        if d%2 == 0 {
            fmt.Println(3)
            fmt.Printf("%d %d %d\n", arr[0]-d, arr[0]+d/2, arr[1]+d)
        } else {
            fmt.Println(2)
            fmt.Printf("%d %d\n", arr[0]-d, arr[1]+d)
        }
        return
    }

    m := make(map[int]int)
    var dif int
    for i := range arr {
        if i > 0 {
            d := arr[i] - arr[i-1]
            m[d]++
            dif = d
        }

        if len(m) > 2 {
            fmt.Println(0)
            return
        }
    }

    if len(m) == 1 {
        fmt.Println(2)
        fmt.Printf("%d %d\n", arr[0]-dif, arr[len(arr)-1]+dif)
        return
    }

    var d1, d2, cnt int
    for k, v := range m {
        if v > 1 {
            cnt++
        } else {
            dif = k
        }
        d1 = k
        if d1 > d2 {
            d1, d2 = d2, d1
        }
    }

    // fmt.Println("abc:", 0, d1, d2, dif)
    if cnt > 1 || d1*2 != d2 {
        fmt.Println(0)
        return
    }

    var cnt1, cnt2, res1, res2 int
    for i := range arr {
        if i > 0 {
            if arr[i-1]+2*d1 == arr[i] {
                res1 = arr[i-1] + d1
                cnt1++
                // return
            } else if arr[i-1]+2*d2 == arr[i] {
                res2 = arr[i-1] + d2
                cnt2++
            }
        }
    }

    if cnt1 == 1 {
        fmt.Printf("%d\n%d\n", 1, res1)
        return
    } else if cnt2 == 1 {
        fmt.Printf("%d\n%d\n", 1, res2)
        return
    }

    fmt.Println(0)
}

package main

import (
    "fmt"
    "sort"
)

func main() {
    var sz int
    fmt.Scanf("%d\n", &sz)
    arr := make([]int, sz)
    for i := range arr {
        fmt.Scanf("%d", &arr[i])
    }

    // fmt.Println(sz)
    // fmt.Println(arr)

    if sz == 1 {
        fmt.Println(-1)
        return
    }

    allEqual := true
    for i := range arr {
        if i > 0 && arr[i] != arr[i-1] {
            allEqual = false
            break
        }
    }

    if allEqual {
        fmt.Printf("1\n%d\n", arr[0])
        return
    }

    sort.Ints(arr)

    if sz == 2 {
        d := arr[1] - arr[0]
        if d%2 == 0 {
            fmt.Println(3)
            fmt.Printf("%d %d %d\n", arr[0]-d, arr[0]+d/2, arr[1]+d)
        } else {
            fmt.Println(2)
            fmt.Printf("%d %d\n", arr[0]-d, arr[1]+d)
        }
        return
    }

    m := make(map[int]int)
    var dif int
    for i := range arr {
        if i > 0 {
            d := arr[i] - arr[i-1]
            m[d]++
            dif = d
        }

        if len(m) > 2 {
            fmt.Println(0)
            return
        }
    }

    if len(m) == 1 {
        fmt.Println(2)
        fmt.Printf("%d %d\n", arr[0]-dif, arr[len(arr)-1]+dif)
        return
    }

    var d1, d2, cnt int
    for k, v := range m {
        if v > 1 {
            cnt++
        } else {
            dif = k
        }
        d1 = k
        if d1 > d2 {
            d1, d2 = d2, d1
        }
    }

    // fmt.Println("abc:", 0, d1, d2, dif)
    if cnt > 1 || d1*2 != d2 {
        fmt.Println(0)
        return
    }

    for i := range arr {
        if i > 0 {
            if arr[i-1]+2*d1 == arr[i] {
                fmt.Println(1)
                fmt.Println(arr[i-1] + d1)
                return
            } else if arr[i-1]+2*d2 == arr[i] {
                fmt.Println(1)
                fmt.Println(arr[i-1] + d2)
                return
            }
        }
    }

    fmt.Println(0)
}

package main

import (
    "fmt"
    "sort"
)

func main() {
    var sz int
    fmt.Scanf("%d\n", &sz)
    arr := make([]int, sz)
    for i := range arr {
        fmt.Scanf("%d", &arr[i])
    }

    // fmt.Println(sz)
    // fmt.Println(arr)

    if sz == 1 {
        fmt.Println(-1)
        return
    }

    allEqual := true
    for i := range arr {
        if i > 0 && arr[i] != arr[i-1] {
            allEqual = false
            break
        }
    }

    if allEqual {
        fmt.Printf("1\n%d\n", arr[0])
        return
    }

    sort.Ints(arr)

    if sz == 2 {
        d := arr[1] - arr[0]
        if d%2 == 0 {
            fmt.Println(3)
            fmt.Printf("%d %d %d\n", arr[0]-d, arr[0]+d/2, arr[1]+d)
        } else {
            fmt.Println(2)
            fmt.Printf("%d %d\n", arr[0]-d, arr[1]+d)
        }
        return
    }

    m := make(map[int]int)
    var dif int
    for i := range arr {
        if i > 0 {
            d := arr[i] - arr[i-1]
            m[d]++
            dif = d
        }

        if len(m) > 2 {
            fmt.Println(0)
            return
        }
    }

    if len(m) == 1 {
        fmt.Println(2)
        fmt.Printf("%d %d\n", arr[0]-dif, arr[len(arr)-1]+dif)
        return
    }

    var d1, d2, cnt int
    for k, v := range m {
        if v > 1 {
            cnt++
        } else {
            dif = k
        }
        d1 = k
        if d1 > d2 {
            d1, d2 = d2, d1
        }
    }

    // fmt.Println("abc:", 0, d1, d2, dif)
    if cnt > 1 || d1*2 != d2 {
        fmt.Println(0)
        return
    }

    for i := range arr {
        if i > 0 && arr[i]-arr[i-1] == dif {
            fmt.Println(1)
            fmt.Println(arr[i-1] + dif/2)
            return
        }
    }

    fmt.Println(0)
}

package main

import (
    "fmt"
    "sort"
)

func main() {
    var sz int
    fmt.Scanf("%d", &sz)
    arr := make([]int, sz)
    for i := range arr {
        fmt.Scanf("%d", &arr[i])
    }

    fmt.Println(sz)
    fmt.Println(arr)

    if sz == 1 {
        fmt.Println(-1)
        return
    }

    allEqual := true
    for i := range arr {
        if i > 0 && arr[i] != arr[i-1] {
            allEqual = false
            break
        }
    }

    if allEqual {
        fmt.Printf("1\n%d\n", arr[0])
        return
    }

    sort.Ints(arr)

    if sz == 2 {
        d := arr[1] - arr[0]
        if d%2 == 0 {
            fmt.Println(3)
            fmt.Printf("%d %d %d\n", arr[0]-d, arr[0]+d/2, arr[1]+d)
        } else {
            fmt.Println(2)
            fmt.Printf("%d %d\n", arr[0]-d, arr[1]+d)
        }
        return
    }

    m := make(map[int]int)
    var dif int
    for i := range arr {
        if i > 0 {
            d := arr[i] - arr[i-1]
            m[d]++
            dif = d
        }

        if len(m) > 2 {
            fmt.Println(0)
            return
        }
    }

    if len(m) == 1 {
        fmt.Println(2)
        fmt.Printf("%d %d\n", arr[0]-dif, arr[len(arr)-1]+dif)
        return
    }

    var d1, d2, cnt int
    for k, v := range m {
        if v > 1 {
            cnt++
        } else {
            dif = k
        }
        d1 = k
        if d1 > d2 {
            d1, d2 = d2, d1
        }
    }

    // fmt.Println("abc:", 0, d1, d2, dif)
    if cnt > 1 || d1*2 != d2 {
        fmt.Println(0)
        return
    }

    for i := range arr {
        if i > 0 && arr[i]-arr[i-1] == dif {
            fmt.Println(1)
            fmt.Println(arr[i-1] + dif/2)
            return
        }
    }

    fmt.Println(0)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var sz int
	fmt.Scanf("%d", &sz)
	arr := make([]int, sz)
	for i := range arr {
		fmt.Scanf("%d", &arr[i])
	}

	if sz == 1 {
		fmt.Println(-1)
		return
	}

	allEqual := true
	for i := range arr {
		if i > 0 && arr[i] != arr[i-1] {
			allEqual = false
			break
		}
	}

	if allEqual {
		fmt.Printf("1\n%d\n", arr[0])
		return
	}

	sort.Ints(arr)

	if sz == 2 {
		d := arr[1] - arr[0]
		if d%2 == 0 {
			fmt.Println(3)
			fmt.Printf("%d %d %d\n", arr[0]-d, arr[0]+d/2, arr[1]+d)
		} else {
			fmt.Println(2)
			fmt.Printf("%d %d\n", arr[0]-d, arr[1]+d)
		}
		return
	}

	m := make(map[int]int)
	var dif int
	for i := range arr {
		if i > 0 {
			d := arr[i] - arr[i-1]
			m[d]++
			dif = d
		}

		if len(m) > 2 {
			fmt.Println(0)
			return
		}
	}

	if len(m) == 1 {
		fmt.Println(2)
		fmt.Printf("%d %d\n", arr[0]-dif, arr[len(arr)-1]+dif)
		return
	}

	var d1, d2, cnt int
	for k, v := range m {
		if v > 1 {
			cnt++
		} else {
			dif = k
		}
		d1 = k
		if d1 > d2 {
			d1, d2 = d2, d1
		}
	}

	// fmt.Println("abc:", 0, d1, d2, dif)
	if cnt > 1 || d1*2 != d2 {
		fmt.Println(0)
		return
	}

	for i := range arr {
		if i > 0 && arr[i]-arr[i-1] == dif {
			fmt.Println(1)
			fmt.Println(arr[i-1] + dif/2)
			return
		}
	}

	fmt.Println(0)
}


Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba".Dr. Moriarty plans to take string s and cut out some substring from it, let's call it t. Then he needs to change the substring t zero or more times. As a result, he should obtain a fixed string u (which is the string that should be sent to Sherlock Holmes). One change is defined as making one of the following actions:   Insert one letter to any end of the string.  Delete one letter from any end of the string.  Change one letter into any other one. Moriarty is very smart and after he chooses some substring t, he always makes the minimal number of changes to obtain u. Help Moriarty choose the best substring t from all substrings of the string s. The substring t should minimize the number of changes Moriarty should make to obtain the string u from it.

The first line contains a non-empty string s, consisting of lowercase Latin letters. The second line contains a non-empty string u, consisting of lowercase Latin letters. The lengths of both strings are in the range from 1 to 2000, inclusive.

Print the only integer — the minimum number of changes that Dr. Moriarty has to make with the string that you choose.

NoteIn the first sample Moriarty can take any substring of length 3, and it will be equal to the required message u, so Moriarty won't have to make any changes.In the second sample you should take a substring consisting of characters from second to fourth ("bca") or from fifth to sixth ("bc"). Then you will only have to make one change: to change or to add the last character.In the third sample the initial string s doesn't contain any character that the message should contain, so, whatever string you choose, you will have to make at least 7 changes to obtain the required message.

package main

import "fmt"

func diff(s, u []byte) int {
	ans := 0
	var i int
	for i = 0; i < len(s) && i < len(u); i++ {
		if s[i] != u[i] { ans++ }
	}
	return ans + len(u) - i
}

func main() {
	var s, u string
	_, err := fmt.Scan(&s, &u)
	if err != nil { panic(err) }
	s2 := []byte(s)
	u2 := []byte(u)
	var ans int = 1e9
	for i := len(u2)-1; i >= 0; i-- {
		ans2 := diff(s2, u2[i:]) + i
		if ans > ans2 { ans = ans2 }
	}
	for i := 1; i < len(s2); i++ {
		ans2 := diff(s2[i:], u2)
		if ans > ans2 { ans = ans2 }
	}
	fmt.Println(ans)
}


Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.

Print the index of the day when Polycarp will celebrate the equator.

NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.

package main

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

var in = bufio.NewScanner(os.Stdin)

func nextInt() int {
	in.Scan()
	r := 0
	for _, c := range in.Bytes() {
		r *= 10
		r += int(c - '0')
	}
	return r
}

func main() {
	in.Split(bufio.ScanWords)
	n, s := nextInt(), 0
	a := make([]int, n)
	for i := range a {
		a[i] = nextInt()
		s += a[i]
	}
	t := (s + 1) / 2
	for i, v := range a {
		t -= v
		if t <= 0 {
			fmt.Println(i + 1)
			break
		}
	}
}

package main

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

type caseInput struct {
	nums []int16
}

func readCaseInput(scanner *bufio.Scanner) caseInput {
	size := readInt(scanner)
	nums := make([]int16, size)
	for i := range nums {
		nums[i] = int16(readInt(scanner))
	}
	in := caseInput{nums}
	return in
}

type caseOutput struct {
	equat int
}

func writeCaseOutput(writer *bufio.Writer, out caseOutput) {
	writef(writer, "%d\n", out.equat)
}

func solveCase(in caseInput) caseOutput {
	sum := 0
	for _, v := range in.nums {
		sum += int(v)
	}
	sum2 := int(0)
	for i, v := range in.nums {
		sum2 += int(v)
		if sum2 * 2 >= sum {
			return caseOutput{i + 1}
		}
	}
	return caseOutput{len(in.nums)}
}

//	everything below is reusable boilerplate
func solveSequential(scanner *bufio.Scanner, writer *bufio.Writer) {
	writeCaseOutput(writer, solveCase(readCaseInput(scanner)))
}

func main() {
	var scanner *bufio.Scanner
	if len(os.Args) > 1 {
		reader, err := os.Open(os.Args[1])
		if err != nil {
			panic(err)
		}
		defer reader.Close()
		scanner = bufio.NewScanner(reader)
	} else {
		scanner = bufio.NewScanner(os.Stdin)
	}
	scanner.Split(bufio.ScanWords)

	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	solveSequential(scanner, writer)
}

func readInt64(sc *bufio.Scanner) int64 {
	sc.Scan()
	res, err := strconv.ParseInt(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func readInt(sc *bufio.Scanner) int {
	return int(readInt64(sc))
}

func writef(writer *bufio.Writer, formatStr string, values ...interface{}) {
	out := fmt.Sprintf(formatStr, values...)
	_, err := writer.WriteString(out)
	if err != nil {
		panic(err)
	}
}

package main

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

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

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

	problems := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(f, "%d", &problems[i])
		sum += problems[i]
	}

	var prefixSum int
	for i := 0; i < n; i++ {
		prefixSum += problems[i]
		if prefixSum >= (sum+1)/2 {
			fmt.Println(i + 1)
			return
		}
	}
}

package main

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

func binSearch(arr []int, x int) int {
	var mid, lo, hi = 0, 0, len(arr) - 1

	for hi - lo > 1 {
		mid = (lo + hi) / 2
		switch {
			case x < arr[mid]: hi = mid
			case x > arr[mid]: lo = mid
			default: return mid
		}
	}

	if arr[hi] >= x {
		return hi
	} else {
		return lo
	}
}

func main() {
	var daysN, celebDay, halfDay int

	var reader *bufio.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscanf(reader, "%d\n", &daysN)

	days := make([]int, daysN)

	celebDay = 0
	fmt.Fscanf(reader, "%d", &days[0])
	for i := 1; i < daysN; i++ {
		fmt.Fscanf(reader, "%d", &days[i])
		days[i] += days[i - 1]
		halfDay = int(math.Ceil(float64(days[i]) / 2))
		if days[celebDay] < halfDay {
			celebDay += binSearch(days[celebDay:i + 1], halfDay)
		}
	}

	fmt.Println(celebDay + 1)
}

package main

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

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

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

	problems := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(f, "%d", &problems[i])
		sum += problems[i]
	}

	var prefixSum int
	for i := 0; i < n; i++ {
		prefixSum += problems[i]
		if prefixSum >= sum/2 {
			fmt.Println(i + 1)
			return
		}
	}
}

package main

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

func binSearch(arr []int, x int) int {
	var mid, lo, hi = 0, 0, len(arr) - 1

	for hi - lo > 1 {
		mid = (lo + hi) / 2
		switch {
			case x < arr[mid]: hi = mid
			case x > arr[mid]: lo = mid
			default: return mid
		}
	}

	if arr[hi] >= x {
		return hi
	} else {
		return lo
	}
}

func main() {
	var daysN, celebDay int

	var reader *bufio.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscanf(reader, "%d\n", &daysN)

	days := make([]int, daysN)

	celebDay = 0
	fmt.Fscanf(reader, "%d ", &days[0])
	for i := 1; i < daysN; i++ {
		fmt.Fscanf(reader, "%d ", &days[i])
		days[i] += days[i - 1]
		if days[celebDay] < days[i] / 2 {
			celebDay += binSearch(days[celebDay:i + 1], days[i] / 2)
		}
	}

	fmt.Println(celebDay + 1)
}