Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.  Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.

Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).

NoteIn the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.

package main

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

func main() {
	defer out.Flush()
	n := in.NextInt()
	line := in.NextLine()
	dist := make([]int, n)
	for i := range dist {
		dist[i] = in.NextInt()
	}
	visited := make([]bool, n)
	pos := 0
	for !visited[pos] {
		visited[pos] = true
		sign := 1
		if line[pos] == '<' {
			sign = -1
		}
		pos += sign * dist[pos]
		if !(0 <= pos && pos < n) {
			fmt.Fprintln(out, "FINITE")
			return
		}
	}
	fmt.Fprintln(out, "INFINITE")
}

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

type FastReader struct {
	r   *bufio.Reader
	buf string
}

func NewFastReader(r io.Reader) *FastReader {
	return &FastReader{
		r: bufio.NewReader(r),
	}
}

func (r *FastReader) advance() {
	for len(r.buf) != 0 && r.buf[0] == ' ' {
		r.buf = r.buf[1:]
	}
	var err error
	for len(r.buf) == 0 && err != io.EOF {
		buf := new(bytes.Buffer)
		for {
			var chunk []byte
			var more bool
			chunk, more, err = r.r.ReadLine()
			buf.Write(chunk)
			if !more {
				break
			}
		}
		r.buf = buf.String()
	}
}

func (r *FastReader) NextLine() string {
	r.advance()
	line := r.buf
	r.buf = ""
	return line
}

func (r *FastReader) NextWord() string {
	r.advance()
	var word string
	wordStart := 0
	for i := 0; i < len(r.buf); i++ {
		b := r.buf[i]
		if b == ' ' {
			if i != wordStart {
				word = r.buf[wordStart:i]
				r.buf = r.buf[i:]
				break
			}
			wordStart = i + 1
		}
	}
	if len(word) == 0 {
		word = r.buf
		r.buf = ""
	}
	return word
}

func (r *FastReader) NextInt() int {
	return parseInt(r.NextWord())
}

func parseInt(word string) int {
	sign := 1
	if word[0] == '-' {
		sign = -1
		word = word[1:]
	}
	result := 0
	for i := 0; i < len(word); i++ {
		result = result*10 + int(word[i]) - '0'
	}
	result *= sign
	return result
}


Initially, you have the array $$$a$$$ consisting of one element $$$1$$$ ($$$a = [1]$$$).In one move, you can do one of the following things:  Increase some (single) element of $$$a$$$ by $$$1$$$ (choose some $$$i$$$ from $$$1$$$ to the current length of $$$a$$$ and increase $$$a_i$$$ by one);  Append the copy of some (single) element of $$$a$$$ to the end of the array (choose some $$$i$$$ from $$$1$$$ to the current length of $$$a$$$ and append $$$a_i$$$ to the end of the array). For example, consider the sequence of five moves:  You take the first element $$$a_1$$$, append its copy to the end of the array and get $$$a = [1, 1]$$$.  You take the first element $$$a_1$$$, increase it by $$$1$$$ and get $$$a = [2, 1]$$$.  You take the second element $$$a_2$$$, append its copy to the end of the array and get $$$a = [2, 1, 1]$$$.  You take the first element $$$a_1$$$, append its copy to the end of the array and get $$$a = [2, 1, 1, 2]$$$.  You take the fourth element $$$a_4$$$, increase it by $$$1$$$ and get $$$a = [2, 1, 1, 3]$$$. Your task is to find the minimum number of moves required to obtain the array with the sum at least $$$n$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the lower bound on the sum of the array.

For each test case, print the answer: the minimum number of moves required to obtain the array with the sum at least $$$n$$$.

package main

import (
	"fmt"
	"math"
)

func main() {
	// f, err := os.Open("input.txt")
	// if err != nil {
	// 	panic(err)
	// }
	// defer f.Close()

	// oldStdin := os.Stdin
	// defer func() { os.Stdin = oldStdin }()

	// os.Stdin = f

	// f2, err := os.Create("output.txt")
	// if err != nil {
	// 	panic(err)
	// }
	// defer f2.Close()

	// oldStdout := os.Stdout
	// defer func() { os.Stdout = oldStdout }()

	// os.Stdout = f2
	var n, number int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d\n", &number)
		solve(number)
	}
}

func solve(number int) {
	z := int(math.Sqrt(float64(number)))
	ans := 1e+9
	for i := z - 5; i <= z+5; i++ {
		if i < 1 || i > number {
			continue
		}
		ans = math.Min(ans, float64(i-1)+math.Ceil(float64((number-1)/i)))
	}
	fmt.Println(ans)
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

type block struct {
	a, b, c, d int
}

func solve() {
	n := nextInt()
	move := n
	for step := 1; step <= 50000; step++ {
		up := step - 1
		up += (n - step + step - 1) / step
		if move > up {
			move = up
		}
	}
	printf("%d\n", move)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)

	defer out.Flush()

	for t := nextInt(); t > 0; t-- {
		solve()
	}
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

func solve() {
	n := nextInt()
	move := n
	for step := 1; step <= 50000; step++ {
		up := step - 1
		up += (n - step + step - 1) / step
		if move > up {
			move = up
		}
	}
	printf("%d\n", move)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)

	defer out.Flush()

	for t := nextInt(); t > 0; t-- {
		solve()
	}
}

package main

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

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

	in := func() float64 {
		sc.Scan()
		i, _ := strconv.ParseFloat(sc.Text(), 10)
		return i
	}

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

		lowVal := math.Sqrt(n)
		lowVal = math.Floor(lowVal)

		otherVal := math.Ceil(n / lowVal)

		fmt.Println(int(lowVal + otherVal) - 2)

	}
}

package main

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

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

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

func solve() {
	var n int
	scanf("%d\n", &n)
	var x int
	x = int(math.Sqrt(float64(n)))
	var ans int
	//printf("x = %d\n", x)
	ans = x - 2 + int((n + x - 1) / x)
	printf("%d\n", ans)

}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		fmt.Println(solve(ReadInt64()))
	}
}

func solve(n int64) int64 {
	min := int64(1 << 60)
	for i := int64(1); i*i <= n; i++ {
		j := (n + i - 1) / i
		v := (i - 1) + (j - 1)
		if v < min {
			min = v
		}
	}
	return min
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) []int64 {
	v := make([]int64, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

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

// ==================== 以上是模版 ====================
func getIn() *bufio.Reader {
	/*
		outputCopy
		0
		3
		11
		72
		63244
	*/
	x := `
	5
	1
	5
	42
	1337
	1000000000
`
	return bufio.NewReaderSize(strings.NewReader(x), 8192)
}

func solve() {
	n := nextInt()

	min := 10000000
	for i := 1; i*i <= n; i++ {
		min = Min(min, i-1+ (n+i-1)/i -1)
	}

	printf("%d\n", min)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	//in = getIn()

	out = bufio.NewWriterSize(os.Stdout, 8192)
	defer out.Flush()
	for t := nextInt(); t > 0; t-- {
		solve()
	}
}

package main

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

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

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		Fprintln(out, sort.Search(63244, func(k int) bool { x := k / 2; return (1+x)*(1+k-x) >= n || (2+x)*(k-x) >= n }))
	}
}

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

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)
var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

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

func main() {
	defer w.Flush()
	var q int
	scan(&q)
	for ; q > 0; q-- {
		var n int
		scan(&n)
		var min = n
		for i := int(math.Sqrt(float64(n)))-6; i < int(math.Sqrt(float64(n)))+6; i++  {
			if i > 0 {
			var a = n/i+i-2
			if n%i != 0 {a++}
			if min > a {min = a}
			}
		}
		print(min,"\n")
	}
}

package main

import "fmt"

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

	for i := 0; i < t; i++ {
		var n int
		fmt.Scanf("%d\n", &n)
		mx := 1
		res := 1000000000
		for ; mx <= n && mx < 40000; mx++ {
			cost := mx - 1 + (n-mx+mx-1)/mx
			if cost < res {
				res = cost
			}
		}

		fmt.Printf("%d\n", res)
	}
}

package main

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

func sqrt(n int) int {
	if n == 0 {
		return 0
	}
	curr := n
	prev := n - 4
	tprev := prev - 9
	for prev != curr {
		tprev = prev
		prev = curr
		curr = (prev + (n / prev)) / 2
		if (tprev == curr) && ((curr-prev) == 1 || (prev-curr) == 1) {
			if prev < curr {
				return prev
			}
			return curr
		}
	}
	return curr
}

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

func main() {
	defer writer.Flush()
	var testCaseNum int
	fmt.Fscan(reader, &testCaseNum)

	for testCase := 0; testCase < testCaseNum; testCase++ {
		var n int
		fmt.Fscan(reader, &n)
		sq := sqrt(n)
		div, mod := n/sq, n%sq
		if mod == 0 {
			fmt.Fprintln(writer, sq+div-2)
		} else {
			fmt.Fprintln(writer, sq+div-1)
		}
	}
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

func solve() {
	n := nextInt()
	move := n
	for step := 1; step <= 50000; step++ {
		up := step - 1
		up += (n - step + step - 1) / step
		if move > up {
			move = up
		}
	}
	printf("%d\n", move)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)

	defer out.Flush()

	for t := nextInt(); t > 0; t-- {
		go solve()
	}
}

package main

import "fmt"

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

	for i := 0; i < t; i++ {
		var n int
		fmt.Scanf("%d", &n)
		mx := 1
		res := 1000000000
		for ; mx <= n && mx < 40000; mx++ {
			cost := mx - 1 + (n-mx+mx-1)/mx
			if cost < res {
				res = cost
			}
		}

		fmt.Printf("%d\n", res)
	}
}


There are $$$n$$$ candies put from left to right on a table. The candies are numbered from left to right. The $$$i$$$-th candy has weight $$$w_i$$$. Alice and Bob eat candies. Alice can eat any number of candies from the left (she can't skip candies, she eats them in a row). Bob can eat any number of candies from the right (he can't skip candies, he eats them in a row). Of course, if Alice ate a candy, Bob can't eat it (and vice versa).They want to be fair. Their goal is to eat the same total weight of candies. What is the most number of candies they can eat in total?

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 2\cdot10^5$$$) — the number of candies on the table. The second line of each test case contains $$$n$$$ integers $$$w_1, w_2, \dots, w_n$$$ ($$$1 \leq w_i \leq 10^4$$$) — the weights of candies from left to right. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$.

For each test case, print a single integer — the maximum number of candies Alice and Bob can eat in total while satisfying the condition.

NoteFor the first test case, Alice will eat one candy from the left and Bob will eat one candy from the right. There is no better way for them to eat the same total amount of weight. The answer is $$$2$$$ because they eat two candies in total.For the second test case, Alice will eat the first three candies from the left (with total weight $$$7$$$) and Bob will eat the first three candies from the right (with total weight $$$7$$$). They cannot eat more candies since all the candies have been eaten, so the answer is $$$6$$$ (because they eat six candies in total).For the third test case, there is no way Alice and Bob will eat the same non-zero weight so the answer is $$$0$$$.For the fourth test case, Alice will eat candies with weights $$$[7, 3, 20]$$$ and Bob will eat candies with weights $$$[10, 8, 11, 1]$$$, they each eat $$$30$$$ weight. There is no better partition so the answer is $$$7$$$.

package main

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

func main() {
	// START WRITING YOUR SOLUTION HERE:
	// writeLine(typeOf(readInt()))
	t := readInt()
	for j := 0; j < t; j++ {
		n := readInt()
		arr := readInts()
		l, r := 0, n-1
		sum_l, sum_r := arr[l], arr[r]
		cnt := 0
		for l < r {
			if sum_l == sum_r {
				cnt = int(math.Max(float64(cnt), float64(l+1+n-r)))

			}
			if sum_l <= sum_r {
				l++
				sum_l += arr[l]
			} else {
				r--
				sum_r += arr[r]
			}
		}
		writeLine(cnt)
	}
}

/* ~~~~~~~~~~ */
/* ~~~~~~~~~~ */
/* ~~~~~~~~~~ */

var in = bufio.NewReader(os.Stdin)

type float = float32
type double = float64
type long = int64
type ulong = uint64

func typeOf(arg interface{}) string {
	switch reflect.TypeOf(arg).Kind() {
	case reflect.Int:
		return "int"
	case reflect.Int8:
		return "int8"
	case reflect.Int16:
		return "int16"
	case reflect.Int32:
		return "int32"
	case reflect.Int64:
		return "int64"
	case reflect.Uint:
		return "uint"
	case reflect.Uint8:
		return "uint8"
	case reflect.Uint16:
		return "uint16"
	case reflect.Uint32:
		return "uint32"
	case reflect.Uint64:
		return "uint64"
	case reflect.Float32:
		return "float32"
	case reflect.Float64:
		return "float64"
	case reflect.Complex64:
		return "complex64"
	case reflect.Complex128:
		return "complex128"
	case reflect.Bool:
		return "bool"
	case reflect.String:
		return "string"
	case reflect.Chan:
		return "chan"
	case reflect.Ptr:
		return "ptr"
	case reflect.Uintptr:
		return "uintptr"
	case reflect.UnsafePointer:
		return "unsafeptr"
	case reflect.Interface:
		return "interface"
	case reflect.Array:
		return "array"
	case reflect.Slice:
		return "slice"
	case reflect.Map:
		return "map"
	case reflect.Struct:
		return "struct"
	case reflect.Func:
		return "func"
	case reflect.Invalid:
		return "invalid"
	default:
		return "nil"
	}
}

/* ~~~~~~~~~~ */

func _scln() string {
	ln, _ := in.ReadString('\n')
	return strings.Trim(ln, " \r\n")
}
func _sc(s []string) string {
	if len(s) == 0 {
		return _scln()
	}
	return s[0]
}

func readLine() string              { return _scln() }
func readString() string            { return _scln() }
func readStrings() []string         { return strings.Split(_scln(), " ") }
func readBool(s ...string) bool     { t, _ := strconv.ParseBool(_sc(s)); return t }
func readByte(s ...string) byte     { t, _ := strconv.ParseUint(_sc(s), 10, 8); return byte(t) }
func readDouble(s ...string) double { t, _ := strconv.ParseFloat(_sc(s), 64); return t }
func readFloat(s ...string) float   { t, _ := strconv.ParseFloat(_sc(s), 32); return float32(t) }
func readInt(s ...string) int       { t, _ := strconv.Atoi(_sc(s)); return t }
func readLong(s ...string) long     { t, _ := strconv.ParseInt(_sc(s), 10, 64); return t }
func readULong(s ...string) ulong   { t, _ := strconv.ParseUint(_sc(s), 10, 64); return t }

/* ~~~~~~~~~~ */

// Too much overhead with universal method using interface{}, wait for the generics,
// but for now — just don't look at the redundancy of the code after that commentary :)

func readBools() []bool {
	strs := readStrings()
	arr := make([]bool, len(strs))
	for i, s := range strs {
		arr[i] = readBool(s)
	}
	return arr
}
func readBytes() []byte {
	strs := readStrings()
	arr := make([]byte, len(strs))
	for i, s := range strs {
		arr[i] = readByte(s)
	}
	return arr
}
func readDoubles() []double {
	strs := readStrings()
	arr := make([]double, len(strs))
	for i, s := range strs {
		arr[i] = readDouble(s)
	}
	return arr
}
func readFloats() []float {
	strs := readStrings()
	arr := make([]float, len(strs))
	for i, s := range strs {
		arr[i] = readFloat(s)
	}
	return arr
}
func readInts() []int {
	strs := readStrings()
	arr := make([]int, len(strs))
	for i, s := range strs {
		arr[i] = readInt(s)
	}
	return arr
}
func readLongs() []long {
	strs := readStrings()
	arr := make([]long, len(strs))
	for i, s := range strs {
		arr[i] = readLong(s)
	}
	return arr
}
func readULongs() []ulong {
	strs := readStrings()
	arr := make([]ulong, len(strs))
	for i, s := range strs {
		arr[i] = readULong(s)
	}
	return arr
}

/* ~~~~~~~~~~ */

func write(arg ...interface{})                 { fmt.Print(arg...) }
func writeLine(arg ...interface{})             { fmt.Println(arg...) }
func writeFormat(f string, arg ...interface{}) { fmt.Printf(f, arg...) }

package main

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

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

func Scan(a ...interface{}) { fmt.Fscan(in, a...) }
func Scanln(s *string) {
	for *s, _ = in.ReadString('\n'); *s == "\n"; {
		*s, _ = in.ReadString('\n')
	}
	*s = (*s)[:len(*s)-1]
}
func Print(a ...interface{})                 { fmt.Fprint(out, a...) }
func Printf(format string, a ...interface{}) { fmt.Fprintf(out, format, a...) }
func Log(a ...interface{}) {
	pc, _, line, _ := runtime.Caller(1)
	fmt.Fprint(out, "log ", runtime.FuncForPC(pc).Name(), ":", line, " ")
	fmt.Fprint(out, a...)
	fmt.Fprint(out, "\n")
}

const N = 2e5 + 10

var (
	a, left, right [N]int
)

func solve() {
	var (
		n int
	)
	Scan(&n)
	for i := 1; i <= n; i++ {
		Scan(&a[i])
		left[i] = left[i-1] + a[i]
	}
	right[n+1] = 0
	for i := n; i >= 1; i-- {
		right[i] = right[i+1] + a[i]
	}

	ans := 0
	l, r := 1, n
	for l < r {
		if left[l] < right[r] {
			l++
		} else if left[l] > right[r] {
			r--
		} else {
			ans = l + (n - r + 1)
			l++
			r--
		}
	}
	Print(ans, "\n")
}

func main() {
	defer out.Flush()

	T := 1
	Scan(&T)
	for test := 0; test < T; test++ {
		solve()
	}
}

package main

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

func countEmojis(k, n int64) int64 {
  if n <= k {
    return (1 + n) * n / 2
  }
  return k * (k - 1) / 2 - (k - n - 1) * (3*k - n) / 2
}

func solve(sc *bufio.Scanner, wr *bufio.Writer) {
  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())
  w := make([]int, n)
  for i := range w {
    sc.Scan()
    w[i], _ = strconv.Atoi(sc.Text())
  }

  max := 0
  l, r := 0, 0
  lw, rw := 0, 0
  for l + r < n {
    if lw <= rw {
      if lw == rw {
        max = l + r
      }
      lw += w[l]
      l++
      continue
    }
    rw += w[n - r - 1]
    r++
  }

  if lw == rw {
    max = n
  }

  wr.WriteString(strconv.Itoa(max))
  wr.WriteRune('\n')
}

const once = false

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

  wr := bufio.NewWriter(os.Stdout)
  defer wr.Flush()

  if once {
    solve(sc, wr)
  } else {
    sc.Scan()
    times, _ := strconv.Atoi(sc.Text())
    for times > 0 {
      solve(sc, wr)
      times--
    }
  }
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	str, _ := reader.ReadString('\n')
	t, _ := strconv.ParseInt(strings.TrimSpace(str), 10, 32)
	tt := int(t)
	for i := 0; i < tt; i++ {
		solve(reader)
	}
}

func solve(reader *bufio.Reader) {
	n := ReadInteger(reader, '\n')
	var ns []int = []int{}
	for i := 0; i < n; i++ {
		var x int
		if i != n-1 {
			x = ReadInteger(reader, ' ')
		} else {
			x = ReadInteger(reader, '\n')
		}
		ns = append(ns, x)
	}
	st := make(map[int]int)
	cur := 0
	for i := 0; i < n; i++ {
		cur += ns[i]
		st[cur] = i + 1
	}
	cur = 0
	ans := 0
	for i := n - 1; i >= 0; i-- {
		cur += ns[i]
		if st[cur] != 0 && st[cur] < i+1 {
			ans = Max(ans, st[cur]+n-i)
		}
	}
	fmt.Println(ans)
}

func ReadInteger(reader *bufio.Reader, lst byte) int {
	str, _ := reader.ReadString(lst)
	n, _ := strconv.ParseInt(strings.TrimSpace(str), 10, 32)
	return int(n)
}

func ReadString(reader *bufio.Reader) string {
	str, _ := reader.ReadString('\n')
	return str
}

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

package main

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

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

	var T, n int
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &n)
		array := make([]int, n)
		sumMap := make(map[int]int, 0)
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &array[i])
			sum += array[i]
			sumMap[sum] = i
		}
		sum = 0
		ans := 0
		for i := n - 1; i > 0; i-- {
			sum += array[i]
			if prefix, ok := sumMap[sum]; ok && prefix < i {
				tmp := prefix + n - i + 1
				if tmp > ans {
					ans = tmp
				}
			}
		}
		fmt.Fprintln(out, ans)
	}
}

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

package main

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

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

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

		arr := make([]int, n)
		store := map[int]int{}
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
			sum += arr[i]
			store[sum] = i + 1
		}

		sum = 0
		ans := 0

		for i := n - 1; i >= 0; i-- {
			sum += arr[i]
			if val, ok := store[sum]; ok && n-i+val <= n {
				ans = int(math.Max(float64(ans), float64(n-i+val)))
			}
		}

		fmt.Fprintln(out, ans)
	}
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

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

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

func nextInt64() int64 {
	i, e := strconv.ParseInt(next(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	defer wr.Flush()
	sc.Buffer(make([]byte, 0), 1000000009)
	sc.Split(bufio.ScanWords)

	t := nextInt()
	for i := 0; i < t; i++ {
		solve()
	}
}

func solve() {
	n := nextInt()
	w := make([]int, n)

	for i := 0; i < n; i++ {
		w[i] = nextInt()
	}

	leftW := make([]int, n+1)
	rightW := make([]int, n+1)

	mp := make(map[int]int)
	for i := 0; i < n; i++ {
		if i-1 >= 0 {
			leftW[i] = leftW[i-1] + w[i]
		} else {
			leftW[i] = w[i]
		}
		mp[leftW[i]] = i + 1
	}

	ans := 0
	for i := n - 1; i >= 0; i-- {
		rightW[i] = rightW[i+1] + w[i]

		elem, ok := mp[rightW[i]]
		tmp := (n - i) + elem

		if ok {
			if tmp <= n && ans < tmp {
				ans = tmp
			}
		}
	}
	out(ans)
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func out(x ...interface{}) {
	fmt.Fprint(wr, x...)
}

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

func nextInt64() int64 {
	i, e := strconv.ParseInt(next(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	defer wr.Flush()
	sc.Buffer(make([]byte, 0), 1000000009)
	sc.Split(bufio.ScanWords)

	T := nextInt()
	for Case := 1; Case <= T; Case++ {
		solve()
	}
}

func solve() {
	n := nextInt()
	a:=make([]int,n,n)
	for i:=0;i<n;i++{
		a[i]=nextInt()
	}
	res:=0
	s1,s2:=a[0],a[n-1]
	for i,j:=0,n-1;i<j;{
		for(i<j&&s2<s1){
			j--
			s2+=a[j]
		}
		if(i<j&&s1==s2){
			if(i+1+n-j>res){
				res=i+1+n-j
			}
		}
		i++
		s1+=a[i]
	}
	fmt.Printf("%v\n", res)
}

package main

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

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

func main() {
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int64, n)

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

		total := 0
		leftSum := int64(arr[0])
		rightSum := int64(arr[n-1])
		left, right := 0, n-1

		for left < right {
			if leftSum == rightSum {
				if total < left+(n-right+1) {
					total = left + (n - right + 1)
				}
			}
			if leftSum <= rightSum {
				left++
				leftSum += arr[left]
			} else {
				right--
				rightSum += arr[right]
			}
		}
		fmt.Fprintln(out, total)
	}

}

package main

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

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

func main(){
    defer writer.Flush()

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

    for t := 1;t <= numTests; t++ {
        var n int
        fmt.Fscan(reader,&n)

        arr := make([]int,n + 1)
        suffSum := make([]int,n + 2)

        for i := 1; i <= n; i++ {
            fmt.Fscan(reader,&arr[i])
        }

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

        prefSum := 0
        ans := 0
        for i := 1; i < n; i++ {
            prefSum += arr[i]
            lo := i + 1
            hi := n
            pos := -1
            for lo <= hi {
                mid := int((lo + hi) / 2)
                if suffSum[mid] > prefSum {
                    lo = mid + 1
                } else if suffSum[mid] < prefSum {
                    hi = mid - 1
                } else {
                    pos = mid
                    break
                }
            }
            if pos != -1 {
                if ans < i + n - pos + 1 {
                    ans = i + n - pos + 1
                }
            }
        }

        fmt.Fprintf(writer,"%d\n",ans)
    }
}

// @Title
// @Description
// @Author
// @Update

package main

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

func fun(in *bufio.Reader) {
        n := 1
        fmt.Fscan(in, &n)
        arr := make([]int, n)
        l, r := 0, n-1
        for i := 0; i < n; i++ {
                fmt.Fscan(in, &arr[i])
        }
        tl, tr := 0, 0
        nl, nr := 0, 0
        for l <= r {
                if nl < nr {
                        nl += arr[l]
                        l++
                } else if nl > nr {
                        nr += arr[r]
                        r--
                } else if nl == nr {
                        tl, tr = l, r
                        nl += arr[l]
                        l++
                }
        }
        if nl == nr {
                fmt.Println(n)
        } else {
                fmt.Println(tl + n - 1 - tr)
        }
}

func main() {
        t := 1
        fmt.Scan(&t)
        in := bufio.NewReader(os.Stdin)
        for i := 1; i <= t; i++ {
                fun(in)
        }

        return
}

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

func solve(reader *bufio.Reader) {
    var n int
    fmt.Fscan(reader, &n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(reader, &a[i])
    }
    var l, r, sl, sr, ans int = 0, n - 1, 0, 0, 0
    for l <= r {
        if(sl < sr) {
            sl += a[l]
            l++
        } else {
            sr += a[r]
            r--
        }
        //fmt.Println(sl, sr, l, r)
        if(sl == sr) {
            ans = n - r + l - 1
        }
    }
    fmt.Println(ans)
}

func main() {
    reader := bufio.NewReader(os.Stdin)
    var tc int
    fmt.Scan(&tc)
    for i := 0; i < tc; i++ {
        solve(reader)
    }
}

package main

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

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

func CF1669F(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	t := 0
	Fscan(in, &t)
	for ; t > 0; t-- {
		ans := int64(0)
		n := 0
		Fscan(in, &n)
		w := make([]uint64, n)
		for i := range w {
			Fscan(in, &w[i])
		}
		pre, suf := make([]uint64, n), make([]uint64, n)
		pre[0], suf[n-1] = w[0], w[n-1]
		vis := make(map[uint64][]int)
		vis[w[n-1]] = append(vis[w[n-1]], n-1)
		for i := 1; i < n; i++ {
			pre[i] = pre[i-1] + w[i]
		}
		for i := n - 2; i >= 0; i-- {
			suf[i] = suf[i+1] + w[i]
			vis[suf[i]] = append(vis[suf[i]], i)
		}
		for i, v := range pre {
			if a, ok := vis[v]; ok {
				tmp := -1
				for j := len(a) - 1; j >= 0; j-- {
					if a[j] > i {
						tmp = a[j]
						break
					}
				}
				if tmp != -1 {
					ans = max(ans, int64(i)+1+int64(n)-int64(tmp))
				}
			}
		}
		Fprintln(out, ans)
	}
}

func max(i, j int64) int64 {
	if i > j {
		return i
	}
	return j
}

package main

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

const MOD int64 = 1000000007

var n int

var w []int

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

func (a ByV) Len() int           { return len(a) }
func (a ByV) Less(i, j int) bool { return a[i].v < a[j].v }
func (a ByV) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n)

		w = make([]int, n)

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

		solve()
	}
}

type pair struct {
	v int
	idx []int
}

//a b c d

//20 12 -- 4
//4  2  -- 4

func solve()  {

	i := 0
	j := n - 1

	alice := 0
	bob := 0

	tot := 0

	for ; i <= j; {
		if alice == bob {
			if alice != 0 {
				tot = i + n - j - 1
			}
			alice += w[i]
			i++

		} else {
			if alice > bob {
				bob += w[j]
				j --

			} else {
				alice += w[i]
				i++
			}
		}
	}

	if alice == bob {
		tot = n
	}

	fmt.Println(tot)
}

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

package main

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

func solve(cin *scanner, cout *writer, cerr *writer) {
	n := cin.NextInt()
	a := cin.NextInts(n)
	r := n
	var lo, hi int64
	var tmp int
	for l := 0; l < n; l++ {
		lo += int64(a[l])
		for l < r - 1 && lo > hi {
			r--
			hi += int64(a[r])
		}
		if lo == hi {
			tmp = n - r + l + 1
		}
	}
	cout.Println(tmp)
}

func main() {
	cin := NewScanner(os.Stdin)
	cout, cerr := NewWriter(os.Stdout), NewWriter(os.Stderr)
	defer cout.Flush()
	defer cerr.Flush()
	t := cin.NextInt()
	// t := 1
	for ti := 0; ti < t; ti++ {
		solve(cin, cout, cerr)
	}
}

// Template Bolierplate {{{
type scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 1024*1024)
	return &scanner{s}
}

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

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

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

func (i *scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(i.Next(), 10, 64)
	return v
}

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

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

type writer struct {
	w *bufio.Writer
}

func NewWriter(w io.Writer) *writer {
	return &writer{bufio.NewWriter(w)}
}

func (i *writer) Print(a ...interface{}) {
	fmt.Fprint(i.w, a...)
}

func (i *writer) Println(a ...interface{}) {
	fmt.Fprintln(i.w, a...)
}

func (i *writer) Printf(format string, a ...interface{}) {
	fmt.Fprintf(i.w, format, a...)
}

func (i *writer) Flush() {
	i.w.Flush()
}

// }}}

// vim: fdm=marker

package main

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

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

func solve() {
	var n int
	// s := ""
	scanf("%d\n", &n)

	arr := make([]int, n)
	// debug(s)
	for i := range arr {
		scanf("%d ", &arr[i])
	}
	scanf("\n")

	// mx := 0
	bob, left, alice, right := 0, 0, 0, n-1
	cntLeft, cntRight := 0, 0
	ansLeft, ansRight := 0, 0

	for left <= right {
		if alice > bob {
			bob += arr[right]
			right--
			cntRight++
		} else if bob > alice {
			alice += arr[left]
			left++
			cntLeft++
		} else {
			ansLeft = cntLeft
			ansRight = cntRight

			if left == right {
				break
			}

			alice += arr[left]
			left++
			cntLeft++
			bob += arr[right]
			right--
			cntRight++
		}
	}

	if alice != bob {
		printf("%d\n", ansRight+ansLeft)
	} else {
		printf("%d\n", cntRight+cntLeft)
	}

	// if cnt%2 != 0 {
	// 	printf("NO\n")
	// } else {
	// 	printf("YES\n")
	// }
}

func main() {
	defer writer.Flush()
	var cases int

	scanf("%d\n", &cases)
	// cases = 1

	for c := 0; c < cases; c++ {
		solve()
	}
}

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

func IntArray(size int) []int {
	arr := make([]int, size)
	for i := 0; i < size; i++ {
		scanf("%d", &arr[i])
	}
	scanf("\n")
	return arr
}

func Max(args ...int) int {
	m := args[0]
	for i := range args {
		if args[i] > m {
			m = args[i]
		}
	}
	return m
}

func Min(args ...int) int {
	m := args[0]
	for i := range args {
		if args[i] < m {
			m = args[i]
		}
	}
	return m
}

package main

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

/*

 */

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	w := make([]int, n)

	for i := range w {
		scanf("%d", &w[i])
	}
	scanf("\n")

	cnt := 0

	lftSum := 0
	lftCnt := 0

	rhtSum := 0
	rhtCnt := 0

	i, j := -1, n

	for i < j {
		if lftSum == 0 {
			i++
			lftSum += w[i]
			lftCnt++
		}

		if rhtSum == 0 {
			j--
			rhtSum += w[j]
			rhtCnt++
		}

		if i >= j {
			break
		}

		if lftSum == rhtSum {
			cnt += lftCnt + rhtCnt

			lftSum = 0
			lftCnt = 0

			rhtSum = 0
			rhtCnt = 0
		} else if lftSum < rhtSum {
			i++
			lftSum += w[i]
			lftCnt++
		} else {
			j--
			rhtSum += w[j]
			rhtCnt++
		}
	}

	fmt.Fprintln(writer, cnt)
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

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

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnhandledErrorResult
func factorize(num int) []int {
	factors := []int{1}

	sqrtA := int(math.Sqrt(float64(num)))

	for ftr := 2; ftr <= sqrtA; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > sqrtA {
		factors = append(factors, num)
	}

	return factors
}

package main

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

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

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

	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

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

		a := make([]int, n)
		a[0] = arr[0]
		for i := 1; i < n; i++ {
			a[i] = a[i-1] + arr[i]
		}

		b := make([]int, n)
		b[0] = arr[n-1]
		for i := 1; i < n; i++ {
			b[i] = b[i-1] + arr[n-i-1]
		}

		var x, y int
		var tot int
		for x+y+2 <= len(arr) {
			if a[x] == b[y] {
				tot = x + 1 + y + 1
				x++
				y++
			} else if a[x] < b[y] {
				x++
			} else {
				y++
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func isok(s string) bool {
	b := strings.Count(s, "B")
	rr := strings.Count(s, "R")
	if rr == 0 && b == 0 {
		return true
	} else if rr == 0 || b == 0 {
		return false
	} else {
		return true
	}
}

func slove() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	nums := make([]int, n)
	for i := range nums {
		fmt.Fscan(r, &nums[i])
	}
	i, j := 0, n
	l, r := 0, 0
	ans := 0
	for i=0;i<j;i++ {
		l += nums[i]
		for l > r && i < j - 1 {
			j--
			r += nums[j]
		}
		if l == r {
			ans = n - j + i + 1
		}
	}
	fmt.Fprintln(w, ans)
}

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

func main() {
	var n int
	fmt.Fscan(r, &n)
	for i:=0;i<n;i++ {
		slove()
	}
}

package main

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

func main_div4_784_F() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	sol = func() {
		var n int
		Fscan(in, &n)
		arr := make([]int, n)
		total := 0
		position := map[int]int{}
		for i := 0; i < n; i++ {
			Fscan(in, &arr[i])
			total += arr[i]
			position[total] = i
		}
		total = 0
		var ans int
		for i := n - 1; i >= 0; i-- {
			total += arr[i]
			if v, ok := position[total]; ok && v < i {
				if n-(i-v-1) > ans {
					ans = n - (i - v - 1)
				}
			}
		}
		Fprintln(out, ans)
	}
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_div4_784_F()
}

package main

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

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

	for ii := 0; ii < t; ii++ {
		var n int
		fmt.Fscan(in, &n)
		nums := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[i])
		}
		a, b := 0, 0
		ans := 0
		i := 0
		j := n - 1
		temp := 0
		for i <= j {
			if a == b {
				ans = temp
			}
			if a <= b {
				temp++
				a += nums[i]
				i++
			} else {
				temp++
				b += nums[j]
				j--
			}
			if a == b {
				ans = temp
			}
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

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

	solve := func(curCase int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sum := make([]int, n+1)
		cnt := map[int]int{}
		for i, v := range a {
			sum[i+1] = sum[i] + v
			cnt[sum[i+1]] = i+1
		}
		ans := 0
		s := 0
		for i := len(a) - 1; i >= 0; i-- {
			v := a[i]
			s+=v
			c,ok := cnt[s]
			if !ok {
				continue
			}
			c2 := n-i
			if c+ c2 <= n {
				ans = max(ans, c+c2)
			}
		}
		Fprintln(out, ans)
	}

	cases := 1
	Fscan(in, &cases)
	for curCase := 1; curCase <= cases; curCase++ {
		solve(curCase)
	}

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

}

func main() { run(os.Stdin, os.Stdout) }
func max(a, b int) int {
	if b > a {
		return b
	}
	return a
}


Let $$$x$$$ be an array of integers $$$x = [x_1, x_2, \dots, x_n]$$$. Let's define $$$B(x)$$$ as a minimal size of a partition of $$$x$$$ into subsegments such that all elements in each subsegment are equal. For example, $$$B([3, 3, 6, 1, 6, 6, 6]) = 4$$$ using next partition: $$$[3, 3\ |\ 6\ |\ 1\ |\ 6, 6, 6]$$$.Now you don't have any exact values of $$$x$$$, but you know that $$$x_i$$$ can be any integer value from $$$[l_i, r_i]$$$ ($$$l_i \le r_i$$$) uniformly at random. All $$$x_i$$$ are independent.Calculate expected value of $$$(B(x))^2$$$, or $$$E((B(x))^2)$$$. It's guaranteed that the expected value can be represented as rational fraction $$$\frac{P}{Q}$$$ where $$$(P, Q) = 1$$$, so print the value $$$P \cdot Q^{-1} \mod 10^9 + 7$$$.

The first line contains the single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the size of the array $$$x$$$. The second line contains $$$n$$$ integers $$$l_1, l_2, \dots, l_n$$$ ($$$1 \le l_i \le 10^9$$$). The third line contains $$$n$$$ integers $$$r_1, r_2, \dots, r_n$$$ ($$$l_i \le r_i \le 10^9$$$).

Print the single integer — $$$E((B(x))^2)$$$ as $$$P \cdot Q^{-1} \mod 10^9 + 7$$$.

package main

import (
	"bufio"
	"flag"
	"fmt"
	"io"
	"math"
	"math/big"
	"os"
)

var reader *bufio.Reader
var writer *bufio.Writer

var inputFile = flag.String("input", "", "")

func init() {
	flag.Parse()
	var i io.Reader
	if *inputFile != "" {
		i, _ = os.Open(*inputFile)
	} else {
		i = os.Stdin
	}
	reader = bufio.NewReaderSize(i, 1<<20)
	writer = bufio.NewWriterSize(os.Stdout, 1<<20)
}

func println(a ...interface{}) {
	_, _ = fmt.Fprintln(writer, a...)
}

func printf(format string, a ...interface{}) {
	_, _ = fmt.Fprintf(writer, format, a...)
}

func scanf(format string, a ...interface{}) {
	_, _ = fmt.Fscanf(reader, format, a...)
}

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

func NextInt64() int64 {
	var res int64
	scan(&res)
	return res
}

func NextInt() int {
	var res int
	scan(&res)
	return res
}

func NextIntArray(n int) []int {
	res := make([]int, n)
	for i := range res {
		scan(&res[i])
	}
	return res
}

func NextInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		scan(&res[i])
	}
	return res
}

func NextString() string {
	var res string
	scan(&res)
	return res
}

func NextBigInt() *big.Int {
	n := new(big.Int)
	n, _ = n.SetString(NextString(), 10)
	return n
}

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

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

func MaxInt64(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

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

type segment struct {
	l int64
	r int64
}

func newSegment() segment {
	return segment{
		l: math.MinInt64,
		r: math.MaxInt64,
	}
}

func intersect(a, b segment) segment {
	return segment{
		l: MaxInt64(a.l, b.l),
		r: MinInt64(a.r, b.r),
	}
}

func (s segment) len() int64 {
	if s.l >= s.r {
		return 0
	}
	return s.r - s.l
}

const MOD = 1000000007

func inv(a int64) int64 {
	res := int64(1)
	for a > 1 {
		res = res * (MOD - MOD / a) % MOD
		a = MOD % a
	}
	return res
}

func prob2(a, b segment) int64 {
	return intersect(a, b).len() * inv(a.len() * b.len() % MOD) % MOD
}

func prob3(a, b, c segment) int64 {
	return intersect(a, intersect(b, c)).len() * inv(a.len() * b.len() % MOD * c.len() % MOD) % MOD
}

func prob(a, b, c segment) int64 {
	return 1 - prob2(a, b) - prob2(b, c) + prob3(a, b, c)
}

func main() {
	defer writer.Flush()

	n := NextInt()
	a := make([]segment, n)
	for i := 0; i < n; i++ {
		a[i].l = NextInt64()
	}
	for i := 0; i < n; i++ {
		a[i].r = NextInt64() + 1
	}

	probs := make([]int64, n)

	s := int64(1)
	probs[0] = 1
	for i := 1; i < n; i++ {
		probs[i] = 1 - prob2(a[i - 1], a[i])
		s += probs[i]
		s %= MOD
	}

	answer := int64(0)
	for i := 0; i < n; i++ {
		s2 := s - probs[i] + 1
		if i > 0 {
			s2 -= probs[i - 1]
			if i > 1 {
				answer += prob(a[i - 2], a[i - 1], a[i])
			} else {
				answer += probs[i]
			}
		}

		if i + 1 < n {
			s2 -= probs[i + 1]
			if i > 0 {
				answer += prob(a[i-1], a[i], a[i+1])
			} else {
				answer += probs[i + 1]
			}
		}

		answer += s2 * probs[i]
		answer %= MOD
	}

	if answer < 0 {
		answer += MOD
	}

	println(answer)
}


When Sasha was studying in the seventh grade, he started listening to music a lot. In order to evaluate which songs he likes more, he introduced the notion of the song's prettiness. The title of the song is a word consisting of uppercase Latin letters. The prettiness of the song is the prettiness of its title.Let's define the simple prettiness of a word as the ratio of the number of vowels in the word to the number of all letters in the word.Let's define the prettiness of a word as the sum of simple prettiness of all the substrings of the word.More formally, let's define the function vowel(c) which is equal to 1, if c is a vowel, and to 0 otherwise. Let si be the i-th character of string s, and si..j be the substring of word s, staring at the i-th character and ending at the j-th character (sisi + 1... sj, i ≤ j).Then the simple prettiness of s is defined by the formula:The prettiness of s equals Find the prettiness of the given song title.We assume that the vowels are I, E, A, O, U, Y.

The input contains a single string s (1 ≤ |s| ≤ 5·105) — the title of the song.

Print the prettiness of the song with the absolute or relative error of at most 10 - 6.

NoteIn the first sample all letters are vowels. The simple prettiness of each substring is 1. The word of length 7 has 28 substrings. So, the prettiness of the song equals to 28.


To stay woke and attentive during classes, Karen needs some coffee!  Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between li and ri degrees, inclusive, to achieve the optimal taste.Karen thinks that a temperature is admissible if at least k recipes recommend it.Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?

The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively. The next n lines describe the recipes. Specifically, the i-th line among these contains two integers li and ri (1 ≤ li ≤ ri ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between li and ri degrees, inclusive. The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.

For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.

NoteIn the first test case, Karen knows 3 recipes.  The first one recommends brewing the coffee between 91 and 94 degrees, inclusive.  The second one recommends brewing the coffee between 92 and 97 degrees, inclusive.  The third one recommends brewing the coffee between 97 and 99 degrees, inclusive. A temperature is admissible if at least 2 recipes recommend it.She asks 4 questions.In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.In the second test case, Karen knows 2 recipes.  The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree.  The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees. A temperature is admissible if at least 1 recipe recommends it.In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none.

// Codeforces My Practice
// author: Leonardone @ NEETSDKASU
package main

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

var red = bufio.NewScanner(os.Stdin)

func read(vs ...interface{}) {
	red.Scan()
	tx := strings.Split(red.Text(), " ")
	for i, v := range vs {
		switch x := v.(type) {
		case *int:
			*x, _ = strconv.Atoi(tx[i])
		}
	}
}

func main() {
	const MAX = 200002
	ls := make([]int, MAX)
	rs := make([]int, MAX)
	var n, k, q int
	read(&n, &k, &q)
	for i := 0; i < n; i++ {
		var l, r int
		read(&l, &r)
		ls[l]++
		rs[r]++
	}
	sums := make([]int, MAX)
	c := 0
	ink := false
	for i := 1; i < MAX; i++ {
		c += ls[i]
		if !ink && c >= k {
			ink = true
		}
		if ink {
			sums[i] = sums[i-1] + 1
		} else {
			sums[i] = sums[i-1]
		}
		c -= rs[i]
		if ink && c < k {
			ink = false
		}
	}
	for i := 0; i < q; i++ {
		var a, b int
		read(&a, &b)
		fmt.Println(sums[b] - sums[a-1])
	}
}

package main

import (
	"fmt"
	"os"
	"io"
	"bufio"
)
var input io.Reader

func main() {
	var n, k, q int
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &n, &k, &q)
	refs := make([]int, 200000 + 2)
	refs2 := make([]int, 200000 + 2)
	for i := 0; i < n; i++ {
		var l, r int
		fmt.Fscan(input, &l, &r)
		refs[l]++
		refs[r + 1]--
	}

	for i := 1; i < len(refs); i++ {
		refs[i] += refs[i - 1]
		if refs[i] >= k {
			refs2[i]++
		}
	}

	for i := 1; i < len(refs); i++ {
		refs2[i] += refs2[i - 1]
	}

	for i := 0; i < q; i++ {
		var l, r int
		fmt.Fscan(input, &l, &r)
		fmt.Println(refs2[r] - refs2[l - 1])
	}

}

package main

import (
	"fmt"
	"os"
	"io"
	"bufio"
)
var input io.Reader

func main() {
	var n, k, q int
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &n, &k, &q)
	refs := make([]int, 200000 + 2)
	refs2 := make([]int, 200000 + 2)
	for i := 0; i < n; i++ {
		var l, r int
		fmt.Fscan(input, &l, &r)
		refs[l]++
		refs[r + 1]--
	}

	for i := 1; i < len(refs); i++ {
		refs[i] += refs[i - 1]
		if refs[i] >= k {
			refs2[i]++
		}
		refs2[i] += refs2[i - 1]
	}

	for i := 0; i < q; i++ {
		var l, r int
		fmt.Fscan(input, &l, &r)
		fmt.Println(refs2[r] - refs2[l - 1])
	}

}

package main

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

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

	imos := make([]int, 200000+2)
	for i := 0; i < N; i++ {
		l, r := sc.NextInt(), sc.NextInt()
		imos[l]++
		imos[r+1]--
	}

	counts := make([]int, len(imos))
	s := 0
	count := 0
	for i := 0; i < len(counts); i++ {
		s += imos[i]
		if s >= K {
			count++
		}
		counts[i] = count
	}

	for i := 0; i < Q; i++ {
		a, b := sc.NextInt(), sc.NextInt()
		fmt.Println(counts[b] - counts[a-1])
	}

}

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

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

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

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

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

	return mp
}

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

package main

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

func lowerBound(src []int, tar int) int {
	index, l, r := -1, 0, len(src)-1
	for l <= r {
		mid := (l + r) / 2
		if src[mid] < tar {
			l = mid + 1
		} else {
			r = mid - 1
			index = mid
		}
	}
	return index
}

func upperBound(src []int, tar int) int {
	index, l, r := -1, 0, len(src)-1
	for l <= r {
		mid := (l + r) / 2
		if src[mid] <= tar {
			l = mid + 1
			index = mid
		} else {
			r = mid - 1
		}
	}
	return index
}

func main() {
	n, k, q := 0, 0, 0
	fmt.Scan(&n, &k, &q)
	l, r, count := make([]int, n), make([]int, n), make([]int, 200001)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	for i := 0; i < n; i++ {
		scanner.Scan()
		l[i], _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		r[i], _ = strconv.Atoi(scanner.Text())
	}
	sort.Ints(l)
	sort.Ints(r)
	for i := 1; i <= 200000; i++ {
		count[i] = count[i-1]
		lb := lowerBound(r, i)
		ub := upperBound(l, i)
		if (lb != -1) && (ub != -1) && ((ub - lb + 1) >= k) {
			count[i]++
		}
	}

	for i := 0; i < q; i++ {
		scanner.Scan()
		qL, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		qR, _ := strconv.Atoi(scanner.Text())
		fmt.Println(count[qR] - count[qL-1])
	}
}

package main

import (
	"fmt"
	"math"
	"sort"
)

type sortR [][2]int

func (r sortR) Less(i, j int) bool {
	if r[i][0] == r[j][0] {
		return r[i][1] < r[j][1]
	}
	return r[i][0] < r[j][0]
}
func (r sortR) Len() int      { return len(r) }
func (r sortR) Swap(i, j int) { r[i], r[j] = r[j], r[i] }

func main() {
	n, k, q := 0, 0, 0
	fmt.Scan(&n, &k, &q)
	r := make([][2]int, n)
	qL := make([][2]int, q)
	for i := 0; i < n; i++ {
		fmt.Scan(&r[i][0], &r[i][1])
	}
	sort.Sort(sortR(r))
	for i := 0; i < q; i++ {
		fmt.Scan(&qL[i][0], &qL[i][1])
	}

	qMap := map[int]bool{}
	for _, v := range qL {
		count := 0
		for i := v[0]; i <= v[1]; i++ {
			if res, ok := qMap[i]; ok == true {
				if res {
					count++
				}
				continue
			}
			upper, lower := 0, 0
			// Search the largest j that r[j][0] <= i
			l, h := 0, len(r)-1
			for l < h {
				mid := (l + h) / 2
				if r[mid][0] <= i {
					l = mid + 1
				} else {
					h = int(math.Max(float64(mid-1), float64(l)))
				}
			}
			if r[l][0] > i {
				l--
				if l < 0 {
					continue
				}
			}
			if (l < (len(r) - 1)) && (r[l+1][0] <= i) {
				l++
			}
			if l == 0 && (r[l][0] > i) {
				continue
			}
			upper = l

			// Search the smallest j that r[j][1] >= i
			l, h = 0, len(r)-1
			for l < h {
				mid := (l + h) / 2
				if r[mid][1] < i {
					l = mid + 1
				} else {
					h = int(math.Max(float64(mid-1), float64(l)))
				}
			}
			if r[l][1] < i {
				l++
				if l == len(r) {
					continue
				}
			}
			if (l > 0) && (r[l-1][1] >= i) {
				l--
			}
			if (l == (len(r) - 1)) && (r[l][1] < i) {
				continue
			}
			lower = l

			if (upper - lower + 1) >= k {
				count++
				qMap[i] = true
			} else {
				qMap[i] = false
			}
		}
		fmt.Println(count)
	}
}

package main

import (
	"fmt"
	"sort"
)

type sortR [][2]int

func (r sortR) Less(i, j int) bool {
	if r[i][0] == r[j][0] {
		return r[i][1] < r[j][1]
	}
	return r[i][0] < r[j][0]
}
func (r sortR) Len() int      { return len(r) }
func (r sortR) Swap(i, j int) { r[i], r[j] = r[j], r[i] }

func main() {
	n, k, q := 0, 0, 0
	fmt.Scan(&n, &k, &q)
	r := make([][2]int, n)
	qL := make([][2]int, q)
	for i := 0; i < n; i++ {
		fmt.Scan(&r[i][0], &r[i][1])
	}
	sort.Sort(sortR(r))
	for i := 0; i < q; i++ {
		fmt.Scan(&qL[i][0], &qL[i][1])
	}

	qMap := map[int]bool{}
	for _, v := range qL {
		count := 0
		for i := v[0]; i <= v[1]; i++ {
			if res, ok := qMap[i]; ok == true {
				if res {
					count++
				}
				continue
			}

			upper := -1
			// Search the largest j that r[j][0] <= i
			l, h := 0, len(r)-1
			for l <= h {
				mid := (l + h) / 2
				if r[mid][0] <= i {
					upper = mid
					l = mid + 1
				} else {
					h = mid - 1
				}
			}
			if upper == -1 {
				continue
			}

			lower := -1
			// Search the smallest j that r[j][1] >= i
			l, h = 0, len(r)-1
			for l <= h {
				mid := (l + h) / 2
				if r[mid][1] >= i {
					lower = mid
					h = mid - 1
				} else {
					l = mid + 1
				}
			}
			if lower == -1 {
				continue
			}

			qMap[i] = false
			if (upper - lower + 1) >= k {
				count++
				qMap[i] = true
			}
		}
		fmt.Println(count)
	}
}

package main

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

type sortR [][2]int

func (r sortR) Less(i, j int) bool {
	if r[i][0] == r[j][0] {
		return r[i][1] < r[j][1]
	}
	return r[i][0] < r[j][0]
}
func (r sortR) Len() int      { return len(r) }
func (r sortR) Swap(i, j int) { r[i], r[j] = r[j], r[i] }

func main() {
	n, k, q := 0, 0, 0
	fmt.Scan(&n, &k, &q)
	r := make([][2]int, n)
	qL := make([][2]int, q)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		scanner.Scan()
		r[i][0], _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		r[i][1], _ = strconv.Atoi(scanner.Text())
	}
	sort.Sort(sortR(r))
	for i := 0; i < q; i++ {
		scanner.Scan()
		qL[i][0], _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		qL[i][1], _ = strconv.Atoi(scanner.Text())
	}

	qMap := map[int]bool{}
	for _, v := range qL {
		count := 0
		for i := v[0]; i <= v[1]; i++ {
			if res, ok := qMap[i]; ok == true {
				if res {
					count++
				}
				continue
			}

			lower := -1
			// Search the smallest j that r[j][1] >= i
			l, h := 0, len(r)-1
			for l <= h {
				mid := (l + h) / 2
				if r[mid][1] >= i {
					lower = mid
					h = mid - 1
				} else {
					l = mid + 1
				}
			}
			if lower == -1 {
				continue
			}

			upper := -1
			// Search the largest j that r[j][0] <= i
			l, h = 0, len(r)-1
			for l <= h {
				mid := (l + h) / 2
				if r[mid][0] <= i {
					upper = mid
					l = mid + 1
				} else {
					h = mid - 1
				}
			}
			if upper == -1 {
				continue
			}

			qMap[i] = false
			if (upper - lower + 1) >= k {
				count++
				qMap[i] = true
			}
		}
		fmt.Println(count)
	}
}


Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours mi minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all n customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.

The first line contains a single integer n (1 ≤ n ≤ 105), that is the number of cafe visitors. Each of the following n lines has two space-separated integers hi and mi (0 ≤ hi ≤ 23; 0 ≤ mi ≤ 59), representing the time when the i-th person comes into the cafe.  Note that the time is given in the chronological order. All time is given within one 24-hour period.

Print a single integer — the minimum number of cashes, needed to serve all clients next day.

NoteIn the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.In the second sample all visitors will come in different times, so it will be enough one cash.

package main

import (
	"fmt"
)

func main() {
	var n, cur int
	lasth, lastm, max := -1, -1, 1
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var h, m int
		fmt.Scan(&h, &m)
		if h == lasth && m == lastm {
			cur++
			if cur > max {
				max = cur
			}
		} else {
			lasth, lastm, cur = h, m, 1
		}
	}
	fmt.Println(max)
}

package main

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

func main() {
    var reader = bufio.NewReader(os.Stdin)
    var n int
    fmt.Scanf("%d\n", &n)
    var m = map[string]int{}
    for i := 0; i < n; i++ {
        var line, _, _ = reader.ReadLine()
        m[string(line)]++
    }

    var ans = 0
    for _, v := range m {
        if v > ans { ans = v }
    }
    fmt.Print(ans)
}

package main

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

func main() {
    defer s.Flush()

	n := s.Next()

	m := make(map[string]int, 0)
	for i := 0; i < n; i++ {
		m[s.NextLine()]++
	}

	max := 0
	for _, v := range m {
		if max  < v {
			max = v
		}
	}
	s.Println(max)
}

var (
	s *InOut
)

func init() {
	s = NewInOut(os.Stdin, os.Stdout)
}

type InOut struct {
	*bufio.Reader
	*bufio.Writer
}

func NewInOut(r io.Reader, w io.Writer) *InOut {
	return &InOut{bufio.NewReader(r), bufio.NewWriter(w)}
}

// Get Next Integer
func (s *InOut) Next() (r int) {
	b, _ := s.ReadByte()
	p := 1
	for (b < '0' || '9' < b) && b != '-' {
		b, _ = s.ReadByte()
	}
	if b == '-' {
		p = -1
		b, _ = s.ReadByte()
	}
	for '0' <= b && b <= '9' {
		r = 10*r + int(b-'0')
		b, _ = s.ReadByte()
	}
	return r * p
}

func (s *InOut) NextInt64() (r int64) {
	b, _ := s.ReadByte()
	p := int64(1)
	for (b < '0' || '9' < b) && b != '-' {
		b, _ = s.ReadByte()
	}
	if b == '-' {
		p = -1
		b, _ = s.ReadByte()
	}
	for '0' <= b && b <= '9' {
		r = 10*r + int64(b-'0')
		b, _ = s.ReadByte()
	}
	return r * p
}

// Get Next Line String
func (s *InOut) NextLine() (r string) {
	b, _ := s.ReadByte()
	for b == '\n' {
		b, _ = s.ReadByte()
	}
	buf := make([]byte, 0)
	for ; b != '\n'; b, _ = s.ReadByte() {
		buf = append(buf, b)
	}
	return string(buf)
}

// Get Next String using delimiter whitespace
func (s *InOut) NextStr() (r string) {
    return string(s.NextBytes())
}

// Get Next String using delimiter whitespace
func (s *InOut) NextBytes() (r []byte) {
	b, _ := s.ReadByte()
	for b == '\n' || b == ' ' {
		b, _ = s.ReadByte()
	}
	buf := make([]byte, 0)
	for ; b != '\n' && b != ' '; b, _ = s.ReadByte() {
		buf = append(buf, b)
	}
	return buf
}

// Print Strings using the suitable way to change type
func (s *InOut) Print(os ...interface{}) {
	for _, o := range os {
		switch o.(type) {
		case byte:
			s.WriteByte(o.(byte))
		case string:
			s.WriteString(o.(string))
		case int:
			s.WriteString(strconv.Itoa(o.(int)))
		case int64:
			s.WriteString(strconv.FormatInt(o.(int64), 10))
		default:
			s.WriteString(fmt.Sprint(o))
		}
	}
}

// Print Strings using the suitable way to change type with new line
func (s *InOut) Println(os ...interface{}) {
	for _, o := range os {
		s.Print(o)
	}
	s.Print("\n")
}

// Print immediately with new line (for debug)
func (s *InOut) PrintlnNow(o interface{}) {
	fmt.Println(o)
}

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)
func main() {
	var n,a,b,aa,bb int
    	c,cash := 1,1
    	input := bufio.NewScanner(os.Stdin)
    	input.Split(bufio.ScanWords)
    	fmt.Scan(&n)

    	for i := 0; i < n; i++ {
        	if i==0 {
        		input.Scan();
        		aa, _ = strconv.Atoi(input.Text());
        		input.Scan();
        		bb, _ = strconv.Atoi(input.Text());
        	} else {
        		input.Scan();
        		a, _ = strconv.Atoi(input.Text());
        		input.Scan();
        		b, _ = strconv.Atoi(input.Text());
        		if (a==aa && b==bb) {
				c+=1
				if c>cash {
				cash = c
				}
			} else {c=1}
			aa = a
			bb = b
		}
	}
	fmt.Println(cash)
}

package main

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

func main() {
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	var n int
	max:=0
	cash:=1
	fmt.Scan(&n)
	h:=make([]int,n)
	m:=make([]int,n)
	for i:=0; i<n;i++{
		in.Scan();
        h[i], _ = strconv.Atoi(in.Text());
        in.Scan();
		m[i], _ = strconv.Atoi(in.Text());

		if i>0{
		if (h[i] == h[i-1])&&(m[i] == m[i-1]){
				cash+=1
		}else{
			cash= 1
		}
		}
		if cash > max{ max=cash}

	}
	fmt.Println(max)
}

package main

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

func main() {

	var (
		n, h, m, ph, pm, alen, maxlen int32
		olv                           *bufio.Reader
		ir                            *bufio.Writer
	)

	olv = bufio.NewReader(os.Stdin)
	ir = bufio.NewWriter(os.Stdout)

	fmt.Scan(&n)
	ph, pm = -1, -1
	maxlen, alen = 0, 0
	for ; n > 0; n-- {
		//		fmt.Fscanf(olv, "%d%d", &h, &m) // nem ugorja at az ure sorokat
		fmt.Fscan(olv, &h)
		fmt.Fscan(olv, &m)

		//		println(h, m)

		if h != ph || m != pm {
			if alen > maxlen {
				maxlen = alen
			}
			alen = 1
			ph, pm = h, m
		} else {
			alen++
		}

	}

	if alen > maxlen {
		maxlen = alen
	}

	fmt.Fprintln(ir, maxlen)
	ir.Flush()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    var n int
    fmt.Scan(&n)
    prev, cnt, ans := "", 0, 1
    for i := 0; i < n; i++ {
        for scanner.Scan() {
            if scanner.Text() != "" { break }
        }
        if scanner.Text() == prev {
            cnt++
        } else {
            if (ans < cnt) { ans = cnt }
            cnt = 1
            prev = scanner.Text()
        }
    }
    if (ans < cnt) { ans = cnt }
    fmt.Println(ans)
}

package main

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

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

    minutes := make([]int, 24*60, 24*60)
    bs := bufio.NewScanner(os.Stdin)
    bs.Split(bufio.ScanWords)
    for i := 0; i < n; i++ {
        bs.Scan()
        h, _ := strconv.Atoi(bs.Text())
        bs.Scan()
        m, _ := strconv.Atoi(bs.Text())
        minutes[h*60 + m]++
    }

    max := 0
    for i := 0; i < 24 * 60; i++ {
        if max < minutes[i] {
            max = minutes[i]
        }
    }

    fmt.Println(max)
}

package main

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

func main() {
    var reader = bufio.NewReader(os.Stdin)
    var n int
    fmt.Scanf("%d", &n)
    var m = map[string]int{}
    for i := 0; i < n; i++ {
        var line, _, _ = reader.ReadLine()
        m[string(line)]++
    }

    var ans = 0
    for _, v := range m {
        if v > ans { ans = v }
    }
    fmt.Print(ans)
}

package main

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

func main() {
    defer s.Flush()

	n := s.Next()

	set := NewStrSet()
	for i := 0; i < n; i++ {
		set.Add(s.NextLine())
	}
	s.Println(1 + n - set.Size())
}

var (
	s *InOut
)

func init() {
	s = NewInOut(os.Stdin, os.Stdout)
}

type InOut struct {
	*bufio.Reader
	*bufio.Writer
}

func NewInOut(r io.Reader, w io.Writer) *InOut {
	return &InOut{bufio.NewReader(r), bufio.NewWriter(w)}
}

// Get Next Integer
func (s *InOut) Next() (r int) {
	b, _ := s.ReadByte()
	p := 1
	for (b < '0' || '9' < b) && b != '-' {
		b, _ = s.ReadByte()
	}
	if b == '-' {
		p = -1
		b, _ = s.ReadByte()
	}
	for '0' <= b && b <= '9' {
		r = 10*r + int(b-'0')
		b, _ = s.ReadByte()
	}
	return r * p
}

func (s *InOut) NextInt64() (r int64) {
	b, _ := s.ReadByte()
	p := int64(1)
	for (b < '0' || '9' < b) && b != '-' {
		b, _ = s.ReadByte()
	}
	if b == '-' {
		p = -1
		b, _ = s.ReadByte()
	}
	for '0' <= b && b <= '9' {
		r = 10*r + int64(b-'0')
		b, _ = s.ReadByte()
	}
	return r * p
}

// Get Next Line String
func (s *InOut) NextLine() (r string) {
	b, _ := s.ReadByte()
	for b == '\n' {
		b, _ = s.ReadByte()
	}
	buf := make([]byte, 0)
	for ; b != '\n'; b, _ = s.ReadByte() {
		buf = append(buf, b)
	}
	return string(buf)
}

// Get Next String using delimiter whitespace
func (s *InOut) NextStr() (r string) {
    return string(s.NextBytes())
}

// Get Next String using delimiter whitespace
func (s *InOut) NextBytes() (r []byte) {
	b, _ := s.ReadByte()
	for b == '\n' || b == ' ' {
		b, _ = s.ReadByte()
	}
	buf := make([]byte, 0)
	for ; b != '\n' && b != ' '; b, _ = s.ReadByte() {
		buf = append(buf, b)
	}
	return buf
}

// Print Strings using the suitable way to change type
func (s *InOut) Print(os ...interface{}) {
	for _, o := range os {
		switch o.(type) {
		case byte:
			s.WriteByte(o.(byte))
		case string:
			s.WriteString(o.(string))
		case int:
			s.WriteString(strconv.Itoa(o.(int)))
		case int64:
			s.WriteString(strconv.FormatInt(o.(int64), 10))
		default:
			s.WriteString(fmt.Sprint(o))
		}
	}
}

// Print Strings using the suitable way to change type with new line
func (s *InOut) Println(os ...interface{}) {
	for _, o := range os {
		s.Print(o)
	}
	s.Print("\n")
}

// Print immediately with new line (for debug)
func (s *InOut) PrintlnNow(o interface{}) {
	fmt.Println(o)
}

// string set
type StrSet struct {
	set map[string]bool
}

func NewStrSet() *StrSet {
	return &StrSet{make(map[string]bool)}
}

func (set *StrSet) Add(i string) bool {
	_, found := set.set[i]
	set.set[i] = true
	return !found    //False if it existed already
}

func (set *StrSet) Contains(i string) bool {
	_, found := set.set[i]
	return found    //true if it existed already
}

func (set *StrSet) Remove(i string) {
	delete(set.set, i)
}

func (set *StrSet) Size() int {
	return len(set.set)
}

package main

import "fmt"

func main() {
	var n int
	cash:=1
	fmt.Scan(&n)
	h:=make([]int,n)
	m:=make([]int,n)
	for i:=0; i<n;i++{
		fmt.Scan(&h[i],&m[i])
		if i>0{
		if h[i] == h[i-1]{
			if (m[i] - m[i-1]) < 2{
				cash+=1
			}
		}
	}
	}
	fmt.Println(cash)
}

package main

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

func main() {
in := bufio.NewScanner(os.Stdin)
	var n int
	max:=0
	cash:=1
	fmt.Scan(&n)
	h:=make([]int,n)
	m:=make([]int,n)
	for i:=0; i<n;i++{
		in.Scan();
        h[i], _ = strconv.Atoi(in.Text());
        in.Scan();
		m[i], _ = strconv.Atoi(in.Text());
		if i>0{
		if cash > max{ max=cash}
		if (h[i] == h[i-1])&&(m[i] == m[i-1]){
				cash+=1
		}else{
			cash= 1
		}
			}
	}
	fmt.Println(max)
}

package main

import "fmt"

func main() {
	var n int
	max:=0
	cash:=1
	fmt.Scan(&n)
	h:=make([]int,n)
	m:=make([]int,n)
	for i:=0; i<n;i++{
		fmt.Scan(&h[i],&m[i])
		if i>0{
		if h[i] == h[i-1]{
			if m[i] == m[i-1]{
				cash+=1
			}
		}else{
			if cash > max{ max=cash}
			cash= 1
		}
	}
	}
	fmt.Println(max)
}

package main

import "fmt"

func main() {
	var n int
	cash:=1
	fmt.Scan(&n)
	h:=make([]int,n)
	m:=make([]int,n)
	for i:=0; i<n;i++{
		fmt.Scan(&h[i],&m[i])
		if i>0{
		if h[i] == h[i-1]{
			if m[i] == m[i-1]{
				cash+=1
			}
		}
	}
	}
	fmt.Println(cash)
}

package main

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

func main() {
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	var n int
	max:=0
	cash:=1
	fmt.Scan(&n)
	h:=make([]int,n)
	m:=make([]int,n)
	for i:=0; i<n;i++{
		in.Scan();
        h[i], _ = strconv.Atoi(in.Text());
        in.Scan();
		m[i], _ = strconv.Atoi(in.Text());

		if i>0{
		if (h[i] == h[i-1])&&(m[i] == m[i-1]){
				cash+=1
		}else{
			cash= 1
		}
		if cash > max{ max=cash}
			}

	}
	fmt.Println(max)
}

package main

import "fmt"

func main() {
	var n int
	max:=0
	cash:=1
	fmt.Scan(&n)
	h:=make([]int,n)
	m:=make([]int,n)
	for i:=0; i<n;i++{
		fmt.Scan(&h[i],&m[i])
		if i>0{
		if cash > max{ max=cash}
		if h[i] == h[i-1]{
			if m[i] == m[i-1]{
				cash+=1
			}
		}else{cash= 1}
	}
	}
	fmt.Println(max)
}

package main

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

func main() {
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	var n int
	max:=0
	cash:=1
	fmt.Scan(&n)
	h:=make([]int,n)
	m:=make([]int,n)
	for i:=0; i<n;i++{
		in.Scan();
        h[i], _ = strconv.Atoi(in.Text());
        in.Scan();
		m[i], _ = strconv.Atoi(in.Text());

		if i>0{
		if cash > max{ max=cash}
		if (h[i] == h[i-1])&&(m[i] == m[i-1]){
				cash+=1
		}else{
			cash= 1
		}
			}
	}
	fmt.Println(max)
}

package main

import "fmt"

func main() {
	var n int
	max:=0
	cash:=1
	fmt.Scan(&n)
	h:=make([]int,n)
	m:=make([]int,n)
	for i:=0; i<n;i++{
		fmt.Scan(&h[i],&m[i])
		if i>0{
		if h[i] == h[i-1]{
			if m[i] == m[i-1]{
				cash+=1
			}
			if cash > max{ max=cash}

		}else{
			if cash > max{ max=cash}
			cash= 1
		}
	}
	}
	fmt.Println(max)
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    var n int
    fmt.Scan(&n)
    prev, cnt, ans := "", 0, 1
    for i := 0; i < n; i++ {
        scanner.Scan()
        if scanner.Text() == prev {
            cnt++
        } else {
            if (ans < cnt) { ans = cnt }
            cnt = 1
            prev = scanner.Text()
        }
    }
    if (ans < cnt) { ans = cnt }
    fmt.Println(ans)
}

package main

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

func main() {
    r := bufio.NewReader(os.Stdin)
    var n int
    fmt.Scan(&n)
    prev, cnt, ans := "", 0, 1
    for i := 0; i < n; i++ {
        s, _ := r.ReadString('\n')
        if (s == prev) {
            cnt++
        } else {
            if (ans < cnt) { ans = cnt }
            cnt = 1
            prev = s
        }
    }
    if (ans < cnt) { ans = cnt }
    fmt.Println(ans)
}


The Hat is a game of speedy explanation/guessing words (similar to Alias). It's fun. Try it! In this problem, we are talking about a variant of the game when the players are sitting at the table and everyone plays individually (i.e. not teams, but individual gamers play).$$$n$$$ people gathered in a room with $$$m$$$ tables ($$$n \ge 2m$$$). They want to play the Hat $$$k$$$ times. Thus, $$$k$$$ games will be played at each table. Each player will play in $$$k$$$ games.To do this, they are distributed among the tables for each game. During each game, one player plays at exactly one table. A player can play at different tables.Players want to have the most "fair" schedule of games. For this reason, they are looking for a schedule (table distribution for each game) such that:  At any table in each game there are either $$$\lfloor\frac{n}{m}\rfloor$$$ people or $$$\lceil\frac{n}{m}\rceil$$$ people (that is, either $$$n/m$$$ rounded down, or $$$n/m$$$ rounded up). Different numbers of people can play different games at the same table. Let's calculate for each player the value $$$b_i$$$ — the number of times the $$$i$$$-th player played at a table with $$$\lceil\frac{n}{m}\rceil$$$ persons ($$$n/m$$$ rounded up). Any two values of $$$b_i$$$must differ by no more than $$$1$$$. In other words, for any two players $$$i$$$ and $$$j$$$, it must be true $$$|b_i - b_j| \le 1$$$. For example, if $$$n=5$$$, $$$m=2$$$ and $$$k=2$$$, then at the request of the first item either two players or three players should play at each table. Consider the following schedules:  First game: $$$1, 2, 3$$$ are played at the first table, and $$$4, 5$$$ at the second one. The second game: at the first table they play $$$5, 1$$$, and at the second  — $$$2, 3, 4$$$. This schedule is not "fair" since $$$b_2=2$$$ (the second player played twice at a big table) and $$$b_5=0$$$ (the fifth player did not play at a big table). First game: $$$1, 2, 3$$$ are played at the first table, and $$$4, 5$$$ at the second one. The second game: at the first table they play $$$4, 5, 2$$$, and at the second one  — $$$1, 3$$$. This schedule is "fair": $$$b=[1,2,1,1,1]$$$ (any two values of $$$b_i$$$ differ by no more than $$$1$$$). Find any "fair" game schedule for $$$n$$$ people if they play on the $$$m$$$ tables of $$$k$$$ games.

The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. Each test case consists of one line that contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2 \le n \le 2\cdot10^5$$$, $$$1 \le m \le \lfloor\frac{n}{2}\rfloor$$$, $$$1 \le k \le 10^5$$$) — the number of people, tables and games, respectively. It is guaranteed that the sum of $$$nk$$$ ($$$n$$$ multiplied by $$$k$$$) over all test cases does not exceed $$$2\cdot10^5$$$.

For each test case print a required schedule  — a sequence of $$$k$$$ blocks of $$$m$$$ lines. Each block corresponds to one game, a line in a block corresponds to one table. In each line print the number of players at the table and the indices of the players (numbers from $$$1$$$ to $$$n$$$) who should play at this table. If there are several required schedules, then output any of them. We can show that a valid solution always exists. You can output additional blank lines to separate responses to different sets of inputs.

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, m, k := 0, 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &m, &k)
		a := []int{}
		for j := 0; j < n; j++ {
			a = append(a, j+1)
		}
		for j := 0; j < k; j++ {
			index := 0
			for q := 0; q < m; q++ {
				sz := n / m
				if q < n%m {
					sz++
				}
				fmt.Fprint(w, sz)
				for t := 0; t < sz; t++ {
					fmt.Fprint(w, " ", a[index])
					index++
				}
				fmt.Fprintln(w, "")
			}
			a = append(a[(n%m)*((n+m-1)/m):], a[:(n%m)*((n+m-1)/m)]...)
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, m, k := 0, 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &m, &k)
		a := []int{}
		for j := 0; j < n; j++ {
			a = append(a, j+1)
		}
		fl, cl := int(math.Floor(float64(n)/float64(m))), int(math.Ceil(float64(n)/float64(m)))
		for j := 0; j < k; j++ {
			for o := 0; o < (n-fl)/m; o++ {
				fmt.Fprint(w, cl, " ")
				for e := 0; e < cl; e++ {
					fmt.Fprint(w, a[e], " ")
				}
				fmt.Fprintln(w, "")
				a = append(a[cl:], a[:cl]...)
			}
			fmt.Fprint(w, fl, " ")
			for e := 0; e < fl; e++ {
				fmt.Fprint(w, a[e], " ")
			}
			fmt.Fprintln(w, "")
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"math"
	"os"
)

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, m, k := 0, 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &m, &k)
		a := list.New()
		for j := 0; j < n; j++ {
			a.PushBack(j + 1)
		}
		fl, cl := int(math.Floor(float64(n)/float64(m))), int(math.Ceil(float64(n)/float64(m)))
		for j := 0; j < k; j++ {
			for o := 0; o < (n-fl)/m; o++ {
				fmt.Fprint(w, cl, " ")
				for e := 0; e < cl; e++ {
					v := a.Front()
					a.Remove(v)
					a.PushBack(v.Value.(int))
					fmt.Fprint(w, v.Value.(int), " ")
				}
				fmt.Fprintln(w, "")
			}
			fmt.Fprint(w, fl, " ")
			q := fl
			for e := a.Front(); q > 0; e = e.Next() {
				fmt.Fprint(w, e.Value.(int), " ")
				q--
			}
			fmt.Fprintln(w, "")
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"math"
	"os"
)

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, m, k := 0, 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &m, &k)
		a := list.New()
		for j := 0; j < n; j++ {
			a.PushBack(j + 1)
		}
		f, c := int(math.Floor(float64(n)/float64(m))), int(math.Ceil(float64(n)/float64(m)))
		for j := 0; j < k; j++ {
			for o := 0; o < (n-f)/m; o++ {
				fmt.Fprint(w, c, " ")
				for e := 0; e < c; e++ {
					v := a.Front()
					a.Remove(v)
					a.PushBack(v.Value.(int))
					fmt.Fprint(w, v.Value.(int), " ")
				}
				fmt.Fprintln(w, "")
			}
			fmt.Fprint(w, f, " ")
			q := f
			for e := a.Front(); q > 0; e = e.Next() {
				fmt.Fprint(w, e.Value.(int), " ")
				q--
			}
			fmt.Fprintln(w, "")
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"math"
	"os"
)

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, m, k := 0, 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &m, &k)
		a := list.New()
		for j := 0; j < n; j++ {
			a.PushBack(j + 1)
		}
		f, c := int(math.Floor(float64(n)/float64(m))), int(math.Ceil(float64(n)/float64(m)))
		for j := 0; j < k; j++ {
			for o := 0; o < (n-f)/m; o++ {
				fmt.Fprint(w, c, " ")
				for j := 0; j < c; j++ {
					v := a.Front()
					a.Remove(v)
					a.PushBack(v.Value.(int))
					fmt.Fprint(w, v.Value.(int), " ")
				}
				fmt.Fprintln(w, "")
			}
			fmt.Fprint(w, f, " ")
			q := f
			for e := a.Front(); q > 0; e = e.Next() {
				fmt.Fprint(w, e.Value.(int), " ")
				q--
			}
			fmt.Fprintln(w, "")
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"math"
	"os"
)

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, m, k := 0, 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &m, &k)
		a := list.New()
		for j := 0; j < n; j++ {
			a.PushBack(j + 1)
		}
		for j := 0; j < k; j++ {
			f, c := int(math.Floor(float64(n)/float64(m))), int(math.Ceil(float64(n)/float64(m)))
			for o := 0; o < (n-f)/m; o++ {
				fmt.Fprint(w, c, " ")
				for j := 0; j < c; j++ {
					v := a.Front()
					a.Remove(v)
					a.PushBack(v.Value.(int))
					fmt.Fprint(w, v.Value.(int), " ")
				}
				fmt.Fprintln(w, "")
			}
			fmt.Fprint(w, f, " ")
			q := a.Front()
			for j := 0; j < f; j++ {
				fmt.Fprint(w, q.Value.(int), " ")
				q = q.Next()
			}
			fmt.Fprintln(w, "")
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"math"
	"os"
)

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, m, k := 0, 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &m, &k)
		a := list.New()
		for j := 0; j < n; j++ {
			a.PushBack(j + 1)
		}
		for j := 0; j < k; j++ {
			f, c := int(math.Floor(float64(n)/float64(m))), int(math.Ceil(float64(n)/float64(m)))
			for o := 0; o < (n-f)/m; o++ {
				fmt.Fprint(w, c, " ")
				for j := 0; j < c; j++ {
					v := a.Front()
					a.Remove(v)
					a.PushBack(v.Value.(int))
					fmt.Fprint(w, v.Value.(int), " ")
				}
				fmt.Fprintln(w, "")
			}
			fmt.Fprint(w, f, " ")
			v := a.Front()
			for j := 0; j < f; j++ {
				fmt.Fprint(w, v.Value.(int), " ")
				v = v.Next()
			}
			fmt.Fprintln(w, "")
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}