// 350A-mic
package main

import (
    "fmt"
    "sort"
)

func main() {
    var n, m int
    fmt.Scan(&n, &m)
    a := make([]int, n)
    b := make([]int, m)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    for k := 0; k < m; k++ {
        fmt.Scan(&b[k])
    }
    sort.Sort(sort.IntSlice(a))
    sort.Sort(sort.IntSlice(b))
    for i := a[n-1]; i < b[0]; i++ {
        if 2*a[0] <= i {
            fmt.Println(i)
            return
        }
    }

    fmt.Println("-1")

}

package main
import (
    "fmt"
    //"unicode/utf8"
    //"strconv"
    "sort"
)

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

package main

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

func main() {
	var n, m int
	if _, err := fmt.Scanf("%d %d\n", &n, &m); err != nil {
		return
	}

	min_c := 0
	max_c := 0
	min_w := 0

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n && scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		if a > max_c {
			max_c = a
		}
		if a < min_c || min_c == 0 {
			min_c = a
		}
	}
	for i := 0; i < m && scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		if a < min_w || min_w == 0 {
			min_w = a
		}
	}

	v := -1
	for i := max_c; i < min_w; i++ {
		if 2*min_c <= i {
			v = i
			break
		}
	}

	fmt.Println(v)
}

package main

import "fmt"

func main() {
    var n,m,a int
    fmt.Scan(&n,&m)
    ac_min, ac_max := 101, 0
    for i := 0; i < n; i++ {
        fmt.Scan(&a)
        if ac_min > a { ac_min = a }
        if ac_max < a { ac_max = a }
    }
    wa_min := 101
    for i := 0; i < m; i++ {
        fmt.Scan(&a)
        if wa_min > a { wa_min = a }
    }
    ans := -1
    for v := ac_max; v < wa_min; v++ {
        if (2*ac_min) <= v {
            ans = v
            break
        }
    }
    fmt.Println(ans)
}

package main
import (
	"fmt"
	//"unicode/utf8"
	//"strconv"
	"sort"
)

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

package main
import (
	"fmt"
	//"unicode/utf8"
	//"strconv"
	"sort"
)

func main() {
	var n,m int
	fmt.Scan(&n,&m)
	c := make([]int,n)
	for i:=0;i<n;i++ {
		fmt.Scan(&c[i])
	}
	w := make([]int,m)
	for i:=0;i<m;i++ {
		fmt.Scan(&w[i])
	}
	sort.Ints(c)
	sort.Ints(w)
	m =2*c[0]
	if m<c[n-1] {
		m=c[n-1]
	}
	fmt.Println(m)
}


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


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


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

}

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


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", &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 (
    "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 (
	"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() {
	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"
)

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


package main

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

// github.com/EndlessCheng/codeforces-go
func CF1400B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int64) int64 {
		if a < b {
			return a
		}
		return b
	}

	var T, c, d, n, m, w, z int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &c, &d, &n, &m, &w, &z)
		if w > z {
			n, m, w, z = m, n, z, w
		}
		ans := int64(0)
		for i := int64(0); i <= n && i*w <= c; i++ {
			j := n - i
			if j*w > d {
				j = d / w
			}

			if s := i + j + min(m, (c-i*w)/z+(d-j*w)/z); s > ans {
				ans = s
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		p, f := readTwoNums(reader)
		cnts, cntw := readTwoNums(reader)
		s, w := readTwoNums(reader)
		res := solve(p, f, cnts, cntw, s, w)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

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 solve(p, f int, cnts int, cntw int, s, w int) int64 {
	// a * s + b * w <= p
	// c * s + d * w <= f
	// a + c <= cnts
	// b + d <= cntw
	// max a + b + c + d
	//if cnts > cntw {
	//	cnts, cntw = cntw, cnts
	//	s, w = w, s
	//}
	P := int64(p)
	F := int64(f)
	S := int64(s)
	W := int64(w)
	var best int64
	for a := 0; a <= cnts; a++ {
		A := int64(a)
		if A*S > P {
			break
		}
		B := min((P-A*S)/W, int64(cntw))
		var C, D int64
		if S <= W {
			C = min(int64(cnts)-A, F/S)
			D = min(int64(cntw)-B, (F-C*S)/W)
		} else {
			D = min(int64(cntw)-B, F/W)
			C = min(int64(cnts)-A, (F-D*W)/S)
		}

		if C < 0 || D < 0 || C*S+D*W > F {
			continue
		}

		if A+B+C+D > best {
			best = A + B + C + D
		}
	}
	return best
}

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

package main

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

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

	for t := io.NextInt(); t > 0; t-- {
		p, f := io.NextInt(), io.NextInt()
		cs, cw := io.NextInt(), io.NextInt()
		s, w := io.NextInt(), io.NextInt()
		if p < f {
			p, f = f, p
		}
		if s > w {
			s, w, cs, cw = w, s, cw, cs
		}

		ans := 0
		for pCarryS := min(cs, p/s); pCarryS >= 0; pCarryS-- {
			fCarryS := min(cs-pCarryS, f/s)
			pCarryW := min(cw, (p-pCarryS*s)/w)
			fCarryW := min(cw-pCarryW, (f-fCarryS*s)/w)
			ans = max(ans, pCarryS+pCarryW+fCarryS+fCarryW)
		}
		io.Println(ans)
	}
}

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

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

package main

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

func cost(s, w uint64, cs, cw, p, f uint64) uint64 {
	var x1, max uint64
	for x1 = 0; x1 <= cs; x1++ {
		if p >= s*x1 {
			y1 := (p - s*x1) / w

			if y1 > cw {
				y1 = cw
			}

			x2 := (cs - x1)

			if f < s*x2 {
				x2 = f / s
			}

			y2 := (f - s*x2) / w

			if y2 > (cw - y1) {
				y2 = (cw - y1)
			}

			if max < (x1 + y1 + x2 + y2) {
				max = (x1 + y1 + x2 + y2)
			}
		}
	}

	return max
}

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

	in := func() uint64 {
		sc.Scan()
		i, _ := strconv.ParseUint(sc.Text(), 10, 64)
		return i
	}

	for t := in(); t > 0; t-- {
		p, f := in(), in()

		cs, cw := in(), in()

		s, w := in(), in()

		val := make([]uint64, 4)

		val[1] = cost(s, w, cs, cw, p, f)
		val[2] = cost(s, w, cs, cw, f, p)
		val[3] = cost(w, s, cw, cs, f, p)
		val[0] = cost(w, s, cw, cs, p, f)

		max := val[0]

		for _, v := range val {
			if v > max {
				max = v
			}
		}

		fmt.Println(max)

	}

}

/*
URL:
https://codeforces.com/contest/1400/problem/B
*/

package main

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

var (
	t int

	p, f       int
	cntS, cntW int
	s, w       int
)

func main() {
	t = readi()
	for tc := 0; tc < t; tc++ {
		p, f = readi2()
		cntS, cntW = readi2()
		s, w = readi2()

		solve()
	}
}

func solve() {
	if p < f {
		p, f = f, p
	}

	if s > w {
		s, w = w, s
		cntS, cntW = cntW, cntS
	}

	tmp := p/s + f/s
	if tmp < cntS {
		fmt.Println(tmp)
		return
	}

	ans := Min(tmp, cntS)
	for i := 0; i <= cntS; i++ {
		P := i * s
		F := (cntS - i) * s

		if P > p || F > f {
			continue
		}

		rp := p - P
		rf := f - F

		plus := rp/w + rf/w
		ChMax(&ans, cntS+Min(cntW, plus))
		// PrintfDebug("%d\n", ans)
	}
	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
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

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

/********** common constants **********/

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	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
)

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

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

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

/*********** Input ***********/

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

// readi returns an integer.
func readi() int {
	return int(readInt64())
}
func readi2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func readi3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func readi4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return readInt64()
}
func readll2() (int64, int64) {
	return readInt64(), readInt64()
}
func readll3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

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

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

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

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

/*********** Output ***********/

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

	return res
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1400B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int64) int64 {
		if a < b {
			return a
		}
		return b
	}

	var T, c, d, n, m, v, w int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &c, &d, &n, &m, &v, &w)
		if v > w {
			n, m, v, w = m, n, w, v
		}
		ans := int64(0)
		for i := int64(0); i <= n && i*v <= c; i++ {
			j := min(n-i, d/v)
			if s := i + j + min(m, (c-i*v)/w+(d-j*v)/w); s > ans {
				ans = s
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var T, c, d, n, m, v, w int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &c, &d, &n, &m, &v, &w)
		if v > w {
			n, m, v, w = m, n, w, v
		}
		ans := 0
		for i := 0; i <= n && i*v <= c; i++ {
			j := min(n-i, d/v)
			if s := i + j + min(m, (c-i*v)/w+(d-j*v)/w); s > ans {
				ans = s
			}
		}
		Fprintln(out, ans)
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

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

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

	for i := 0; i < t; i++ {
		var p, f int
		fmt.Fscan(reader, &p, &f)

		var cnts, cntw int
		fmt.Fscan(reader, &cnts, &cntw)

		var s, w int
		fmt.Fscan(reader, &s, &w)

		if s > w {
			tmp := s
			s = w
			w = tmp

			tmp = cnts
			cnts = cntw
			cntw = tmp
		}

		ans := 0
		for s1 := 0; s1 <= min(cnts, (p/s)); s1++ {
			w1 := min(cntw, (p-s1*s)/w)
			s2 := min(cnts-s1, f/s)
			w2 := min(cntw-w1, (f-(s2*s))/w)
			ans = max(ans, s1+w1+s2+w2)
		}

		fmt.Println(ans)
	}
}

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

	return b
}

func max(el ...int) int {
	ans := MinInt
	for _, e := range el {
		if e > ans {
			ans = e
		}
	}

	return ans
}

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		p, f := readTwoNums(reader)
		cnts, cntw := readTwoNums(reader)
		s, w := readTwoNums(reader)
		res := solve(p, f, cnts, cntw, s, w)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

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 solve(p, f int, cnts int, cntw int, s, w int) int64 {
	// a * s + b * w <= p
	// c * s + d * w <= f
	// a + c <= cnts
	// b + d <= cntw
	// max a + b + c + d
	if cnts > cntw {
		cnts, cntw = cntw, cnts
		s, w = w, s
	}
	P := int64(p)
	F := int64(f)
	S := int64(s)
	W := int64(w)
	var best int64
	for a := 0; a <= cnts; a++ {
		A := int64(a)
		B := (P - A*S) / W
		if B < 0 {
			break
		}
		var C, D int64
		if S <= W {
			C = min(int64(cnts)-A, F/S)
			D = min(int64(cntw)-B, (F-C*S)/W)
		} else {
			D = min(int64(cntw)-B, F/W)
			C = min(int64(cnts)-A, (F-D*W)/S)
		}

		if A+B+C+D > best {
			best = A + B + C + D
		}
	}
	return best
}

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

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		p, f := readTwoNums(reader)
		cnts, cntw := readTwoNums(reader)
		s, w := readTwoNums(reader)
		res := solve(p, f, cnts, cntw, s, w)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

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 solve(p, f int, cnts int, cntw int, s, w int) int64 {
	// a * s + b * w <= p
	// c * s + d * w <= f
	// a + c <= cnts
	// b + d <= cntw
	// max a + b + c + d
	if cnts > cntw {
		cnts, cntw = cntw, cnts
		s, w = w, s
		p, f = f, p
	}
	P := int64(p)
	F := int64(f)
	S := int64(s)
	W := int64(w)
	var best int64
	for a := 0; a <= cnts; a++ {
		A := int64(a)
		B := (P - A*S) / W
		if B < 0 {
			break
		}
		var C, D int64
		if S <= W {
			C = min(int64(cnts)-A, F/S)
			D = min(int64(cntw)-B, (F-C*S)/W)
		} else {
			D = min(int64(cntw)-B, F/W)
			C = min(int64(cnts)-A, (F-D*W)/S)
		}

		if A+B+C+D > best {
			best = A + B + C + D
		}
	}
	return best
}

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

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		p, f := readTwoNums(reader)
		cnts, cntw := readTwoNums(reader)
		s, w := readTwoNums(reader)
		res := solve(p, f, cnts, cntw, s, w)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

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 solve(p, f int, cnts int, cntw int, s, w int) int64 {
	// a * s + b * w <= p
	// c * s + d * w <= f
	// a + c <= cnts
	// b + d <= cntw
	// max a + b + c + d
	//if cnts > cntw {
	//	cnts, cntw = cntw, cnts
	//	s, w = w, s
	//}
	P := int64(p)
	F := int64(f)
	S := int64(s)
	W := int64(w)
	var best int64
	for a := 0; a <= cnts; a++ {
		A := int64(a)
		if A*S > P {
			break
		}
		B := (P - A*S) / W
		var C, D int64
		if S <= W {
			C = min(int64(cnts)-A, F/S)
			D = min(int64(cntw)-B, (F-C*S)/W)
		} else {
			D = min(int64(cntw)-B, F/W)
			C = min(int64(cnts)-A, (F-D*W)/S)
		}

		if A+B+C+D > best {
			best = A + B + C + D
		}
	}
	return best
}

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

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		p, f := readTwoNums(reader)
		cnts, cntw := readTwoNums(reader)
		s, w := readTwoNums(reader)
		res := solve(p, f, cnts, cntw, s, w)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

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 solve(p, f int, cnts int, cntw int, s, w int) int64 {
	// a * s + b * w <= p
	// c * s + d * w <= f
	// a + c <= cnts
	// b + d <= cntw
	// max a + b + c + d
	//if cnts > cntw {
	//	cnts, cntw = cntw, cnts
	//	s, w = w, s
	//}
	P := int64(p)
	F := int64(f)
	S := int64(s)
	W := int64(w)
	var best int64
	for a := 0; a <= cnts; a++ {
		A := int64(a)
		if A*S > P {
			break
		}
		B := (P - A*S) / W
		var C, D int64
		if S <= W {
			C = min(int64(cnts)-A, F/S)
			D = min(int64(cntw)-B, (F-C*S)/W)
		} else {
			D = min(int64(cntw)-B, F/W)
			C = min(int64(cnts)-A, (F-D*W)/S)
		}

		if C < 0 || D < 0 {
			continue
		}

		if A+B+C+D > best {
			best = A + B + C + D
		}
	}
	return best
}

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

package main

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

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

	for t := io.NextInt(); t > 0; t-- {
		p, f := io.NextInt(), io.NextInt()
		cs, cw := io.NextInt(), io.NextInt()
		s, w := io.NextInt(), io.NextInt()
		if p < f {
			p, f = f, p
		}
		if s > w {
			s, w, cs, cw = w, s, cw, cs
		}

		ans := 0
		canCarry := p/s + f/s
		if canCarry <= cs {
			ans = canCarry
		} else {
			pCarry := min(cs, p/s)
			fCarry := cs - pCarry
			for ; pCarry >= 0; pCarry, fCarry = pCarry-1, fCarry+1 {
				pCarryW := min(cw, (p-pCarry*s)/w)
				fCarryW := min(cw-pCarryW, (f-fCarry*s)/w)
				ans = max(ans, pCarry+pCarryW+fCarry+fCarryW)
			}
		}
		io.Println(ans)
	}
}

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

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

package main

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

func cost(s, w uint64, cs, cw, p *uint64) uint64 {

	var i, max, x1, y1 uint64

	for i = 0; i <= *cs; i++ {
		if *p >= s*i {
			j := (*p - s*i) / w

			if j > *cw {
				j = *cw
			}

			v := i + j

			if v > max {
				x1 = i
				y1 = j
				max = v
			}
		} else {
			break
		}
	}

	*cs -= x1
	*cw -= y1

	// fmt.Println("--->", max, x1, y1)

	*p -= max

	return x1 + y1
}

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

	in := func() uint64 {
		sc.Scan()
		i, _ := strconv.ParseUint(sc.Text(), 10, 64)
		return i
	}

	for t := in(); t > 0; t-- {
		p, f := in(), in()

		cs, cw := in(), in()

		s, w := in(), in()

		cst := make([]uint64, 4)

		cs1, cw1 := cs, cw
		p1, f1 := p, f
		cst[0] = cost(s, w, &cs1, &cw1, &p1) +
			cost(s, w, &cs1, &cw1, &f1)

		cs1, cw1 = cs, cw
		p1, f1 = p, f
		cst[1] = cost(s, w, &cs1, &cw1, &f1) +
			cost(s, w, &cs1, &cw1, &p1)

		cs1, cw1 = cs, cw
		p1, f1 = p, f
		cst[2] = cost(w, s, &cw1, &cs1, &f1) +
			cost(w, s, &cw1, &cs1, &p1)

		cs1, cw1 = cs, cw
		p1, f1 = p, f
		cst[3] = cost(w, s, &cw1, &cs1, &p1) +
			cost(w, s, &cw1, &cs1, &f1)

		max := cst[0]

		for i := range cst {
			if max < cst[i] {
				max = cst[i]
			}
		}

		fmt.Println(max)
	}

}

package main

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

func cost(s, w uint64, cs, cw, p *uint64) uint64 {

	var i, max, x1, y1 uint64

	for i = 0; i <= *cs; i++ {
		if *p >= s*i {
			j := (*p - s*i) / w

			if j > *cw {
				j = *cw
			}

			v := i + j

			if v > max {
				x1 = i
				y1 = j
				max = v
			}
		} else {
			break
		}
	}

	*cs -= x1
	*cw -= y1

	//fmt.Println("--->", max, x1, y1)

	*p -= max

	return x1 + y1
}

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

	in := func() uint64 {
		sc.Scan()
		i, _ := strconv.ParseUint(sc.Text(), 10, 64)
		return i
	}

	for t := in(); t > 0; t-- {
		p, f := in(), in()

		cs, cw := in(), in()
		cs1, cw1 := cs, cw

		s, w := in(), in()

		cst1 := cost(s, w, &cs, &cw, &p) +
			cost(s, w, &cs, &cw, &f)

		cst2 := cost(s, w, &cs1, &cw1, &f) +
			cost(s, w, &cs1, &cw1, &p)

		if cst1 > cst2 {
			fmt.Println(cst1)
		} else {
			fmt.Println(cst2)
		}
	}

}

package main

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

func cost(s, w uint64, cs, cw, p, f uint64) uint64 {
	var x1, max uint64
	for x1 = 0; x1 <= cs; x1++ {
		if p >= s*x1 {
			y1 := (p - s*x1) / w

			if y1 > cw {
				y1 = cw
			}

			x2 := (cs - x1)

			if f < s*x2 {
				x2 = f / s
			}

			y2 := (f - s*x2) / w

			if y2 > (cw - y1) {
				y2 = (cw - y1)
			}

			if max < (x1 + y1 + x2 + y2) {
				max = (x1 + y1 + x2 + y2)
			}
		}
	}

	return max
}

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

	in := func() uint64 {
		sc.Scan()
		i, _ := strconv.ParseUint(sc.Text(), 10, 64)
		return i
	}

	for t := in(); t > 0; t-- {
		p, f := in(), in()

		cs, cw := in(), in()

		s, w := in(), in()

		val1 := cost(s, w, cs, cw, p, f)
		val2 := cost(s, w, cs, cw, f, p)

		if val1 > val2 {
			fmt.Println(val1)
		} else {
			fmt.Println(val2)
		}

	}

}


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

func main() {
	var n,m,i int
	var a [100005]int64
	fmt.Scan(&n)
	var r,w,h int64
	r=-1
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	out :=bufio.NewWriter(os.Stdout)
	for i=0;i<n; i++{
		input.Scan()
		aa,_:=strconv.ParseInt(input.Text(),0,64)
		a[i]=aa
	}
	input.Scan()
	bb,_:=strconv.Atoi(input.Text())
	m=bb

	for i=0;i<m;i++ {
		input.Scan()
		cc,_:=strconv.ParseInt(input.Text(),0,64)
		w=cc
		input.Scan()
		dd,_:=strconv.ParseInt(input.Text(),0,64)
		h=dd

		//fmt.Println(w,h)

		if a[w-1]>r {
			r=a[w-1]
		}
		out.WriteString(strconv.FormatInt(r,10)+"\n")
		r+=h
	}
	out.Flush()
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

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

	n := scanInt(scanner)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = int64(scanInt(scanner))
	}
	extraPos, extraHeight := -1, int64(-1)
	m := scanInt(scanner)
	for i := 0; i < m; i++ {
		pos := scanInt(scanner)-1
		height := int64(scanInt(scanner))
		base := extraHeight
		if pos > extraPos {
			base = a[pos]
		}
		writer.WriteString(fmt.Sprintf("%d\n", base))
		height += base
		extraHeight = height
		if height >= a[n-1] {
			extraPos = n-1
		} else {
			left, right := 0, n-1
			for left != right {
				mid := (left+right)/2
				if a[mid] > height {
					right = mid
				} else {
					left = mid+1
				}
			}
			extraPos = left-1
		}
	}
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

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

	n := scanInt(scanner)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = int64(scanInt(scanner))
	}
	extraHeight := int64(-1)
	m := scanInt(scanner)
	for i := 0; i < m; i++ {
		pos := scanInt(scanner)-1
		height := int64(scanInt(scanner))
		base := a[pos]
		if extraHeight > base {
			base = extraHeight
		}
		writer.WriteString(fmt.Sprintf("%d\n", base))
		extraHeight = height+base
	}
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

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

	n := scanInt(scanner)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt(scanner)
	}
	extraPos, extraHeight := -1, -1
	m := scanInt(scanner)
	for i := 0; i < m; i++ {
		pos := scanInt(scanner)-1
		height := scanInt(scanner)
		base := extraHeight
		if pos > extraPos {
			base = a[pos]
		}
		writer.WriteString(fmt.Sprintf("%d\n", base))
		height += base
		extraHeight = height
		if height >= a[n-1] {
			extraPos = n-1
		} else {
			left, right := 0, n-1
			for left != right {
				mid := (left+right)/2
				if a[mid] > height {
					right = mid
				} else {
					left = mid+1
				}
			}
			extraPos = left-1
		}
	}
}