There are $n$ candies put from left to right on a table. The candies are numbered from left to right. The $i$-th candy has weight $w_i$. Alice and Bob eat candies.

Alice can eat any number of candies from the left (she can't skip candies, she eats them in a row).

Bob can eat any number of candies from the right (he can't skip candies, he eats them in a row).

Of course, if Alice ate a candy, Bob can't eat it (and vice versa).

They want to be fair. Their goal is to eat the same total weight of candies. What is the most number of candies they can eat in total?


-----Input-----

The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases.

The first line of each test case contains an integer $n$ ($1 \leq n \leq 2\cdot10^5$) — the number of candies on the table.

The second line of each test case contains $n$ integers $w_1, w_2, \dots, w_n$ ($1 \leq w_i \leq 10^4$) — the weights of candies from left to right.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot10^5$.


-----Output-----

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


-----Examples-----

Input
4
3
10 20 10
6
2 1 4 2 4 1
5
1 2 4 8 16
9
7 3 20 5 15 1 11 8 10
Output
2
6
0
7


-----Note-----

For the first test case, Alice will eat one candy from the left and Bob will eat one candy from the right. There is no better way for them to eat the same total amount of weight. The answer is $2$ because they eat two candies in total.

For the second test case, Alice will eat the first three candies from the left (with total weight $7$) and Bob will eat the first three candies from the right (with total weight $7$). They cannot eat more candies since all the candies have been eaten, so the answer is $6$ (because they eat six candies in total).

For the third test case, there is no way Alice and Bob will eat the same non-zero weight so the answer is $0$.

For the fourth test case, Alice will eat candies with weights $[7, 3, 20]$ and Bob will eat candies with weights $[10, 8, 11, 1]$, they each eat $30$ weight. There is no better partition so the answer is $7$.

Source: codeforces | Difficulty: EASY
Tags: Sorting

Amortized analysis

Data structures

Greedy algorithms


Solutions:
from sys import stdin
from math import log, floor, ceil, gcd
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
input = stdin.readline
inp = lambda : int(stdin.readline())
rs = lambda : stdin.readline().strip()

def ra(typ):
	return list(map(typ, stdin.readline().split()))

def rv(typ):
	return map(typ, stdin.readline().split())

def main():
	for _ in range(inp()):
		n = inp()
		w = ra(int)
		a = 0
		b = n - 1
		(ans, pre, pos) = (0, w[0], w[n - 1])
		while a < b:
			if pre == pos:
				ans = a + 1 + (n - b)
			if pre <= pos:
				a += 1
				pre += w[a]
			else:
				b -= 1
				pos += w[b]
		print(ans)
main()


def eat_candies(n, weights):
	left = 0
	right = n - 1
	left_sum = 0
	right_sum = 0
	result = 0
	while left <= right:
		if left_sum < right_sum:
			left_sum += weights[left]
			left += 1
		elif left_sum > right_sum:
			right_sum += weights[right]
			right -= 1
		else:
			result = left + n - right - 1
			if left == right:
				break
			left_sum += weights[left]
			right_sum += weights[right]
			left += 1
			right -= 1
	if left_sum == right_sum:
		result = left + n - right - 1
	return result
t = int(input())
outputs = []
for i in range(t):
	n = int(input())
	weights = [int(c) for c in input().split(' ')]
	outputs.append(eat_candies(n, weights))
for o in outputs:
	print(o)


def solution(candies):
	n = len(candies)
	left = 0
	right = n - 1
	presum = 0
	subsum = 0
	candy_num = 0
	max_num = 0
	while left <= right:
		if presum <= subsum:
			presum += candies[left]
			left += 1
		else:
			subsum += candies[right]
			right -= 1
		candy_num += 1
		if presum == subsum:
			max_num = candy_num
	return max_num
test_cast_num = int(input())
candies = []
for _ in range(test_cast_num):
	input()
	candies.append(list(map(int, input().split())))
for candy in candies:
	print(solution(candy))


def solve(arr):
	if len(arr) < 2:
		return 0
	ans = 0
	count = 2
	left = 0
	right = len(arr) - 1
	balance = arr[right] - arr[left]
	if arr[left] - arr[right] == 0:
		ans = count
	while left != right - 1:
		count += 1
		if balance >= 0:
			left += 1
			balance -= arr[left]
		else:
			right -= 1
			balance += arr[right]
		if balance == 0:
			ans = count
	return ans
t = int(input())
cases = []
for i in range(t):
	input()
	cases.append(list(map(int, input().split(' '))))
ans = []
for case in cases:
	ans.append(solve(case))
for answer in ans:
	print(answer)


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	number = 2
	answer = 0
	candy = list(map(int, input().split()))
	left = 0
	leftSum = candy[left]
	right = n - 1
	rightSum = candy[right]
	while left < right:
		if leftSum == rightSum:
			answer = number
			right -= 1
			left += 1
			rightSum += candy[right]
			leftSum += candy[left]
			number += 2
		elif leftSum > rightSum:
			right -= 1
			rightSum += candy[right]
			number += 1
		elif rightSum > leftSum:
			left += 1
			leftSum += candy[left]
			number += 1
	print(answer)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	if n == 2:
		if a[0] == a[1]:
			print(2)
		else:
			print(0)
		return
	(index1, index2) = (0, 1)
	(w1, w2) = (a[0], a[-1])
	ans = 0
	while index1 + index2 < n:
		if w1 < w2:
			index1 += 1
			try:
				w1 += a[index1]
			except BaseException:
				break
		elif w1 > w2:
			index2 += 1
			try:
				w2 += a[-index2]
			except BaseException:
				break
		else:
			ans = index1 + index2 + 1
			index1 += 1
			index2 += 1
			try:
				w1 += a[index1]
				w2 += a[-index2]
			except BaseException:
				break
	print(ans)
for i in range(int(input())):
	main()


def solve(N, candies):
	half = sum(candies) // 2
	s = 0
	for j in range(N):
		s += candies[j]
		if s > half:
			break
	i = j - 1
	(wa, wb) = (sum(candies[:i + 1]), sum(candies[j:]))
	while wa != wb:
		if i == -1 or j == N:
			return 0
		if wa > wb:
			wa -= candies[i]
			i -= 1
		else:
			wb -= candies[j]
			j += 1
	return i + 1 + N - j
T = int(input())
for _ in range(T):
	N = int(input())
	candies = list(map(int, input().split()))
	print(solve(N, candies))


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	i = 0
	k = n - 1
	a = arr[0]
	b = arr[-1]
	ans = 0
	while i < k:
		if a == b:
			ans = i + 1 + (n - k)
		if a >= b:
			k -= 1
			b += arr[k]
		else:
			i += 1
			a += arr[i]
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	alice = 0
	alice_index = 0
	bob = 0
	bob_index = len(a) - 1
	ans = 0
	while alice_index <= bob_index:
		if alice <= bob:
			alice += a[alice_index]
			alice_index += 1
		else:
			bob += a[bob_index]
			bob_index -= 1
		if alice == bob:
			ans = alice_index + (len(a) - bob_index - 1)
	print(ans)


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	w = list(map(int, input().split()))
	(l, r) = (0, n - 1)
	(a, b) = (0, 0)
	ans = 0
	while l <= r:
		if a < b:
			a += w[l]
			l += 1
		else:
			b += w[r]
			r -= 1
		if a == b:
			ans = max(ans, l + n - 1 - r)
	print(ans)
tst = int(input())
for tt in range(tst):
	solve()


def value(array):
	answer = 0
	count = 0
	mass1 = 0
	mass2 = 0
	j = len(array) - 1
	for i in range(len(array)):
		mass1 += array[i]
		count += 1
		while mass2 < mass1 and j > i:
			mass2 += array[j]
			j -= 1
			count += 1
		if mass1 == mass2 and count > answer:
			answer = count
	return answer

def main():
	n = int(input())
	data = []
	for i in range(n):
		count = int(input())
		array = list(map(int, input().split()))
		data.append(array)
	for array in data:
		print(value(array))
main()


for ar in [*open(0)][2::2]:
	ar = [*map(int, ar.strip().split())]
	l = len(ar)
	(i, j, c, ans) = (1, l - 1, 1, 0)
	(ls, rs) = (ar[0], 0)
	while i <= j:
		if ls < rs:
			ls += ar[i]
			i += 1
			c += 1
		elif ls > rs:
			rs += ar[j]
			j -= 1
			c += 1
		if ls == rs:
			ans = c
			ls += ar[i]
			i += 1
			c += 1
	print(ans)


from random import getrandbits
RANDOM = getrandbits(32)

class Wrapper(int):

	def __init__(self, x):
		int.__init__(x)

	def __hash__(self):
		return super(Wrapper, self).__hash__() ^ RANDOM
T = int(input())
q = []
for i in range(T):
	n = int(input())
	arr = [int(i) for i in input().split()]
	q.append((arr, n))
target = 'abcdefghijk'

def solve(arr, n):
	if n == 1:
		print(0)
		return
	i = 0
	j = n - 1
	lastSum = 0
	isum = arr[i]
	jsum = arr[j]
	while j - i > 1:
		if isum == jsum:
			lastSum = i + 1 + (n - j)
		if isum < jsum:
			i += 1
			isum += arr[i]
		else:
			j -= 1
			jsum += arr[j]
	if isum == jsum:
		lastSum = i + 1 + (n - j)
	print(lastSum)
for (arr, n) in q:
	solve(arr, n)


def f():
	n = int(input())
	l = 0
	r = n - 1
	w = [int(i) for i in input().split()]
	res = 0
	while l <= r:
		ce = 0
		lw = 0
		rw = 0
		ce += 1
		lw = w[l]
		l += 1
		while l <= r and lw != rw:
			if lw > rw:
				rw += w[r]
				r -= 1
				ce += 1
			else:
				lw += w[l]
				l += 1
				ce += 1
		if lw == rw:
			res += ce
		else:
			break
	return res
t = int(input())
for _ in range(t):
	print(f())


def solve(arr):
	a = 0
	b = 0
	i = 0
	j = len(arr) - 1
	ans = 0
	added = 0
	while i <= j:
		if a < b:
			a += int(arr[i])
			i += 1
			added += 1
		else:
			if a == b:
				ans = added
			b += int(arr[j])
			j -= 1
			added += 1
	return len(arr) if a == b else ans
n = int(input())
for i in range(n):
	m = int(input())
	arr = input().split(' ')
	print(solve(arr))


a = []
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	si = l[0]
	sj = l[-1]
	i = 0
	j = n - 1
	k = 0
	m = 0
	while j - i > 0:
		if si == sj:
			i += 1
			j -= 1
			k += 2
			m = k
			si += l[i]
			sj += l[j]
		elif si > sj:
			j -= 1
			sj += l[j]
			k += 1
		else:
			i += 1
			si += l[i]
			k += 1
	a.append(str(m))
print('\n'.join(a))


t = int(input())

def f(candies):
	ans = 0
	(i, j) = (0, len(candies) - 1)
	(lsum, rsum) = (candies[i], candies[j])
	while j > i:
		if lsum > rsum:
			j -= 1
			rsum += candies[j]
		elif lsum < rsum:
			i += 1
			lsum += candies[i]
		else:
			ans = i + 1 + len(candies) - j
			i += 1
			j -= 1
			lsum += candies[i]
			rsum += candies[j]
	return ans
for k in range(t):
	n = input()
	candies = [int(w) for w in input().split()]
	print(f(candies))


from bisect import bisect_left, bisect_right
from operator import truediv

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		lst = list(map(int, input().split()))
		cum = [0] * n
		cum[0] = lst[0]
		for i in range(1, n):
			cum[i] = cum[i - 1] + lst[i]
		spl = cum[n - 1] / 2
		i = bisect_left(cum, spl)
		j = bisect_right(cum, spl)
		if i == j:
			i -= 1
			j += 1
		if i < 0 or j >= n:
			print(0)
			continue
		sum1 = cum[i]
		sum2 = cum[n - 1] - cum[j - 1]
		foo = False
		while not (i < 0 or j >= n):
			if sum1 == sum2:
				foo = True
				break
			if sum1 < sum2:
				j += 1
			elif sum1 > sum2:
				i -= 1
			sum1 = cum[i]
			sum2 = cum[n - 1] - cum[j - 1]
		if foo:
			print(i + n - j + 1)
			continue
		if i < 0 or j >= n:
			print(0)
			continue
		print(i + n - 1 - j)
main()


def solve(n, arr):
	l = 0
	r = n - 1
	c = 2
	res = 0
	alice = arr[l]
	bob = arr[r]
	while l < r:
		if alice == bob:
			if l + 1 == r:
				res += c
				return res
			elif l + 2 == r:
				res += c
				return res
			else:
				l += 1
				r -= 1
				alice += arr[l]
				bob += arr[r]
				res += c
				c = 2
		elif alice > bob:
			r -= 1
			bob += arr[r]
			c += 1
		else:
			l += 1
			alice += arr[l]
			c += 1
	return res
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solve(n, arr))


for i in range(int(input())):
	number_of_candies = int(input())
	candies_weights = list(map(int, input().split()))
	alice_current_weight = sum(candies_weights)
	bob_last_weight = 0
	bob_weights = set()
	for j in range(number_of_candies - 1, -1, -1):
		current_candy_weight = candies_weights[j]
		alice_current_weight -= current_candy_weight
		bob_last_weight += current_candy_weight
		bob_weights.add(bob_last_weight)
		if alice_current_weight in bob_weights:
			bob_calculated_candies_weight = 0
			for k in range(number_of_candies - 1, -1, -1):
				bob_calculated_candies_weight += candies_weights[k]
				if bob_calculated_candies_weight == alice_current_weight:
					print(j + 1 + number_of_candies - k - 1)
					break
			break
	else:
		print(0)


for _ in range(int(input())):
	N = int(input())
	candies = list(map(int, input().split()))
	(left, right) = (0, N - 1)
	(alice, bob) = (0, 0)
	while left <= right:
		if alice < bob:
			alice += candies[left]
			left += 1
		else:
			bob += candies[right]
			right -= 1
	left -= 1
	right += 1
	while alice != bob:
		if alice < bob:
			bob -= candies[right]
			right += 1
		else:
			alice -= candies[left]
			left -= 1
	print(left + 1 + (N - right))


def calculate():
	i = 0
	j = N - 1
	if i == j:
		return 0
	left = arr[i]
	right = arr[j]
	count = 2
	equal = 0
	while i < j:
		if left < right:
			if i + 1 < j:
				i += 1
				left += arr[i]
				count += 1
			else:
				return equal
		elif left > right:
			if j - 1 > i:
				j -= 1
				right += arr[j]
				count += 1
			else:
				return equal
		else:
			equal = count
			if i + 1 < j - 1:
				i += 1
				j -= 1
				left += arr[i]
				right += arr[j]
				count += 2
			else:
				return equal
T = int(input())
for _ in range(T):
	N = int(input())
	arr = list(map(int, input().split()))
	print(calculate())


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for test in range(t):
	n = inp()
	candies = inlt()
	(lo, hi) = (0, n - 1)
	(a, b, count) = (0, 0, 0)
	while lo <= hi:
		if a < b:
			a += candies[lo]
			lo += 1
		elif b < a:
			b += candies[hi]
			hi -= 1
		elif lo != hi:
			a += candies[lo]
			b += candies[hi]
			lo += 1
			hi -= 1
		else:
			break
		if a == b:
			count = lo + n - hi - 1
	print(count)


for n in [*open(0)][2::2]:
	n = [*map(int, n.split())]
	(a, b, l, f) = [0] * 4
	r = len(n) - 1
	while l <= r:
		if a <= b:
			a += n[l]
			l += 1
		elif b < a:
			b += n[r]
			r -= 1
		if a == b:
			f = len(n) - r + l - 1
	print(f)


for s in [*open(0)][2::2]:
	a = (*map(int, s.split()),)
	i = j = r = s = t = 0
	while i - j < len(a):
		if s <= t:
			s += a[i]
			i += 1
		else:
			j -= 1
			t += a[j]
		if s == t:
			r = i - j
	print(r)


def _get_res(arr):
	(p1, p2) = (0, len(arr) - 1)
	(sum1, sum2) = (0, 0)
	res = 0
	while p1 <= p2:
		if sum1 >= sum2:
			sum2 += arr[p2]
			p2 -= 1
		else:
			sum1 += arr[p1]
			p1 += 1
		if sum1 == sum2:
			res = p1 + (len(arr) - 1 - p2)
	return res
for _ in range(int(input())):
	input()
	nums = list(map(int, input().split()))
	print(_get_res(nums))


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		li = [int(x) for x in input().split()]
		(p1, p2) = (-1, n)
		(s1, s2) = (0, 0)
		ans = 0
		while p1 < p2:
			if s1 == s2:
				ans = n - p2 + p1 + 1
				try:
					p1 += 1
					s1 += li[p1]
				except:
					p2 -= 1
					s2 += li[p2]
			elif s1 < s2:
				p1 += 1
				s1 += li[p1]
			else:
				p2 -= 1
				s2 += li[p2]
		print(ans)
main()


import math
import functools
from collections import *

def Solve():
	n = int(input())
	ar = [int(i) for i in input().split()]
	if n < 2:
		print(0)
		return
	(l, r) = (0, n - 1)
	res = 0
	temp = 2
	cur = ar[0] - ar[-1]
	while l < r:
		if cur < 0:
			l += 1
			cur += ar[l]
			temp += 1
		elif cur > 0:
			r -= 1
			cur -= ar[r]
			temp += 1
		else:
			res += temp
			temp = 2
			l += 1
			r -= 1
			cur = ar[l] - ar[r]
	print(res)

def main():
	x = int(input(''))
	for _ in range(x):
		Solve()
main()


def task(n, a):
	start = 0
	end = len(a) - 1
	left = 0
	right = 0
	candies = 0
	best = 0
	while start <= end:
		candies += 1
		if left <= right:
			left += a[start]
			start += 1
		else:
			right += a[end]
			end -= 1
		if left == right:
			best = candies
	print(best)
t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	task(n, a)


import math

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	l = 0
	r = n - 1
	left = 0
	right = 0
	while l <= r:
		if left < right:
			left += arr[l]
			l += 1
		else:
			right += arr[r]
			r -= 1
		if left == right:
			ans = max(ans, l + (n - r - 1))
	print(ans)
t = int(input())
for i in range(t):
	solve()


def fun(l, n):
	count = 2
	i = 0
	j = len(l) - 1
	alice = l[0]
	bob = l[-1]
	max_yet = 0
	while i < j:
		if alice < bob:
			i += 1
			alice += l[i]
			count += 1
		elif alice > bob:
			j -= 1
			bob += l[j]
			count += 1
		elif alice == bob:
			i += 1
			j -= 1
			alice += l[i]
			bob += l[j]
			max_yet = count
			count += 2
	return max_yet
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	print(fun(l, n))


out = []
T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	l = 0
	r = N - 1
	Alice = 0
	Bob = 0
	ans = 0
	while l <= r:
		if Alice <= Bob:
			Alice += A[l]
			if Alice == Bob:
				ans = l + 1 + N - r - 1
			l += 1
		else:
			Bob += A[r]
			r -= 1
			if Alice == Bob:
				ans = l + N - r - 1
	out.append(ans)
print(*out, sep='\n')


import collections
from math import ceil, gcd, sqrt, log
INF = float('inf')
mod = 1000000007

def solve():
	n = int(input())
	A = list(map(int, input().split()))
	maxCandies = 0
	(i, j) = (0, n - 1)
	(Alex, Bob) = (0, 0)
	(c1, c2) = (0, 0)
	while i <= j:
		if Alex < Bob:
			Alex += A[i]
			i += 1
			c1 += 1
		elif Bob < Alex:
			Bob += A[j]
			j -= 1
			c2 += 1
		else:
			maxCandies = c1 + c2
			if i != j:
				Alex += A[i]
				Bob += A[j]
				c1 += 1
				c2 += 1
			i += 1
			j -= 1
	if Alex == Bob:
		maxCandies = max(maxCandies, c1 + c2)
	print(maxCandies)
t = int(input())
while t != 0:
	solve()
	t -= 1


for i in range(int(input())):
	lenght = int(input())
	array = [int(i) for i in input().split()]
	prefix = array[0]
	sufix = array[lenght - 1]
	i = 0
	j = lenght - 1
	count = 0
	ans = 0
	while i < j:
		if prefix == sufix:
			count += 2
			ans = count
			i += 1
			j -= 1
			prefix += array[i]
			sufix += array[j]
		elif prefix > sufix:
			j -= 1
			sufix += array[j]
			count += 1
		else:
			i += 1
			prefix += array[i]
			count += 1
	print(ans)


def eat():
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		return 0
	(left_index, right_index) = (0, n - 1)
	(left_sum, right_sum) = (a[0], a[-1])
	max_sum = 2 if left_sum == right_sum else 0
	while left_index < right_index:
		if left_sum == right_sum:
			max_sum = left_index + 1 + n - right_index
		if left_sum <= right_sum:
			left_index += 1
			left_sum += a[left_index]
		else:
			right_index -= 1
			right_sum += a[right_index]
	return max_sum

def main():
	t = int(input())
	for _ in range(t):
		print(eat())
main()


def solve(n, nums):
	(left, right) = (0, n - 1)
	(lSum, rSum) = (nums[left], nums[right])
	ans = 0
	while left < right:
		while rSum < lSum:
			right -= 1
			rSum += nums[right]
		if lSum == rSum and left != right:
			ans = left + 1 + (n - right)
		left += 1
		lSum += nums[left]
	if lSum == rSum and left != right and (left < right):
		ans = left + 1 + (n - right - 1)
	return ans
t = int(input())
for T in range(t):
	n = int(input())
	nums = list(map(int, input().split(' ')))
	print(solve(n, nums))


import math as m
i = input()
inp = []
for a in range(0, int(i)):
	inp += [[input(), input()]]

def maxx(arr):
	if arr == []:
		return 0
	else:
		return max(arr)
for s in inp:
	n = int(s[0])
	arr = [int(x) for x in s[1].split()]
	i = 0
	j = n - 1
	lsum = arr[i]
	rsum = arr[j]
	best = 0
	while i < j:
		if lsum < rsum:
			i += 1
			lsum += arr[i]
		elif rsum < lsum:
			j -= 1
			rsum += arr[j]
		else:
			best = i + (n - 1 - j) + 2
			i += 1
			lsum += arr[i]
	print(best)


answers = []
for _ in range(int(input())):
	n = int(input())
	w = [int(x) for x in input().split()]
	i = 0
	j = n - 1
	a = 0
	b = 0
	ans = 0
	while i <= j:
		a += w[i]
		i += 1
		while a > b and i <= j:
			b += w[j]
			j -= 1
		if a == b:
			ans = i + (n - 1 - j)
	answers.append(ans)
for ans in answers:
	print(ans)


def compute(n, a):
	weights_right = 0
	weights_left = 0
	cntr_right = 0
	cntr_left = 0
	idx_right = n - 1
	idx_left = 0
	answers = 0
	while idx_left <= idx_right:
		if weights_left <= weights_right:
			weights_left += a[idx_left]
			idx_left += 1
		elif weights_left > weights_right:
			weights_right += a[idx_right]
			idx_right -= 1
		if weights_left == weights_right:
			answers = n - idx_right + idx_left - 1
	return answers
t = int(input())
for _ in range(t):
	n = int(input())
	a = input().split()
	a = [int(i) for i in a]
	print(compute(n, a))


def Candies(arr, n):
	if n < 2:
		return 0
	ans = 0
	i = 0
	j = n - 1
	Alice = arr[0]
	Bob = arr[n - 1]
	while i < j:
		if Alice == Bob:
			ans = i + 1 + n - j
			i += 1
			j -= 1
			Alice += arr[i]
			Bob += arr[j]
		elif Alice > Bob:
			j -= 1
			Bob += arr[j]
		else:
			i += 1
			Alice += arr[i]
	return ans
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(Candies(arr, n))


def verdict(n, a):
	Alice_Tot = a[0]
	Bob_Tot = a[-1]
	l = 0
	r = n - 1
	res = 0
	while l < r:
		if Alice_Tot == Bob_Tot:
			res = l + 1 + (n - r)
			l += 1
			Alice_Tot += a[l]
		elif Alice_Tot < Bob_Tot:
			l += 1
			Alice_Tot += a[l]
		else:
			r -= 1
			Bob_Tot += a[r]
	return res
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	print(verdict(n, a))


t = int(input())
for _ in range(t):

	def solve():
		n = int(input())
		a = list(map(int, input().split()))
		ans = 0
		(suml, sumr) = (a[0], a[n - 1])
		(l, r) = (0, n - 1)
		while l < r:
			if suml == sumr:
				ans = max(ans, l + 1 + n - r)
			if suml < sumr:
				l += 1
				suml += a[l]
			else:
				r -= 1
				sumr += a[r]
		print(ans)
	solve()


def resi():
	n = int(input())
	w = list(map(int, input().split()))
	Bob = 0
	Alice = 0
	l = 0
	d = n - 1
	br = 0
	while l - 1 <= d:
		br += 1
		if Bob == Alice:
			res = l + (n - 1 - d)
			Alice += w[l]
			l += 1
		if Bob > Alice:
			Alice += w[l]
			l += 1
		if Bob < Alice:
			Bob += w[d]
			d -= 1
	print(res)
	return
for _ in range(int(input())):
	resi()


import math

def solve():
	n = int(input())
	arr = [int(i) for i in input().split()]
	bob = arr[n - 1]
	alice = arr[0]
	r = n - 1
	l = 0
	ans = 0
	while l < r:
		if bob == alice:
			ans = max(ans, l + n - r + 1)
		if alice <= bob:
			l += 1
			alice += arr[l]
		else:
			r -= 1
			bob += arr[r]
	print(ans)
tst = int(input())
for i in range(tst):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	w = list(map(int, input().split()))
	a = w[0]
	b = w[-1]
	i = 0
	j = n - 1
	t = 2
	c = 0
	while i < j:
		if a == b:
			c = t
			j -= 1
			b += w[j]
			i += 1
			a += w[i]
			t += 2
		elif a > b:
			j -= 1
			b += w[j]
			t += 1
		else:
			i += 1
			a += w[i]
			t += 1
	print(c)


def inp(*, cf=lambda x: x):
	return cf(input())

def inpint():
	return inp(cf=int)

def inp_line(*, cf=lambda x: x, s=' '):
	return list(map(cf, input().split(s)))

def inpints():
	return inp_line(cf=int)

def test_case(case):
	n = inpint()
	w = inpints()
	ai = 0
	bi = len(w) - 1
	suma = w[0]
	sumb = w[len(w) - 1]
	ans = 0
	while ai < bi:
		if suma == sumb:
			ans = max(ans, ai + 1 + n - bi)
		if suma <= sumb:
			ai += 1
			suma += w[ai]
		elif suma > sumb:
			bi -= 1
			sumb += w[bi]
	return ans

def main():
	T = inpint()
	for t in range(1, T + 1):
		print(test_case(t))
main()


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_ls():
	return list(map(int, sys.stdin.readline().strip().split()))

def main():
	for _ in range(int(input())):
		n = int(input())
		ls = get_ls()
		(i, j) = (0, n - 1)
		(x, y) = (ls[0], ls[-1])
		ans = 0
		while i < j:
			if x == y:
				ans = max(ans, i + 1 + n - j)
			if x <= y:
				i += 1
				x += ls[i]
			else:
				j -= 1
				y += ls[j]
		print(ans)
main()


for _ in range(int(input())):
	n = int(input())
	s = [int(i) for i in input().split()]
	(l, r) = (0, 0)
	(a, b) = (0, 0)
	ans = 0
	while r + l <= n:
		if a == b:
			ans = r + l
			a += s[l]
			b += s[n - r - 1]
			l += 1
			r += 1
		elif a > b:
			b += s[n - r - 1]
			r += 1
		else:
			a += s[l]
			l += 1
	print(ans)


import collections
import sys
from collections import Counter, deque
import heapq
import bisect
import copy
MOD = 1000000007
NO = lambda : print('NO')
YES = lambda : print('YES')
_1 = lambda : print(-1)
ari = lambda : [int(_) for _ in input().split()]
cin = lambda : int(input())
cis = lambda : input()
show = lambda x: print(x)
fast = lambda : sys.stdin.readline()
test_case = 1
test_case = int(input())
sys.setrecursionlimit(10 ** 6)

def ans():
	n = cin()
	arr = ari()
	i = 0
	j = n - 1
	left = 0
	right = 0
	ans = 0
	while i <= j:
		if left > right:
			right += arr[j]
			j -= 1
		else:
			left += arr[i]
			i += 1
		if left == right:
			ans = max(ans, i + (n - (j + 1)))
	print(ans)
	return
for _ in range(test_case):
	ans()


t_num = int(input())
for i in range(t_num):
	input()
	line = input()
	weights = [int(x) for x in line.split()]
	candies = 0
	i_alice = 0
	i_bob = len(weights) - 1
	alice_total = weights[i_alice]
	bob_total = weights[i_bob]
	answ = 0
	a_num = 1
	b_num = 1
	while i_alice < i_bob:
		if alice_total > bob_total:
			i_bob -= 1
			bob_total += weights[i_bob]
			b_num += 1
		elif alice_total < bob_total:
			i_alice += 1
			alice_total += weights[i_alice]
			a_num += 1
		if alice_total == bob_total:
			answ = a_num + b_num
			i_bob -= 1
			bob_total += weights[i_bob]
			b_num += 1
			i_alice += 1
			alice_total += weights[i_alice]
			a_num += 1
	print(answ)


for _ in range(int(input())):
	n = int(input())
	w = list(map(int, input().split()))
	(i, j) = (0, n - 1)
	ans = 0
	(alice, bob) = (w[0], w[n - 1])
	while i < j:
		if alice < bob:
			i += 1
			alice += w[i]
		elif alice > bob:
			j -= 1
			bob += w[j]
		else:
			ans = i + 1 + (n - j)
			(i, j) = (i + 1, j - 1)
			(alice, bob) = (alice + w[i], bob + w[j])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1:
		print(0)
		continue
	i = 0
	j = n - 1
	(cl, cr) = (l[0], l[-1])
	ans = 0
	while i < j:
		if cl > cr:
			j -= 1
			cr += l[j]
		elif cl < cr:
			i += 1
			cl += l[i]
		else:
			ans = i + n - j + 1
			i += 1
			j -= 1
			cl += l[i]
			cr += l[j]
	print(ans)


from collections import deque
for _ in range(int(input())):
	w1 = 0
	w2 = 0
	eaten = 0
	n = int(input())
	a = deque(map(int, input().split()))
	try:
		while len(a):
			while w1 < w2:
				w1 += a.popleft()
				eaten += 1
			if w1 == w2:
				ans = eaten
				w1 += a.popleft()
				eaten += 1
			while w2 < w1:
				w2 += a.pop()
				eaten += 1
			if w1 == w2:
				ans = eaten
				w2 += a.pop()
				eaten += 1
	except IndexError:
		pass
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	li = [int(i) for i in input().split()]
	(a, b) = (0, 0)
	cnt = 0
	ans = 0
	(i, j) = (0, n - 1)
	while i < j:
		if a == b:
			ans = cnt
			a += li[i]
			i += 1
			cnt += 1
		elif a > b:
			b += li[j]
			j -= 1
			cnt += 1
		else:
			a += li[i]
			i += 1
			cnt += 1
	if a == b:
		ans = cnt
	elif a > b:
		if i == j and a == b + li[j]:
			ans = cnt + 1
	elif i == j and b == a + li[j]:
		ans = cnt + 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	weights = list(map(int, input().split()))
	maxCandies = 0
	alice = 0
	aliceSum = 0
	bobSum = 0
	candies = 0
	bob = len(weights) - 1
	if len(weights) > 1:
		aliceSum += weights[alice]
		alice += 1
		candies += 1
		bobSum += weights[bob]
		bob -= 1
		candies += 1
		if aliceSum == bobSum:
			maxCandies = candies
		while alice <= bob:
			if aliceSum < bobSum:
				aliceSum += weights[alice]
				alice += 1
				candies += 1
			elif bobSum < aliceSum:
				bobSum += weights[bob]
				bob -= 1
				candies += 1
			if aliceSum == bobSum:
				maxCandies = candies
				aliceSum += weights[alice]
				alice += 1
				candies += 1
	print(maxCandies)


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split(' ')))
	if N == 1:
		print(0)
		continue
	else:
		m = 0
		i = 0
		si = A[0]
		j = N - 1
		sj = A[N - 1]
		while i < j:
			if si == sj:
				m = i + 1 + N - j
				i += 1
				j -= 1
				sj += A[j]
				si += A[i]
			elif si > sj:
				j -= 1
				sj += A[j]
			else:
				i += 1
				si += A[i]
		print(m)


t = int(input())
for tt in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	l = 0
	r = n - 1
	alice = 0
	bob = 0
	cnt = 0
	ans = 0
	while l <= r:
		if alice == bob:
			ans = cnt
			if l == r:
				break
			alice += ar[l]
			bob += ar[r]
			l += 1
			r -= 1
			cnt += 2
		elif alice > bob:
			bob += ar[r]
			r -= 1
			cnt += 1
		else:
			alice += ar[l]
			l += 1
			cnt += 1
	if alice == bob:
		ans = cnt
	print(ans)


def sol(n, li):
	l = 0
	r = n - 1
	le = 0
	ri = 0
	c = 0
	while l <= r:
		if le > ri:
			ri = ri + li[r]
			r = r - 1
		elif le < ri:
			le = le + li[l]
			l = l + 1
		elif le == ri:
			if r == l:
				break
			c = l + n - r - 1
			ri = ri + li[r]
			r = r - 1
			le = le + li[l]
			l = l + 1
	if le == ri:
		c = l + n - r - 1
	return c
t = int(input())
for ii in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(sol(n, l))


t = int(input())
for _ in range(t):
	n = int(input())
	w = list(map(int, input().split()))
	if n == 1:
		print(0)
	elif n == 2:
		if w[0] == w[1]:
			print(2)
		else:
			print(0)
	else:
		(i, j) = (0, n - 1)
		(s1, s2) = (w[0], w[n - 1])
		(ind1, ind2) = (-1, -1)
		flag = 0
		while i < j:
			if s1 == s2:
				(ind1, ind2) = (i, j)
				flag = 1
				i += 1
				j -= 1
				s1 += w[i]
				s2 += w[j]
			elif s1 < s2:
				i += 1
				s1 += w[i]
			elif s1 > s2:
				j -= 1
				s2 += w[j]
		if flag:
			print(ind1 + 1 + (n - ind2))
		else:
			print(0)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = 0
	r = n - 1
	ans = 0
	sum1 = 0
	sum2 = 0
	konf = 0
	while r >= l:
		if sum1 == sum2:
			ans = konf
		if sum1 > sum2:
			sum2 += a[r]
			r -= 1
			konf += 1
		else:
			sum1 += a[l]
			l += 1
			konf += 1
	if sum1 == sum2:
		ans = konf
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(ans, i, j, l, r) = (0, 0, n - 1, 0, 0)
	while i < j:
		if i == 0 and j == n - 1:
			l += arr[0]
			r += arr[-1]
		if l == r:
			ans = n - j + (i + 1)
			i += 1
			j -= 1
			l += arr[i]
			r += arr[j]
		elif l < r:
			i += 1
			l += arr[i]
		else:
			j -= 1
			r += arr[j]
	print(ans)


def solution():
	n = int(input())
	w = [int(i) for i in input().split()]
	(a, b) = (w[0], w[n - 1])
	(apos, bpos) = (0, n - 1)
	ans = 0
	while apos < bpos:
		if a == b:
			ans = apos + 1 + (n - bpos)
		if a <= b:
			apos += 1
			a += w[apos]
		else:
			bpos -= 1
			b += w[bpos]
	print(ans)
t = int(input())
for _ in range(t):
	solution()


def main():
	t = int(input())
	for _ in range(t):
		N = int(input())
		arr = list(map(int, input().split()))
		bob_idx = N
		alice_idx = -1
		bobs_weight = 0
		alice_weight = 0
		answ = 0
		while True:
			if alice_weight == bobs_weight and alice_idx < bob_idx:
				candies = alice_idx + 1 + (N - bob_idx)
				if candies > answ:
					answ = candies
			alice_idx += 1
			if alice_idx >= bob_idx:
				break
			alice_weight += arr[alice_idx]
			while alice_weight > bobs_weight and bob_idx > alice_idx:
				bob_idx -= 1
				bobs_weight += arr[bob_idx]
		print(str(answ))
main()


t = int(input())
for _ in range(t):
	n = int(input())
	candies = list(map(int, input().split()))
	l = -1
	r = n
	Alice = 0
	Bob = 0
	mx_cnt = 0
	while l < r:
		if Alice == Bob:
			mx_cnt = l + 1 + n - r
			l += 1
			r -= 1
			Alice += candies[l]
			Bob += candies[r]
		elif Alice < Bob:
			l += 1
			Alice += candies[l]
		else:
			r -= 1
			Bob += candies[r]
	print(mx_cnt)


def main():
	for _ in range(int(input())):
		n = int(input())
		list1 = [int(i) for i in input().split()]
		print(solve(list1, n))

def solve(list1, n):
	if n == 1:
		return 0
	Right = list1[n - 1]
	Left = list1[0]
	if n == 2 and Right == Left:
		return 2
	Ltemp = 0
	Rtemp = n - 1
	count = 0
	while n >= n - Rtemp + (Ltemp + 1):
		if Right == Left:
			count = n - Rtemp + (Ltemp + 1)
		if Left >= Right:
			Rtemp -= 1
			Right += list1[Rtemp]
		else:
			Ltemp += 1
			Left += list1[Ltemp]
	return count
main()


for _ in range(int(input())):
	x = int(input())
	arr = list(map(int, input().split()))
	if x == 1:
		print(0)
		continue
	ans = 0
	l = 0
	r = x - 1
	cl = arr[l]
	cr = arr[r]
	coun = 2
	while l < r:
		if cl == cr:
			ans += coun
			coun = 0
			if r - l > 2:
				coun = 2
				l += 1
				r -= 1
				cl = arr[l]
				cr = arr[r]
			else:
				break
			continue
		if cl < cr:
			l += 1
			cl += arr[l]
		else:
			r -= 1
			cr += arr[r]
		coun += 1
	if cl == cr:
		ans += coun
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	index1 = 0
	sum1 = 0
	index2 = n - 1
	sum2 = 0
	checkpoint = 0
	for i in range(n):
		if sum1 == sum2:
			checkpoint = i
			sum1 += arr[index1]
			index1 += 1
		elif sum1 < sum2:
			sum1 += arr[index1]
			index1 += 1
		else:
			sum2 += arr[index2]
			index2 -= 1
	if sum1 == sum2:
		checkpoint = n
	print(checkpoint)


for _ in range(int(input())):
	n = int(input())
	C = list(map(int, input().split()))
	(l, r) = (0, n - 1)
	(a, b) = (0, 0)
	while l <= r:
		if a < b:
			a += C[l]
			l += 1
		else:
			b += C[r]
			r -= 1
	while a != b:
		if a > b:
			l -= 1
			a -= C[l]
		else:
			r += 1
			b -= C[r]
	print(l + (n - r) - 1)


n_tests = int(input())
ans = [0] * n_tests
for i in range(n_tests):
	n = int(input())
	arr = list(map(int, input().split()))
	li = 0
	ri = n - 1
	sl = 0
	sr = 0
	sc = 0
	c = 0
	cc = 0
	while ri >= li:
		if sl < sr:
			c += 1
			sl += arr[li]
			li += 1
		else:
			c += 1
			sr += arr[ri]
			ri -= 1
		if sl == sr:
			sc = sl
			cc = c
	ans[i] = cc
for i in range(n_tests):
	print(ans[i])


test_count = int(input())
for i in range(test_count):
	result = 0
	number_count = int(input())
	numbers_list = list(map(int, input().split()))
	start_sum = numbers_list[0]
	end_sum = numbers_list[-1]
	start_same_index = 0
	end_same_index = number_count - 1
	start_index = 0
	end_index = number_count - 1
	flag = True
	while start_index < end_index:
		if start_sum == end_sum:
			flag = False
			start_same_index = start_index
			end_same_index = end_index
			start_index += 1
			end_index -= 1
			start_sum += numbers_list[start_index]
			end_sum += numbers_list[end_index]
		elif start_sum > end_sum:
			end_index -= 1
			end_sum += numbers_list[end_index]
		else:
			start_index += 1
			start_sum += numbers_list[start_index]
	if flag:
		result = 0
	else:
		result = start_same_index + 1 + len(numbers_list) - end_same_index
	print(result)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	total = output = 0
	alice = bob = 0
	lb = 0
	rb = n - 1
	while lb <= rb:
		if alice == bob:
			if lb != rb:
				output = total
				alice += arr[lb]
				lb += 1
				bob += arr[rb]
				rb -= 1
				total += 2
			else:
				output = total
				alice += arr[lb]
				total += 1
				lb += 1
				rb -= 1
		elif alice > bob:
			bob += arr[rb]
			rb -= 1
			total += 1
		elif alice < bob:
			alice += arr[lb]
			lb += 1
			total += 1
	if alice == bob:
		output = total
	print(output)


for _ in range(int(input())):
	n = int(input())
	weight = list(map(int, input().split()))
	(kanan, right) = (0, n)
	(kiri, left) = (0, -1)
	ans = 0
	current = 0
	while right > left:
		if kiri == kanan:
			ans = current
			kiri += weight[left + 1]
			left += 1
			current += 1
		elif kiri > kanan:
			kanan += weight[right - 1]
			right -= 1
			current += 1
		else:
			kiri += weight[left + 1]
			left += 1
			current += 1
	print(ans)


T = int(input())

def solve(l):
	st = 0
	ed = len(l)
	xcnt = 0
	ycnt = 0
	x = 0
	y = 0
	ret = 0
	while st <= ed:
		if x <= y:
			if x == y:
				ret = max(ret, xcnt + ycnt)
			x += l[st]
			st += 1
			xcnt += 1
		else:
			y += l[ed - 1]
			ed -= 1
			ycnt += 1
	return ret
for _ in range(T):
	N = int(input())
	l = list(map(int, input().split()))
	print(solve(l))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(reversed(a))
	ans = 0
	i = 0
	j = 0
	p = 0
	q = 0
	while i + j <= n:
		if p > q:
			q += b[j]
			j += 1
		elif q > p:
			p += a[i]
			i += 1
		if p == q:
			ans = i + j
			p += a[i]
			q += b[j]
			i += 1
			j += 1
	print(ans)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	j = n - 1
	s1 = l[i]
	s2 = l[j]
	ans = 0
	while i < j:
		if s2 < s1:
			j -= 1
			s2 += l[j]
		elif s1 < s2:
			i += 1
			s1 += l[i]
		else:
			ans = max(ans, i + 1 + (n - j))
			i += 1
			j -= 1
			s1 += l[i]
			s2 += l[j]
	print(ans)


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	lans = [0]
	ans = 2
	i = 0
	j = n - 1
	a = l[i]
	b = l[j]
	if n == 1:
		print(0)
	else:
		while ans < n:
			if a == b:
				lans.append(ans)
				i += 1
				a += l[i]
				ans += 1
			elif a > b:
				j -= 1
				b += l[j]
				ans += 1
			elif a < b:
				i += 1
				a += l[i]
				ans += 1
		if a == b:
			lans.append(ans)
		print(lans[-1])
	t -= 1


import math
t = int(input())
for _ in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	res = 0
	test1 = l[0]
	test2 = l[n - 1]
	i = 0
	j = n - 1
	while i < j:
		if test1 == test2:
			res = i + 1 + (n - j)
			i += 1
			j -= 1
			test2 += l[j]
			test1 += l[i]
		elif test1 > test2:
			j -= 1
			test2 += l[j]
		else:
			i += 1
			test1 += l[i]
	print(res)


test = int(input())
for t in range(test):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(0)
	else:
		i = -1
		j = n
		sum_left = 0
		sum_right = 0
		res = 0
		count = 0
		while j - i > 0:
			if sum_right < sum_left:
				j -= 1
				sum_right += a[j]
				count += 1
			elif sum_left < sum_right:
				i += 1
				count += 1
				sum_left += a[i]
			else:
				res = count
				i += 1
				count += 1
				sum_left += a[i]
		print(res)


t = int(input())
for test in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	lefts = arr[0]
	rights = arr[-1]
	i = 0
	j = n - 1
	(f, ans) = (0, 0)
	while i < j:
		if lefts == rights:
			ans = max(ans, i + 1 + n - j)
			i += 1
			j -= 1
			rights += arr[j]
			lefts += arr[i]
			f = 1
		elif lefts > rights:
			j -= 1
			rights += arr[j]
		else:
			i += 1
			lefts += arr[i]
	if f == 0:
		print(0)
	else:
		print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(l, r) = (0, len(a) - 1)
	ans = 0
	(ls, rs) = (0, 0)
	while l <= r:
		if ls == rs:
			ans = l + n - r - 1
			ls += a[l]
			l += 1
		elif ls > rs:
			rs += a[r]
			r -= 1
		else:
			ls += a[l]
			l += 1
	if ls == rs:
		ans = l + n - r - 1
	print(ans)


for t in range(int(input())):
	n = int(input())
	L = list(map(int, input().split()))
	left = 0
	right = n - 1
	lsum = rsum = 0
	maxpos = 0
	while left <= right:
		if lsum > rsum:
			rsum += L[right]
			right -= 1
		elif lsum < rsum:
			lsum += L[left]
			left += 1
		else:
			maxpos = left + n - right - 1
			lsum += L[left]
			left += 1
	if lsum == rsum:
		maxpos = left + n - right - 1
	print(maxpos)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	cnt = 0
	suma = a[0]
	sumb = a[-1]
	i = 0
	j = n - 1
	ct = 0
	nt = 0
	while i < j:
		if suma == sumb:
			i += 1
			j -= 1
			suma += a[i]
			sumb += a[j]
			ct += 1
			nt += 1
			cnt += ct + nt
			(ct, nt) = (0, 0)
		elif suma < sumb:
			i += 1
			suma += a[i]
			ct += 1
		elif suma > sumb:
			j -= 1
			sumb += a[j]
			nt += 1
	print(cnt)


for t in range(int(input())):
	n = int(input())
	candy = list(map(int, input().split()))
	a = 0
	b = n - 1
	sum_a = 0
	sum_b = 0
	candies_eaten = int
	for i in range(n + 1):
		if sum_a > sum_b:
			sum_b += candy[b]
			b -= 1
		elif sum_a < sum_b:
			sum_a += candy[a]
			a += 1
		else:
			candies_eaten = i
			sum_a += candy[a]
			a += 1
	print(candies_eaten)


t = int(input())
for i in range(0, t):
	n = int(input())
	L = list(map(int, input().split()))
	(wA, wB) = (L[0], L[n - 1])
	ans = 0
	(k, j) = (0, n - 1)
	while k < j:
		if wA > wB:
			j -= 1
			wB += L[j]
		elif wA < wB:
			k += 1
			wA += L[k]
		else:
			ans = k + 1 + n - j
			k += 1
			j -= 1
			wA += L[k]
			wB += L[j]
	print(ans)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	megaCount = count = 0
	aage = 0
	pichhe = n - 1
	aageSum = pichheSum = 0
	if n == 1:
		print(0)
		continue
	if n >= 2:
		aageSum = l[0]
		pichheSum = l[-1]
	for i in range(n):
		if aage == pichhe or aage > pichhe:
			break
		if aageSum > pichheSum:
			pichhe -= 1
			count += 1
			pichheSum += l[pichhe]
		elif aageSum < pichheSum:
			aage += 1
			count += 1
			aageSum += l[aage]
		else:
			aage += 1
			pichhe -= 1
			aageSum += l[aage]
			pichheSum += l[pichhe]
			count += 2
			megaCount = count
	print(megaCount)


_ = int(input())
for __ in range(_):
	n = int(input())
	arr = list(map(int, input().split()))
	if n == 1:
		print(0)
	elif n == 2:
		if arr[0] == arr[1]:
			print(2)
		else:
			print(0)
	else:
		left_sum = arr[0]
		right_sum = arr[n - 1]
		left = 0
		right = n - 1
		out = 0
		while True:
			if left == right:
				break
			if left_sum == right_sum:
				out = left + (n - right + 1)
			if left_sum > right_sum:
				right -= 1
				right_sum += arr[right]
			else:
				left += 1
				left_sum += arr[left]
		print(out)