package main

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

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

func main() {
	defer out.Flush()

	var test int
	fmt.Fscan(in, &test)
	for test > 0 {
		test--
		solve()
	}
}

func solve() {
	var n, m, x int
	fmt.Fscan(in, &n, &m)
	l := n + m - 2
	cntTotal := make([]int, l/2+1)
	cnt1 := make([]int, l/2+1)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscan(in, &x)
			dist := i + j
			if dist == l-dist {
				continue
			}
			if dist > l-dist {
				dist = l - dist
			}
			cntTotal[dist]++
			if x == 1 {
				cnt1[dist]++
			}
		}
	}
	res := 0
	for i := 0; i <= l/2; i++ {
		cnt0 := cntTotal[i] - cnt1[i]
		if cnt0 < cnt1[i] {
			res += cnt0
		} else {
			res += cnt1[i]
		}
	}
	fmt.Fprintln(out, res)
}

package main

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

func main() {
	t := nextInt()
	for i := 0; i < t; i++ {
		n, m := nextInt(), nextInt()
		matrix := make([][]int, n)
		for r := 0; r < n; r++ {
			matrix[r] = nextInts(m)
		}
		fmt.Println(solve(matrix))
	}
}

func solve(matrix [][]int) int {
	n, m := len(matrix), len(matrix[0])
	distToCount := make([][]int, n+m-1)
	for i := 0; i < n+m-1; i++ {
		distToCount[i] = make([]int, 2)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			distToCount[i+j][matrix[i][j]]++
		}
	}

	ans := 0
	for dist := 0; dist <= n+m-2; dist++ {
		oppositOfDist := n + m - 2 - dist
		if dist >= oppositOfDist {
			break
		}
		ans += Min(
			distToCount[dist][0]+distToCount[oppositOfDist][0],
			distToCount[dist][1]+distToCount[oppositOfDist][1],
		)
	}
	return ans
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

package main

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

func main() {
	t := nextInt()
	for i := 0; i < t; i++ {
		n, m := nextInt(), nextInt()
		matrix := make([][]int, n)
		for r := 0; r < n; r++ {
			matrix[r] = nextInts(m)
		}
		fmt.Println(solve2(matrix))
	}
}

func solve2(matrix [][]int) int {
	n, m := len(matrix), len(matrix[0])
	cnt := make([][]int, n+m-1)
	for i := 0; i < n+m-1; i++ {
		cnt[i] = make([]int, 2)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			cnt[i+j][matrix[i][j]]++
		}
	}

	ans := 0
	for i := 0; i <= n+m-2; i++ {
		j := n + m - 2 - i
		if i <= j {
			continue
		}
		ans += Min(
			cnt[i][0]+cnt[j][0],
			cnt[i][1]+cnt[j][1],
		)
	}
	return ans
}

func solve(matrix [][]int) int64 {
	n := len(matrix)
	m := len(matrix[0])

	var result int64

	maxDist := n - 1 + m - 1
	var I int
	if maxDist%2 == 0 {
		I = maxDist / 2
	} else {
		I = maxDist/2 + 1
	}
	for i := 0; i < I; i++ {
		count0 := 0
		count1 := 0

		for y := 0; y < n; y++ {
			x := i - y
			if x < 0 {
				break
			}
			if x >= m {
				break
			}

			if matrix[y][x] == 1 {
				count1++
			} else {
				count0++
			}

			y2 := (n - 1) - y
			x2 := (m - 1) - x

			if !(y2 == y && x2 == x) {
				if matrix[y2][x2] == 1 {
					count1++
				} else {
					count0++
				}
			}
		}

		min := Min(count0, count1)
		result += int64(min)
	}

	return result
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

/*
URL:
https://codeforces.com/problemset/problem/1366/C
*/

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
	A    [][]int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, m = ReadInt2()
		A = [][]int{}
		for j := 0; j < n; j++ {
			row := ReadIntSlice(m)
			A = append(A, row)
		}

		solve()
	}
}

func solve() {
	ans := 0

	// グループの数
	cnts := make([][2]int, n+m-1)
	// 普通の二重ループでスキャン、グループごとに1/0の数をカウントする
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			cnts[i+j][A[i][j]]++
		}
	}

	for i := 0; i <= n+m-2; i++ {
		j := n + m - 2 - i

		// iがj以上になったら終了
		if i >= j {
			break
		}

		// 小さい方を上塗りする
		ans += Min(cnts[i][0]+cnts[j][0], cnts[i][1]+cnts[j][1])
	}

	fmt.Println(ans)
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

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

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

var nTest, n, m int
var a [30][30]int

func level(x, y int) int {
	d1 := x + y
	d2 := n - 1 - x + m - 1 - y

	if d1 < d2 {
		return d1
	}

	return d2
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &nTest)

	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &n, &m)
		res := 0
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				fmt.Fscan(in, &a[i][j])
			}
		}

		for l := 0; l < (n+m-1)/2; l++ {
			zero := 0
			one := 0
			for i := 0; i < n; i++ {
				for j := 0; j < m; j++ {
					lv := level(i, j)

					if lv == l {
						if a[i][j] == 1 {
							one++
						} else {
							zero++
						}
					}
				}
			}
			// fmt.Println(l, zero, one)
			if zero < one {
				res += zero
			} else {
				res += one
			}
		}

		fmt.Fprintln(out, res)
	}
	out.Flush()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1366C(_r io.Reader, out io.Writer) {
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	in := bufio.NewReader(_r)
	var t, n, m, v int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		a := make([][2]int, n+m-1)
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				Fscan(in, &v)
				a[i+j][v]++
			}
		}
		ans := 0
		for i, j := 0, n+m-2; i < j; i++ {
			ans += min(a[i][0]+a[j][0], a[i][1]+a[j][1])
			j--
		}
		Fprintln(out, ans)
	}
}

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

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	t := getNextInt(scanner)
	for i := 0; i < t; i++ {
		testcase(scanner, writer)
	}
}
func testcase(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := getNextInt(scanner)
	g := makeGrid(n, m)
	dd := makeGrid(n+m-1, 2)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			g[i][j] = getNextInt(scanner)
			dd[i+j][g[i][j]]++
		}
	}
	var ans int
	for i := 0; i < n+m-1; i++ {
		if i == n+m-2-i {
			continue
		}
		ans += min(dd[i][0]+dd[n+m-2-i][0], dd[i][1]+dd[n+m-2-i][1])
	}
	fmt.Fprintln(writer, ans>>1)
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func makeGrid(h, w int) [][]int {
	index := make([][]int, h, h)
	data := make([]int, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

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

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

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

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

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

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

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

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

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

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

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

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

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

func sol(n, m int64, nm [][]int64) int64 {
	ret := int64(0)
	steps := n + m - 1
	for offset := int64(0); offset < steps/2; offset++ {
		counts := map[int64]int64{
			0: 0,
			1: 0,
		}
		for i := int64(0); i <= offset; i++ {
			j := offset - i
			if i >= 0 && i < n && j >= 0 && j < m {
				counts[nm[i][j]]++
				counts[nm[n-1-i][m-1-j]]++
			}
		}
		ret += min(counts[0], counts[1])
	}
	return ret
}

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)

		G := make([][]int, n)

		for i := 0; i < n; i++ {
			G[i] = readNNums(reader, m)
		}

		fmt.Println(solve(n, m, G))
	}
}

func solve(n int, m int, G [][]int) int {
	N := n + m - 1

	cnt := make([]int, N)
	cnt1 := make([]int, N)

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			k := i + j
			if k <= N-1-k {
				cnt[k]++
				cnt1[k] += G[i][j]
			} else {
				cnt[N-1-k]++
				cnt1[N-1-k] += G[i][j]
			}
		}
	}

	var res int

	h := N / 2

	for i := 0; i < h; i++ {
		if cnt1[i] == cnt[i] {
			continue
		}
		res += min(cnt1[i], cnt[i]-cnt1[i])
	}

	return res
}

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

package main

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

const (
	mod = int64(1e9 + 7)
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 1
	fmt.Fscanf(in, "%d\n", &t)
	for tt := 0; tt < t; tt++ {
		n, m := 0, 0
		fmt.Fscanf(in, "%d %d\n", &n, &m)
		dis0 := make([]int, n+m)
		dis1 := make([]int, n+m)
		tmp := 0
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				fmt.Fscanf(in, "%d", &tmp)
				if tmp == 0 {
					dis0[i+j]++
				} else {
					dis1[i+j]++
				}
			}
			fmt.Fscanf(in, "\n")
		}
		ans := 0
		for i := 0; i < n+m; i++ {
			a := i
			b := n + m - 2 - i
			if a >= b {
				break
			}
			//fmt.Println(a, b)
			ans += min(dis0[a]+dis0[b], dis1[a]+dis1[b])
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

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

package main

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

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

	return i
}

func cost(a [][]int, l, m, n int) int {
	var c int

	cnt11 := 0
	cnt01 := 0

	for r := 0; r < n; r++ {
		c = l - r
		if c <= m-1 && c >= 0 {
			if a[r][c] == 0 {
				cnt01++
			} else {
				cnt11++
			}
		}
	}

	cnt02 := 0
	cnt12 := 0

	for r := 0; r < n; r++ {
		c = (n + m - 2 - l) - r

		if c <= m-1 && c >= 0 {
			if a[r][c] == 0 {
				cnt02++
			} else {
				cnt12++
			}
		}
	}

	//fmt.Println("---->", l, cnt01, cnt11, cnt02, cnt12)

	v1 := abs(cnt01 + cnt02)
	v2 := abs(cnt12 + cnt11)

	if v1 < v2 {
		return v1
	}

	return v2

}

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

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

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

		a := make([][]int, n)

		for i := range a {
			a[i] = make([]int, m)

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

		c := 0

		for l := 0; l < (n+m-1)/2; l++ {
			c1 := cost(a, l, m, n)
			// fmt.Println("------->", l, c1)
			c += c1
		}

		fmt.Println(c)

	}
}

package main

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

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

	return i
}

func cost(a [][]int, l, m, n int) int {
	r := 0
	c := l

	if l >= m {
		c = m - 1
	}

	cnt11 := 0
	cnt01 := 0

	for r < n && c >= 0 {
		if a[r][c] == 0 {
			cnt01++
		} else {
			cnt11++
		}
		r++
		c--
	}

	cnt02 := 0
	cnt12 := 0

	r = n - 1
	c = m - 1 - l

	if c < 0 {
		c = 0
	}

	for r >= 0 && c < m {
		if a[r][c] == 0 {
			cnt02++
		} else {
			cnt12++
		}
		r--
		c++
	}

	//fmt.Println("---->", l, cnt01, cnt11, cnt02, cnt12)

	v1 := abs(cnt01 + cnt02)
	v2 := abs(cnt12 + cnt11)

	if v1 < v2 {
		return v1
	}

	return v2

}

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

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

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

		a := make([][]int, n)

		for i := range a {
			a[i] = make([]int, m)

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

		c := 0

		for l := 0; l < (n+m-1)/2; l++ {
			c1 := cost(a, l, m, n)
			// fmt.Println("------->", l, c1)
			c += c1
		}

		fmt.Println(c)

	}
}

package main

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

func main() {
	t := nextInt()
	for i := 0; i < t; i++ {
		n, m := nextInt(), nextInt()
		matrix := make([][]int, n)
		for r := 0; r < n; r++ {
			matrix[r] = nextInts(m)
		}
		fmt.Println(solve(matrix))
	}
}

func solve(matrix [][]int) int64 {
	n := len(matrix)
	m := len(matrix[0])

	var result int64

	maxDist := n - 1 + m - 1
	var I int
	if maxDist%2 == 0 {
		I = maxDist / 2
	} else {
		I = maxDist/2 + 1
	}
	for i := 0; i < I; i++ {
		count0 := 0
		count1 := 0

		for y := 0; y < n; y++ {
			x := i - y
			if x < 0 {
				break
			}
			if x >= m {
				break
			}

			if matrix[y][x] == 1 {
				count1++
			} else {
				count0++
			}

			y2 := (n - 1) - y
			x2 := (m - 1) - x

			if !(y2 == y && x2 == x) {
				if matrix[y2][x2] == 1 {
					count1++
				} else {
					count0++
				}
			}
		}

		min := Min(count0, count1)
		result += int64(min)
	}

	return result
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

package main

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

func main() {
	t := nextInt()
	for i := 0; i < t; i++ {
		n, m := nextInt(), nextInt()
		matrix := make([][]int, n)
		for r := 0; r < n; r++ {
			matrix[r] = nextInts(m)
		}
		fmt.Println(solve(matrix))
	}
}

func solve(matrix [][]int) int64 {
	n := len(matrix)
	m := len(matrix[0])

	var result int64

	maxDist := n - 1 + m - 1
	for i := 0; i < (maxDist+1)/2; i++ {
		count0 := 0
		count1 := 0

		for y := 0; y < n; y++ {
			x := i - y
			if x < 0 {
				break
			}
			if x >= m {
				break
			}

			if matrix[y][x] == 1 {
				count1++
			} else {
				count0++
			}

			y2 := (n - 1) - y
			x2 := (m - 1) - x

			if !(y2 == y && x2 == x) {
				if matrix[y2][x2] == 1 {
					count1++
				} else {
					count0++
				}
			}
		}

		min := Min(count0, count1)
		result += int64(min)
	}

	return result
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}


package main

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

type scanner struct {
  s *bufio.Scanner
}

func NewScanner() *scanner {
  s := bufio.NewScanner(os.Stdin)
  s.Split(bufio.ScanWords)
  return &scanner{s}
}

func (i *scanner) Next() string {
  i.s.Scan()
  return i.s.Text()
}

func (i *scanner) NextInt() int {
  v, _ := strconv.Atoi(i.Next())
  return v
}

func (i *scanner) NextInts(n int) []int {
  res := make([]int, n)
  for j := range res {
    res[j] = i.NextInt()
  }
  return res
}

func main() {
  cin := NewScanner()
  t := cin.NextInt()
  for ti := 0; ti < t; ti++ {
    n := cin.NextInt()
    a, b := cin.NextInts(n), cin.NextInts(n)
    idxb := make([]int, n)
    for i, v := range b {
      idxb[(v - 1) / 2] = i
    }
    sufMinIdxb := make([]int, n)
    sufMinIdxb[n - 1] = idxb[n - 1]
    for i := n - 2; i >= 0; i-- {
      if sufMinIdxb[i + 1] < idxb[i] {
        sufMinIdxb[i] = sufMinIdxb[i + 1]
      } else {
        sufMinIdxb[i] = idxb[i]
      }
    }
    ans := n + n
    for i, vv := range a {
      v := (vv - 1) / 2
      t := i + sufMinIdxb[v]
      if t < ans {
        ans = t
      }
    }
    fmt.Println(ans)
  }
}

package main

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

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

	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		pos := make([]int, n)
		for i := range pos {
			Fscan(in, &v)
			pos[v/2] = i
		}
		minP := make([]int, n)
		minP[0] = pos[0]
		for i := 1; i < n; i++ {
			minP[i] = min(minP[i-1], pos[i])
		}
		ans := int(1e9)
		for i := 0; i < n; i++ {
			Fscan(in, &v)
			ans = min(ans, i+minP[v/2-1])
		}
		Fprintln(out, ans)
	}
}

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

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

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

func (s *Scanner) Word() string {
	s.Scan()
	return s.Text()
}

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

func solve(a, b []int) int {
	cost := make([]int, len(a)+len(b)+1)
	for i := range a {
		cost[a[i]] = i
		cost[b[i]] = i
	}

	bestA := make([]int, len(a)*2+1)
	for i := 1; i < len(bestA); i += 2 {
		if i > 1 && bestA[i-2] < cost[i] {
			bestA[i] = bestA[i-2]
		} else {
			bestA[i] = cost[i]
		}
	}

	bestB := make([]int, len(b)*2+1)
	for i := 2 * len(b); i > 0; i -= 2 {
		if i+2 < len(bestB) && bestB[i+2] < cost[i] {
			bestB[i] = bestB[i+2]
		} else {
			bestB[i] = cost[i]
		}
	}

	res := len(a) + len(b)
	for i := 1; i < len(a)+len(b); i += 2 {
		if c := bestA[i] + bestB[i+1]; c < res {
			res = c
		}
	}
	return res
}

func main() {
	stdin := NewWordScanner(os.Stdin)
	tests := stdin.Int()

	for i := 0; i < tests; i++ {
		n := stdin.Int()
		a := stdin.Ints(n)
		b := stdin.Ints(n)
		fmt.Println(solve(a, b))
	}
}


package main

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

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

	var T int
	var s []byte
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &s)
		n := len(s)
		cnt := [26]int{}
		for _, b := range s {
			cnt[b-'a']++
		}
		set := []int{}
		p1 := -1
		for i, c := range cnt {
			if c > 0 {
				set = append(set, i)
				if c == 1 && p1 < 0 {
					p1 = i
				}
			}
		}
		if len(set) == 1 {
			Fprintf(out, "%s\n", s)
			continue
		}
		sort.Slice(s, func(i, j int) bool { return s[i] < s[j] })
		if p1 >= 0 {
			c := 'a' + byte(p1)
			i := bytes.IndexByte(s, c)
			Fprintf(out, "%c%s%s\n", c, s[:i], s[i+1:])
			continue
		}
		cnt0 := cnt[set[0]]
		c0 := 'a' + byte(set[0])
		if cnt0-2 <= n-cnt0 {
			Fprintf(out, "%c%c", c0, c0)
			cnt0 -= 2
			for _, i := range set[1:] {
				for cc := cnt[i]; cc > 0; cc-- {
					Fprintf(out, "%c", 'a'+byte(i))
					if cnt0 > 0 {
						Fprintf(out, "%c", c0)
						cnt0--
					}
				}
			}
			Fprintln(out)
		} else if len(set) == 2 {
			Fprintf(out, "%c%s%s\n", c0, strings.Repeat(string('a'+byte(set[1])), cnt[set[1]]), strings.Repeat(string('a'+byte(set[0])), cnt[set[0]]-1))
		} else {
			Fprintf(out, "%c%c%s%c", c0, 'a'+byte(set[1]), strings.Repeat(string('a'+byte(set[0])), cnt[set[0]]-1), 'a'+byte(set[2]))
			cnt[set[1]]--
			cnt[set[2]]--
			for _, i := range set[1:] {
				for cc := cnt[i]; cc > 0; cc-- {
					Fprintf(out, "%c", 'a'+byte(i))
				}
			}
			Fprintln(out)
		}
	}
}

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

package main

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

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

	var T int
	var s []byte
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &s)
		n := len(s)
		cnt := [26]int{}
		for _, b := range s {
			cnt[b-'a']++
		}
		set := []int{}
		pc1 := -1
		for i, c := range cnt {
			if c > 0 {
				set = append(set, i)
				if c == 1 && pc1 < 0 {
					pc1 = i
				}
			}
		}
		if len(set) == 1 {
			Fprintf(out, "%s\n", s)
			continue
		}
		if pc1 >= 0 {
			sort.Slice(s, func(i, j int) bool { return s[i] < s[j] })
			b := 'a' + byte(pc1)
			i := bytes.IndexByte(s, b)
			Fprintf(out, "%c%s%s\n", b, s[:i], s[i+1:])
			continue
		}
		cnt0 := cnt[set[0]]
		b0 := 'a' + byte(set[0])
		if cnt0-2 <= n-cnt0 {
			Fprintf(out, "%c%c", b0, b0)
			cnt0 -= 2
			for _, i := range set[1:] {
				for c := cnt[i]; c > 0; c-- {
					Fprintf(out, "%c", 'a'+byte(i))
					if cnt0 > 0 {
						Fprintf(out, "%c", b0)
						cnt0--
					}
				}
			}
			Fprintln(out)
		} else if len(set) == 2 {
			Fprintf(out, "%c%s%s\n", b0, strings.Repeat(string('a'+byte(set[1])), cnt[set[1]]), strings.Repeat(string('a'+byte(set[0])), cnt[set[0]]-1))
		} else {
			Fprintf(out, "%c%c%s%c", b0, 'a'+byte(set[1]), strings.Repeat(string('a'+byte(set[0])), cnt[set[0]]-1), 'a'+byte(set[2]))
			cnt[set[1]]--
			cnt[set[2]]--
			for _, i := range set[1:] {
				Fprintf(out, "%s", strings.Repeat(string('a'+byte(i)), cnt[i]))
			}
			Fprintln(out)
		}
	}
}

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

package main

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

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

	var T int
	var s []byte
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &s)
		n := len(s)
		cnt := [26]int{}
		for _, b := range s {
			cnt[b-'a']++
		}
		set := []int{}
		p1 := -1
		for i, c := range cnt {
			if c > 0 {
				set = append(set, i)
				if c == 1 && p1 < 0 {
					p1 = i
				}
			}
		}
		if len(set) == 1 {
			Fprintf(out, "%s\n", s)
			continue
		}
		sort.Slice(s, func(i, j int) bool { return s[i] < s[j] })
		if p1 >= 0 {
			c := 'a' + byte(p1)
			i := bytes.IndexByte(s, c)
			Fprintf(out, "%c%s%s\n", c, s[:i], s[i+1:])
			continue
		}
		cnt0 := cnt[set[0]]
		c0 := 'a' + byte(set[0])
		if cnt0-2 <= n-cnt0 {
			Fprintf(out, "%c%c", c0, c0)
			cnt0 -= 2
			for cc := cnt[set[1]]; cc > 0; cc-- {
				Fprintf(out, "%c", 'a'+byte(set[1]))
				if cnt0 > 0 {
					Fprintf(out, "%c", c0)
					cnt0--
				}
			}
			Fprintln(out)
		} else if len(set) == 2 {
			Fprintf(out, "%c%s%s\n", c0, strings.Repeat(string('a'+byte(set[1])), cnt[set[1]]), strings.Repeat(string('a'+byte(set[0])), cnt[set[0]]-1))
		} else {
			Fprintf(out, "%c%c%s%c", c0, 'a'+byte(set[1]), strings.Repeat(string('a'+byte(set[0])), cnt[set[0]]-1), 'a'+byte(set[2]))
			cnt[set[1]]--
			cnt[set[2]]--
			for _, i := range set[1:] {
				for cc := cnt[i]; cc > 0; cc-- {
					Fprintf(out, "%c", 'a'+byte(i))
				}
			}
			Fprintln(out)
		}
	}
}

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


package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var n, m int
	fmt.Fscan(in, &n)

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

	b := make([]int64, n+1)
	for i := 0; i < n; i++ {
		b[i+1] = b[i] + int64(a[i])
	}

	sort.Ints(a)
	c := make([]int64, n+1)
	for i := 0; i < n; i++ {
		c[i+1] = c[i] + int64(a[i])
	}

	fmt.Fscan(in, &m)
	for i := 0; i < m; i++ {
		var q, l, r int
		fmt.Fscan(in, &q, &l, &r)
		if q == 1 {
			fmt.Fprintln(out, b[r]-b[l-1])
		} else {
			fmt.Fprintln(out, c[r]-c[l-1])
		}
	}
	out.Flush()
}

package main
import (
	"fmt"
	"sort"
	"bufio"
	"os"
	"strconv"
)
type lala []int64
func (a lala) Len() int           { return len(a) }
func (a lala) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a lala) Less(i, j int) bool { return a[i] < a[j] }
func main() {
	var n int
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	fmt.Scan(&n)
	ar:=make([]int64,n+1)
	sr:=make([]int64,n+1)
	for i:=1;i<=n;i++ {
		input.Scan()
		aa,_:=strconv.ParseInt(input.Text(),0,64)
		ar[i]=aa
		//fmt.Scan(&ar[i])
		sr[i]=ar[i]
		ar[i]+=ar[i-1]
	}
	sort.Sort(lala(sr))
	for i:=1;i<=n;i++ {
		sr[i]+=sr[i-1]
	}
	var s,q,l,r int
	input.Scan()
	ee,_:=strconv.Atoi(input.Text())
	s=ee
	//fmt.Scan(&s)
	for i:=0;i<s;i++ {
		input.Scan()
		dd,_:=strconv.Atoi(input.Text())
		q=dd

		input.Scan()
		bb,_:=strconv.Atoi(input.Text())
		l=bb

		input.Scan()
		cc,_:=strconv.Atoi(input.Text())
		r=cc

		//fmt.Scan(&q,&l,&r)
		if q==1 {
			fmt.Println(ar[r]-ar[l-1])
		} else {
			fmt.Println(sr[r]-sr[l-1])
		}
	}
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)

    ScanInts := func(a ...*int) {
        for i := 0; i < len(a); i++ {
            scanner.Scan()
            *(a[i]), _ = strconv.Atoi(scanner.Text())
        }
    }
    var n int
    ScanInts(&n)
    arr := make([]int, n, n)
    for i := 0; i < n; i++ {
        ScanInts(&arr[i])
    }

    ori_sum := make([]int64, n, n)
    sor_sum := make([]int64, n, n)
    ori_sum[0] = int64(arr[0])

    for i := 1; i < n; i++ {
        ori_sum[i] = ori_sum[i-1] + int64(arr[i])
    }
    sort.Ints(arr)
    sor_sum[0] = int64(arr[0])
    for i := 1; i < n; i++ {
        sor_sum[i] = sor_sum[i-1] + int64(arr[i])
    }

    var l, r, tp, nq int
    ScanInts(&nq)
    for ; nq > 0; nq-- {
        ScanInts(&tp, &l, &r)
        l--
        r--

        if tp == 1 {
            if l == 0 {
                fmt.Println(ori_sum[r])
            } else {
                fmt.Println(ori_sum[r] - ori_sum[l-1])
            }
        } else {
            if l == 0 {
                fmt.Println(sor_sum[r])
            } else {
                fmt.Println(sor_sum[r] - sor_sum[l-1])
            }
        }
    }
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)

    ScanInts := func(a... *int) {
        for i := 0; i < len(a); i++ {
            scanner.Scan()
            *(a[i]), _ = strconv.Atoi(scanner.Text())
        }
    }

    var n,m,l,r,t int
    ScanInts(&n)
    v, u := make([]int,n), make([]int,n)
    for i := 0; i < n; i++ {
        ScanInts(&v[i])
        u[i] = v[i]
    }
    sort.Ints(u)
    cv, cu := make([]int64,n), make([]int64,n)
    cv[0], cu[0] = int64(v[0]), int64(u[0])
    for i := 1; i < n; i++ {
        cv[i] = cv[i-1]+int64(v[i])
        cu[i] = cu[i-1]+int64(u[i])
    }
    ScanInts(&m)
    for i := 0; i < m; i++ {
        ScanInts(&t,&l,&r)
        l--; r--;
        if t == 1 {
            if l == 0 { writer.WriteString(strconv.FormatInt(cv[r],10)) } else { writer.WriteString(strconv.FormatInt(cv[r]-cv[l-1],10)) }
        } else {
            if l == 0 { writer.WriteString(strconv.FormatInt(cu[r],10)) } else { writer.WriteString(strconv.FormatInt(cu[r]-cu[l-1],10)) }
        }
        writer.WriteRune('\n')
    }
    writer.Flush()
}

package main

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

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

	var n int

	var srt, arr []int64
	srt, arr = append(srt, 0), append(arr, 0)

	fmt.Fscan(reader, &n)
	for i := 0; i < n; i++ {
		var x int64
		fmt.Fscan(reader, &x)
		srt = append(srt, x+srt[i])
		arr = append(arr, x)
	}

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

	for i := 1; i <= n; i++ {
		arr[i] = arr[i] + arr[i-1]
	}

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

	for qr > 0 {
		var tp, l, r int
		fmt.Fscan(reader, &tp, &l, &r)
		if tp == 1 {
			fmt.Println(srt[r] - srt[l-1])
		} else {
			fmt.Println(arr[r] - arr[l-1])
		}
		qr--
	}
}

package main
import (
	"fmt"
	"sort"
	"bufio"
	"os"
	"strconv"
)
type lala []int64
func (a lala) Len() int           { return len(a) }
func (a lala) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a lala) Less(i, j int) bool { return a[i] < a[j] }
func main() {
	var n int
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	fmt.Scan(&n)
	ar:=make([]int64,n+1)
	sr:=make([]int64,n+1)
	for i:=1;i<=n;i++ {
		input.Scan()
		aa,_:=strconv.ParseInt(input.Text(),0,64)
		ar[i]=aa
		//fmt.Scan(&ar[i])
		sr[i]=ar[i]
		ar[i]+=ar[i-1]
	}
	sort.Sort(lala(sr))
	for i:=1;i<=n;i++ {
		sr[i]+=sr[i-1]
	}
	var s,q,l,r int
	fmt.Scan(&s)
	for i:=0;i<s;i++ {
		input.Scan()
		aa,_:=strconv.Atoi(input.Text())
		q=aa

		input.Scan()
		bb,_:=strconv.Atoi(input.Text())
		l=bb

		input.Scan()
		cc,_:=strconv.Atoi(input.Text())
		r=cc

		//fmt.Scan(&q,&l,&r)
		if q==1 {
			fmt.Println(ar[r]-ar[l-1])
		} else {
			fmt.Println(sr[r]-sr[l-1])
		}
	}
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)

    ScanInts := func(a ...*int) {
        for i := 0; i < len(a); i++ {
            scanner.Scan()
            *(a[i]), _ = strconv.Atoi(scanner.Text())
        }
    }
    var n int
    ScanInts(&n)
    arr := make([]int, n, n)
    for i := 0; i < n; i++ {
        ScanInts(&arr[i])
    }

    ori_sum := make([]int64, n, n)
    sor_sum := make([]int64, n, n)
    ori_sum[0] = int64(arr[0])

    for i := 1; i < n; i++ {
        ori_sum[i] = ori_sum[i-1] + int64(arr[i])
    }
    sort.Ints(arr)
    sor_sum[0] = int64(arr[0])
    for i := 1; i < n; i++ {
        sor_sum[i] = sor_sum[i-1] + int64(arr[i])
    }

    var l, r, tp, nq int
    ScanInts(&nq)
    for ; nq > 0; nq-- {
        ScanInts(&tp, &l, &r)
        l--
        r--
        var result int64
        if tp == 1 {
            if l == 0 {
                result = ori_sum[r]
            } else {
                result = ori_sum[r] - ori_sum[l-1]
            }
        } else {
            if l == 0 {
                result = sor_sum[r]
            } else {
                result = sor_sum[r] - sor_sum[l-1]
            }
        }
        writer.WriteString(strconv.FormatInt(result, 10))
    }
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)

    ScanInts := func(a... *int) {
        for i := 0; i < len(a); i++ {
            scanner.Scan()
            *(a[i]), _ = strconv.Atoi(scanner.Text())
        }
    }

    var n,m,l,r,t int
    ScanInts(&n)
    v, u := make([]int,n), make([]int,n)
    for i := 0; i < n; i++ {
        ScanInts(&v[i])
        u[i] = v[i]
    }
    sort.Ints(u)
    for i := 1; i < n; i++ {
        v[i] += v[i-1]
        u[i] += u[i-1]
    }
    ScanInts(&m)
    for i := 0; i < m; i++ {
        ScanInts(&t,&l,&r)
        l--; r--;
        if t == 1 {
            if l == 0 { writer.WriteString(strconv.Itoa(v[r])) } else { writer.WriteString(strconv.Itoa(v[r]-v[l-1])) }
        } else {
            if l == 0 { writer.WriteString(strconv.Itoa(u[r])) } else { writer.WriteString(strconv.Itoa(u[r]-u[l-1])) }
        }
        writer.WriteRune('\n')
    }
    writer.Flush()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)

    ScanInts := func(a... *int) {
        for i := 0; i < len(a); i++ {
            scanner.Scan()
            *(a[i]), _ = strconv.Atoi(scanner.Text())
        }
    }

    var n,m,l,r,t int
    ScanInts(&n)
    v, u := make([]int,n), make([]int,n)
    for i := 0; i < n; i++ {
        ScanInts(&v[i])
        u[i] = v[i]
    }
    sort.Ints(u)
    cv, cu := make([]int64,n), make([]int64,n)
    cv[0], cu[0] = int64(v[0]), int64(u[0])
    for i := 1; i < n; i++ {
        v[i] += v[i-1]
        u[i] += u[i-1]
    }
    ScanInts(&m)
    for i := 0; i < m; i++ {
        ScanInts(&t,&l,&r)
        l--; r--;
        if t == 1 {
            if l == 0 { writer.WriteString(strconv.FormatInt(cv[r],10)) } else { writer.WriteString(strconv.FormatInt(cv[r]-cv[l-1],10)) }
        } else {
            if l == 0 { writer.WriteString(strconv.FormatInt(cu[r],10)) } else { writer.WriteString(strconv.FormatInt(cu[r]-cu[l-1],10)) }
        }
        writer.WriteRune('\n')
    }
    writer.Flush()
}

package main

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

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

	var n int

	var srt, arr []int
	srt, arr = append(srt, 0), append(arr, 0)

	fmt.Fscan(reader, &n)
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(reader, &x)
		srt = append(srt, x+srt[i])
		arr = append(arr, x)
	}

	sort.Ints(arr)
	for i := 1; i <= n; i++ {
		arr[i] = arr[i] + arr[i-1]
	}

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

	for qr > 0 {
		var tp, l, r int
		fmt.Fscan(reader, &tp, &l, &r)
		if tp == 1 {
			fmt.Println(srt[r] - srt[l-1])
		} else {
			fmt.Println(arr[r] - arr[l-1])
		}
		qr--
	}
}


package main

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

const maxN = 1023

func main() {
  in := bufio.NewReader(os.Stdin)
  out := bufio.NewWriter(os.Stdout)
  defer out.Flush()
  var tt int
  fmt.Fscan(in, &tt)
  for tc := 1; tc <= tt; tc++ {
    var n int
    fmt.Fscan(in, &n)
    var a[maxN] int
    res := "NO"
    for i := 0; i < n; i++ {
      fmt.Fscan(in, &a[i])
      sq := math.Sqrt(float64(a[i]))
      if math.Ceil(sq) != math.Floor(sq) {
        res = "YES"
      }
    }
    fmt.Fprintf(out, "%s\n", res)
  }
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		counter:=0
		for j:=0;j<n;j++{
			var x int
			fmt.Fscan(in,&x)
			if isIntegral(math.Sqrt(float64(x))) == false {
				counter++
			}
		}
		if counter == 0 {
			fmt.Fprintln(out,"NO")
		} else {
			fmt.Fprintln(out,"YES")
		}
	}
}

func isIntegral(x float64) bool {
	if x == float64(int(x)) {
		return true
	}
	return false
}

package main

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

func solve(r *bufio.Reader) {
	var n int
	fmt.Fscan(r, &n)
	nums := make([]int, n)
	hasNonquare := false
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &nums[i])
		if !hasNonquare {
			x := int(math.Sqrt(float64(nums[i])))
			if x*x != nums[i] {
				hasNonquare = true
			}
		}
	}

	if hasNonquare {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		solve(r)
	}
}

package main

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

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

func solve(n int, a []int) string {
	for _, x := range a {
		var isSquare = false
		for i := 1; i*i <= x; i++ {
			if i*i == x {
				isSquare = true
				break
			}
		}
		if !isSquare {
			return "YES"
		}
	}
	return "NO"
}

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"
	"io/ioutil"
	"os"
	"strconv"
	"strings"
)

var fields []string

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

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

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

	if err != nil {
		panic(err)
	}

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

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

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

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

	if err != nil {
		panic(err)
	}

	return n
}

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

	if err != nil {
		panic(err)
	}

	return n
}

func main() {
	isSquare := map[int]bool{}

	for i := 1; i <= 100; i++ {
		isSquare[i*i] = true
	}

	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		res := "NO"

		for i := 0; i < n; i++ {
			a := ScanInt()

			if !isSquare[a] {
				res = "YES"
			}
		}

		fmt.Println(res)
	}
}

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

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

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

	TC := sc.NextInt()
	for tc := 0; tc < TC; tc++ {
		N := sc.NextInt()
		arr := sc.NextInts(N)

		hasNonSquare := false
		for i := 0; i < N && !hasNonSquare; i++ {
			sq := int(math.Sqrt(float64(arr[i])) + 1e-7)
			if sq*sq != arr[i] {
				hasNonSquare = true
			}
		}
		if hasNonSquare {
			fmt.Fprintln(wr, "YES")
		} else {
			fmt.Fprintln(wr, "NO")
		}
	}

}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N, a int
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N)
		found := false
		for n := 0; n < N; n++ {
			Fscan(in, &a)
			if !isSquare(a) {
				found = true
			}
		}
		if found {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}

}

func isSquare(num int) bool {
	switch num & 0x0f {
	case 0:
		fallthrough
	case 1:
		fallthrough
	case 4:
		fallthrough
	case 9:
		temp := (int)(math.Sqrt(float64(num) + 0.5))
		return temp*temp == num
	default:
		return false
	}
}

package main

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

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

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

	var cases [][]int
	for i := 0; i < t; i++ {
		var n int
		_, _ = fmt.Fscan(reader, &n)
		var numbers []int
		for j := 0; j < n; j++ {
			var v int
			_, _ = fmt.Fscan(reader, &v)
			numbers = append(numbers, v)
		}
		cases = append(cases, numbers)
	}

	for _, v := range cases {
		fmt.Fprintln(writer, solution(v))
	}
}

func solution(numbers []int) string {
	for _, v := range numbers {
		sqrt := math.Sqrt(float64(v))
		if sqrt != float64(int64(sqrt)) {
			return "Yes"
		}
	}

	return "No"
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscanf(in, "%d\n", &t)
	for caseidx := 0; caseidx < t; caseidx++ {
		var n int
		var array []int
		fmt.Fscanf(in, "%d\n", &n)
		for i := 0; i < n; i++ {
			var a int
			fmt.Fscanf(in, "%d", &a)
			array = append(array, a)
		}
		fmt.Fscanf(in, "\n")
		flag := true
		for i := 0; i < len(array); i++ {
			var sqr int
			sqr = int(math.Sqrt(float64(array[i])))
			if sqr*sqr != array[i] {
				flag = false
			}
		}
		if !flag {
			fmt.Fprintf(out, "YES\n")
		} else {
			fmt.Fprintf(out, "NO\n")
		}
	}
	out.Flush()
}

package main

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

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

for v := 1;v*v<=1e4;v++ {
	sq[v*v]=true
}
	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		for _, v := range a {
			if !sq[v] {
				Fprintln(out, "YES")
				return
			}
		}
		Fprintln(out, "NO")
	}

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

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1514A
Date: 2/11/21
User: epradere
URL: https://codeforces.com/problemset/problem/1514/A
Problem: CF1514A
**/
func (in *CF1514A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt()
		ws := false
		for i := 0; i < n; i++ {
			num := in.NextInt()
			root := int(math.Sqrt(float64(num)))
			if root*root == num {
				continue
			} else {
				ws = true

			}
		}
		if ws {
		 	fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}

}

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

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

package main

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

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

	solve := func() {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)

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

		for i := 0; i < n; i++ {

			x := a[i]
			o := int(math.Sqrt(float64(x)))
			if o*o != x {
				fmt.Fprintln(out, "YES")
				return
			}
		}

		fmt.Fprintln(out, "NO")

	}

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

}

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

package main

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

const maxN = 1023

func main() {
  in := bufio.NewReader(os.Stdin)
  out := bufio.NewWriter(os.Stdout)
  defer out.Flush()
  var tt int
  fmt.Fscan(in, &tt)
  for tc := 1; tc <= tt; tc++ {
    var n int
    fmt.Fscan(in, &n)
    var a[maxN] int
    var flag bool
    flag = false
    for i := 0; i < n; i++ {
      fmt.Fscan(in, &a[i])
      sq := math.Sqrt(float64(a[i]))
      if math.Ceil(sq) != math.Floor(sq) {
        flag = true
      }
    }
    if flag {
      fmt.Fprint(out, "YES\n")
    }else {
      fmt.Fprint(out, "NO\n")
    }
  }
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1514A
Date: 2/11/21
User: epradere
URL: https://codeforces.com/problemset/problem/1514/A
Problem: CF1514A
**/
func (in *CF1514A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt()
		for i := 0; i < n; i++ {
			num := in.NextInt()
			root := int(math.Sqrt(float64(num)))
			if root*root == num {
				continue
			} else {
				fmt.Println("YES")
			}
		}

		fmt.Println("NO")
	}

}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1514A
Date: 2/11/21
User: epradere
URL: https://codeforces.com/problemset/problem/1514/A
Problem: CF1514A
**/
func (in *CF1514A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt()
		mapa := map[int]int{}
		for i := 0; i < n; i++ {
			num := in.NextInt()
			_, ok := mapa[num]
			if !ok {
				mapa[num] = 0
			}
			mapa[num]++
		}
		par := 0
		impar := 0
		ws := false
		for k, v := range mapa {

			root := int(math.Sqrt(float64(k)))
			if root * root == k {
				ws = true
				break
			}

			if v >= 2 {
				ws = true
				break
			}
			if k%10 == 0 {
				exp := int(math.Log10(float64(k)))
				if exp%2 == 0 {
					par ++
				} else {
					impar ++
				}
			}
		}
		if ws || par >= 2 || impar >= 2 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}

}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1514A
Date: 2/11/21
User: epradere
URL: https://codeforces.com/problemset/problem/1514/A
Problem: CF1514A
**/
func (in *CF1514A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt()
		mapa := map[int]int{}
		for i := 0; i < n; i++ {
			num := in.NextInt()
			_, ok := mapa[num]
			if !ok {
				mapa[num] = 0
			}
			mapa[num]++
		}
		par := 0
		impar := 0
		ws := false
		for k, v := range mapa {
			if v >= 2 {
				ws = true
				break
			}
			if k%10 == 0 {
				exp := int(math.Log10(float64(k)))
				if exp%2 == 0 {
					par ++
				} else {
					impar ++
				}
			}
		}
		if ws || par >= 2 || impar >= 2 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}

}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1514A
Date: 2/11/21
User: epradere
URL: https://codeforces.com/problemset/problem/1514/A
Problem: CF1514A
**/
func (in *CF1514A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt()
		mapa := map[int]int{}
		for i := 0; i < n; i++ {
			num := in.NextInt()
			_, ok := mapa[num]
			if !ok {
				mapa[num] = 0
			}
			mapa[num]++
		}
		par := 0
		impar := 0
		ws := false
		for k, v := range mapa {
			if v >= 2 {
				ws = true
				break
			}
			if k%10 == 0 {
				exp := int(math.Log10(float64(k)))
				if exp%2 == 0 {
					par ++
				} else {
					impar ++
				}
			}
		}
		if ws || par >= 2 || impar >= 2 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}

}

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

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

package main

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

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

	solve := func() {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a)
		}

		for i := 0; i < n; i++ {

			x := a[i]
			o := int(math.Sqrt(float64(x)))
			if o*o != x {
				fmt.Fprintln(out, "YES")
				return
			}
		}

		fmt.Fprintln(out, "NO")

	}

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

}

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

package main

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

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

	solve := func() {
		var n int
		fmt.Fscan(in, &n)

		for i := 0; i < n; i++ {
			var x int
			fmt.Fscan(in, &x)
			o := int(math.Sqrt(float64(x)))
			if o*o != x {
				fmt.Fprintln(out, "YES")
				return
			}
		}
		fmt.Fprintln(out, "NO")

	}

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

}

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


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

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() {
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var n int

func main() {
	n = ReadInt()

	if n%2 == 0 {
		b := 4
		a := n + b
		fmt.Println(a, b)
	} else {
		b := 9
		a := n + b
		fmt.Println(a, b)
	}
}

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

/*********** 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"
	"bytes"
	"fmt"
	"io"
	"os"
	"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

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
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func gcdll(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcdll(b, a%b)
}

// 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 := readll()
	println(9*n, 8*n)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n int64
	fmt.Fscan(reader, &n)
	fmt.Fprintln(writer, 9 * n, 8 * n)
}//2020-08-07 14:40:31.758

package main

import "fmt"

func main() {
	var n int64
	fmt.Scan(&n)
	var p,q int64
	if n%2 == 0 {
		p = 4
	} else {
		p = 9
	}
	q = p + n
	fmt.Println(q,p)
}

package main

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

//https://codeforces.com/contest/1269

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

	var n int

	fmt.Fscan(in, &n)

	for max := 2; max < 5000001; max++ {
		for b1 := 2; b1 <= max; b1++ {
			for b2 := 2; b2 <= b1; b2++ {
				for a2 := 2; a2 <= b2; a2++ {
					if (n+b1*b2)%a2 == 0 {
						a1 := (n + b1*b2) / a2
						fmt.Fprint(out, a1*a2)
						fmt.Fprint(out, " ")
						fmt.Fprint(out, b1*b2)
						out.Flush()
						return
					}
				}
			}
		}
	}
}

package main

import "fmt"

func isPrime(a int) bool {
	prime := true
	for i := 2; i < a-1; i++ {
		rest := a % i
		if rest == 0 {
			prime = false
			break
		}
	}
	return prime
}

func main() {
	var n int
	fmt.Scan(&n)
	b := 4
	var a int
	for {
		if !isPrime(b) {
			a = b + n
			if !isPrime(a) {
				fmt.Println(a, b)
				break
			}
		}
		b++
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := int64(1)
	fmt.Fscanf(in, "%d\n", &n)
	fmt.Fprintf(out, "%d %d\n", 9*n, 8*n)
}

package main

import (
        "fmt"
)

func main() {
        var n int
        fmt.Scanf("%d", &n)

        start := n
        end := start + n

        if !isComposite(start) {
                start *= 2
                end = start + n
        }

        for {
                if isComposite(end) {
                        fmt.Println(end, start)
                        return
                } else {
                        start *= 2
                        end = start + n
                }
        }
}

func isComposite(v int) bool {
        for i := 2; i < v; i++ {
                if v%i == 0 {
                        return true
                }
        }
        return false
}

package main

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

var n int

func main() {
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)
	fmt.Fscanf(reader, "%d\n", &n)
	fmt.Println(n*9, n*8)
}

//go 1.10.4

package main
import "fmt"
func main() {
  var n int
  fmt.Scanln(&n)
  fmt.Println(9*n, 8*n)
}

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

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

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

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

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

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60
const INF_INT32 = math.MaxInt32
const INF_BIT30 = 1 << 30

var n int

func main() {
	n = ReadInt()

	if n%2 == 0 {
		b := 4
		a := n + b
		fmt.Println(a, b)
	} else {
		b := 9
		a := n + b
		fmt.Println(a, b)
	}
}

/*
- まずは全探索を検討しましょう
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
	- MOD取る系はint64必須ですよ？
*/

/*
ASCII code

ASCII   10進数  ASCII   10進数  ASCII   10進数
!       33      "       34      #       35
$       36      %       37      &       38
'       39      (       40      )       41
*       42      +       43      ,       44
-       45      .       46      /       47
0       48      1       49      2       50
3       51      4       52      5       53
6       54      7       55      8       56
9       57      :       58      ;       59
<       60      =       61      >       62
?       63      @       64      A       65
B       66      C       67      D       68
E       69      F       70      G       71
H       72      I       73      J       74
K       75      L       76      M       77
N       78      O       79      P       80
Q       81      R       82      S       83
T       84      U       85      V       86
W       87      X       88      Y       89
Z       90      [       91      \       92
]       93      ^       94      _       95
`       96      a       97      b       98
c       99      d       100     e       101
f       102     g       103     h       104
i       105     j       106     k       107
l       108     m       109     n       110
o       111     p       112     q       113
r       114     s       115     t       116
u       117     v       118     w       119
x       120     y       121     z       122
{       123     |       124     }       125
~       126             127
*/

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

package main

import (
        "fmt"
)

func main() {
        var n int
        fmt.Scanf("%d", &n)

        start := n
        end := start + n

        for {
                if isComposite(end) {
                        fmt.Println(end, start)
                        return
                } else {
                        start *= 2
                        end = start + n
                }
        }
}

func isComposite(v int) bool {
        for i := 2; i < v; i++ {
                if v%i == 0 {
                        return true
                }
        }
        return false
}

package main

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

//https://codeforces.com/contest/1269

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

	var n int

	fmt.Fscanln(in, &n)

	for max := 2; max < 5000001; max++ {
		for b1 := 2; b1 < max; b1++ {
			for b2 := 2; b2 <= b1; b2++ {
				for a2 := 2; a2 < b2; a2++ {
					if (n+b1*b2)%a2 == 0 {
						a1 := (n + b1*b2) / a2
						fmt.Fprintln(out, a1*a2, " ", b1*b2)
						return
					}
				}
			}
		}
	}
}


package main

import (
	"fmt"
)

func calculate_probability(chars []int, n int) float64 {
	cnt := make([]int, 26)
	sz := len(chars)
	unique := 0

	for i := 0; i < sz; i++ {
		cnt[chars[i]]++
	}
	for i := 0; i < 26; i++ {
		if cnt[i] == 1 {
			unique++
		}
	}
	return float64(unique) / float64(sz) / float64(n)
}

func main() {
	var s string
	fmt.Scanf("%s\n", &s)
	mapping := make([][][]int, 26)

	n := len(s)
	for start := 0; start < n; start++ {
		for length := 1; length < n; length++ {
			fromchar := s[start] - byte('a')
			tochar := s[(start+length)%n] - byte('a')

			if mapping[fromchar] == nil {
				mapping[fromchar] = make([][]int, n)
			}

			mapping[fromchar][length] = append(mapping[fromchar][length], int(tochar))
		}
	}

	prob := 0.0
	probs := make([][]float64, 26)

	for i := 0; i < 26; i++ {
		probs[i] = make([]float64, n)
		if mapping[i] == nil {
			continue
		}
		for k := 0; k < n; k++ {
			probs[i][k] = calculate_probability(mapping[i][k], n)
		}
	}

	for i := 0; i < n; i++ {
		fromchar := s[i] - byte('a')
		bestprob := 0.0
		for i := 1; i < n; i++ {
			if bestprob < probs[fromchar][i] {
				bestprob = probs[fromchar][i]
			}
		}
		prob += bestprob
	}

	fmt.Printf("%.9f\n", prob)
}

package main

import (
	"fmt"
)

func check(value [26]int) bool {
	for i := 0; i < 26; i++ {
		if value[i] >= 2 {
			return false
		}
	}

	for i := 0; i < 26; i++ {
		if value[i] >= 1 {
			return true
		}
	}

	return false
}

func check0(value [5005][26]int, n int) bool {
	for i := 0; i < n; i++ {
		if check(value[i]) {
			return true
		}
	}

	return false
}

func main() {
	var s string
	fmt.Scanf("%s\n", &s)
	n := len(s)

	mapping := make([][][]int, 26)
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			x := s[i] - 'a'
			y := s[j] - 'a'
			z := (j - i + n) % n

			if mapping[x] == nil {
				mapping[x] = make([][]int, n)
			}
			if mapping[x][z] == nil {
				mapping[x][z] = make([]int, 26)
			}

			mapping[x][z][y]++
		}
	}

	ans := 0
	for i := 0; i < 26; i++ {
		if mapping[i] == nil {
			continue
		}

		best := 0
		for j := 0; j < n; j++ {
			probability := 0
			for k := 0; k < 26; k++ {
				if mapping[i][j][k] == 1 {
					probability++
				}
			}

			if best < probability {
				best = probability
			}
		}

		ans += best
	}

	fmt.Printf("%.9f\n", float64(ans)/float64(n))
}

package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	le := len(s)
	var cnt [26][5000][26]int
	for i := range s {
		for k := 0; k < le; k++ {
			cnt[s[i]-'a'][k][s[(i+k)%le]-'a']++
		}
	}
	sum := 0
	for first := range cnt {
		// tot := cnt[first][0][first]
		best := 0
		for pos := range s {
			uniq := 0
			for _, c := range cnt[first][pos] {
				if c == 1 {
					uniq++
				}
			}
			if best < uniq {
				best = uniq
			}
		}
		sum += best
	}
	fmt.Println(float64(sum) / float64(le))
}


package main

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

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

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

	a := make([]int64, n)
	left := int64(0)
	for i := range a {
		fmt.Fscan(in, &a[i])
		left += a[i]
	}

	counter := int64(0)
	used := int64(0)
	for i := n - 1; i >= 0; i-- {
		if (left - used) / 3 > a[i] / 2 {
			left -= a[i]
			counter += a[i] / 2
			used += a[i] / 2 * 3 - a[i]
			if used < 0 {
				used = 0
			}
		} else {
			counter += (left - used) / 3
			break
		}
	}

	fmt.Println(counter)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1119E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, left int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	ans := int64(0)
	for _, v := range a {
		if left > 0 {
			if v > 2*left {
				ans += int64(left)
				v -= 2 * left
				left = 0
			} else {
				ans += int64(v / 2)
				left -= v / 2
				v %= 2
			}
		}
		ans += int64(v / 3)
		left += v % 3
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	var n, left int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	ans := int64(0)
	for _, v := range a {
		if left > 0 {
			if v > 2*left {
				ans += int64(left)
				v -= 2 * left
				left = 0
			} else {
				ans += int64(v / 2)
				left -= v / 2
				v %= 2
			}
		}
		ans += int64(v / 3)
		left += v % 3
	}
	Print(ans)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	var n, v, left int
	ans := int64(0)
	for Fscan(in, &n); n > 0; n-- {
		Fscan(in, &v)
		if left > 0 {
			if v > 2*left {
				ans += int64(left)
				v -= 2 * left
				left = 0
			} else {
				ans += int64(v / 2)
				left -= v / 2
				v %= 2
			}
		}
		ans += int64(v / 3)
		left += v % 3
	}
	Print(ans)
}

package main

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

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

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

	var n int64
	fmt.Fscanln(in, &n)

	a := make([]int64, n)
	left := int64(0)
	for i := range a {
		fmt.Fscan(in, &a[i])
		left += a[i]
	}

	used := int64(0)
	counter := int64(0)
	for i := n - 1; i >= 0; i-- {
		if (left - used) / 3 > a[i] / 2 {
			triangles := a[i] / 2
			left -= a[i]

			used += triangles * 3 - a[i]
			if used < 0 {
				left += used
				used = 0
			}
			counter += triangles
		} else {
			triangles := (left - used) / 3
			counter += triangles
			break
		}
	}

	fmt.Println(counter)
}

package main

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

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

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

	var n int64
	fmt.Fscanln(in, &n)

	a := make([]int64, n)
	left := int64(0)
	for i := range a {
		fmt.Fscan(in, &a[i])
		left += a[i]
	}

	use := int64(0)
	counter := int64(0)
	for i := n - 1; i >= 0; i-- {
		triangles := min((left - use) / 3, a[i] / 2)
		left -= a[i]
		counter += triangles

		use += triangles * 3 - a[i]
		if left - use < 3 {
			break
		}
	}

	fmt.Println(counter)
}

package main

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

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

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

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

	var n int64
	fmt.Fscanln(in, &n)

	a := make([]int64, n)
	left := int64(0)
	for i := range a {
		fmt.Fscan(in, &a[i])
		left += a[i]
	}

	used := int64(0)
	counter := int64(0)
	for i := n - 1; i >= 0; i-- {
		triangles := min((left - used) / 3, a[i] / 2)
		left -= a[i]
		counter += triangles

		used += max(triangles * 3 - a[i], 0)
		if left - used < 3 {
			break
		}
	}

	fmt.Println(counter)
}

package main

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

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

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

	var n int64
	fmt.Fscanln(in, &n)

	a := make([]int64, n)
	left := int64(0)
	for i := range a {
		fmt.Fscan(in, &a[i])
		left += a[i]
	}

	use := int64(0)
	counter := int64(0)
	for i := n - 1; i >= 0; i-- {
		triangles := min((left - use) / 3, a[i] / 2)
		left -= a[i]
		counter += triangles

		use += triangles * 3 - a[i]

		if a[i] == 1 {
			if use == 0 {
				left--
			} else {
				use--
			}
		}
		if left < 3 {
			break
		}
	}

	fmt.Println(counter)
}

package main

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

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

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

	var n int64
	fmt.Fscanln(in, &n)

	a := make([]int64, n)
	left := int64(0)
	for i := range a {
		fmt.Fscan(in, &a[i])
		left += a[i]
	}

	used := int64(0)
	counter := int64(0)
	for i := n - 1; i >= 0; i-- {
		triangles := min((left - used) / 3, a[i] / 2)
		counter += triangles
		left -= a[i]

		if triangles * 3 > a[i] {
			used += triangles * 3 - a[i]
		}
		if left - used < 3 {
			break
		}
	}

	fmt.Println(counter)
}

package main

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

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

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

	var n int64
	fmt.Fscanln(in, &n)

	a := make([]int64, n)
	left := int64(0)
	for i := range a {
		fmt.Fscan(in, &a[i])
		left += a[i]
	}

	used := int64(0)
	counter := int64(0)
	/*for i := n - 1; i >= 0; i-- {
		triangles := min((left - used) / 3, a[i] / 2)
		counter += triangles
		left -= a[i]

		if triangles * 3 > a[i] {
			used += triangles * 3 - a[i]
		}
		//if left - used < 3 {
		//	break
		}
	}*/

	for i := n - 1; i >= 0; i-- {
		if left - used / 3 > a[i] / 2 {
			triangles := a[i] / 2
			left -= a[i]

			used += triangles * 3 - a[i]
			counter += triangles
		} else {
			triangles := (left - used) / 3
			counter += triangles
			break
		}
	}

	fmt.Println(counter)
}

package main

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

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

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

	var n int64
	fmt.Fscanln(in, &n)

	a := make([]int64, n)
	left := int64(0)
	for i := range a {
		fmt.Fscan(in, &a[i])
		left += a[i]
	}

	counter := int64(0)
	for i := n - 1; i >= 0; i-- {
		triangles := min(left / 3, a[i] / 2)
		left -= triangles * int64(3)
		counter += triangles

		if triangles == 0 && a[i] % 2 != 0 {
			left--
		}
		if left < 3 {
			break
		}
	}

	fmt.Println(counter)
}

package main

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

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

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

	var n int64
	fmt.Fscanln(in, &n)

	a := make([]int64, n)
	left := int64(0)
	for i := range a {
		fmt.Fscan(in, &a[i])
		left += a[i]
	}

	use := int64(0)
	counter := int64(0)
	for i := n - 1; i >= 0; i-- {
		triangles := min((left - use) / 3, a[i] / 2)
		left -= a[i]
		counter += triangles

		if left - use < 3 {
			break
		}
		use += triangles * 3 - a[i]
	}

	fmt.Println(counter)
}

package main

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

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

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

	var n int64
	fmt.Fscanln(in, &n)

	a := make([]int64, n)
	left := int64(0)
	for i := range a {
		fmt.Fscan(in, &a[i])
		left += a[i]
	}

	counter := int64(0)
	for i := n - 1; i >= 0; i-- {
		triangles := min(left / 3, a[i] / 2)
		left -= triangles * int64(3)
		counter += triangles

		if a[i] == 1 {
			left--
		}
		if left < 3 {
			break
		}
	}

	fmt.Println(counter)
}

package main

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

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

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

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

	a := make([]int, n)
	left := 0
	for i := range a {
		fmt.Fscan(in, &a[i])
		left += a[i]
	}

	counter := 0
	for i := n - 1; i >= 0; i-- {
		triangles := min(left / 3, a[i] / 2)
		left -= triangles * 3
		counter += triangles

		if triangles == 0 && a[i] % 2 != 0 {
			left--
		}
		if left < 3 {
			break
		}
	}

	fmt.Println(counter)
}

package main

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

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

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

	var n int64
	fmt.Fscanln(in, &n)

	a := make([]int64, n)
	left := int64(0)
	for i := range a {
		fmt.Fscan(in, &a[i])
		left += a[i]
	}

	used := int64(0)
	counter := int64(0)
	/*for i := n - 1; i >= 0; i-- {
		triangles := min((left - used) / 3, a[i] / 2)
		counter += triangles
		left -= a[i]

		if triangles * 3 > a[i] {
			used += triangles * 3 - a[i]
		}
		//if left - used < 3 {
		//	break
		}
	}*/

	for i := n - 1; i >= 0; i-- {
		if (left - used) / 3 > a[i] / 2 {
			triangles := a[i] / 2
			left -= a[i]

			used += triangles * 3 - a[i]
			counter += triangles
		} else {
			triangles := (left - used) / 3
			counter += triangles
			break
		}
	}

	fmt.Println(counter)
}

package main

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

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

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

	var n int64
	fmt.Fscanln(in, &n)

	a := make([]int64, n)
	left := int64(0)
	for i := range a {
		fmt.Fscan(in, &a[i])
		left += a[i]
	}

	used := int64(0)
	counter := int64(0)
	/*for i := n - 1; i >= 0; i-- {
		triangles := min((left - used) / 3, a[i] / 2)
		counter += triangles
		left -= a[i]

		if triangles * 3 > a[i] {
			used += triangles * 3 - a[i]
		}
		//if left - used < 3 {
		//	break
		}
	}*/

	for i := n - 1; i >= 0; i-- {
		if left - used / 3 > a[i] / 2 {
			triangles := a[i] / 2
			left -= a[i]

			used += triangles * 3 - a[i]
			if a[i] % 2 != 0 && used > 0 {
				used--
			}
			counter += triangles
		} else {
			triangles := (left - used) / 3
			counter += triangles
			break
		}
	}

	fmt.Println(counter)
}