pythondef solve(N, AS):
import sys
INF = sys.maxsize
from itertools import accumulate
acc = list(accumulate(AS + AS)) + [0]
def rangeSum(start, end):
return acc[end - 1] - acc[start - 1]
start = 0
end = 1
ret = INF
total = rangeSum(0, N)
while True:
x = rangeSum(start, end)
y = total - x
d = x - y
ret = min(abs(d), ret)
if d < 0:
if end == 2 * N - 1:
break
end += 1
else:
start += 1
return ret