from itertools import accumulate



n = int(eval(input()))

a = list(map(int, input().split()))

acc = tuple(accumulate(a))



ret = min(abs(acc[-1] - x * 2) for x in acc)

print(ret)

n = int(eval(input()))

*a, = list(map(int, input().split()))

tot = sum(a)



ret = tot

l, r = 0, tot

for i in range(n):

    l += a[i]

    r -= a[i]

    ret = min(ret, abs(l - r))

print(ret)

from itertools import accumulate

n = int(eval(input()))
a = list(map(int, input().split()))
acc = tuple(accumulate(a))
ret = min(abs(acc[-1] - x * 2) for x in acc)
print(ret)

n = int(eval(input()))
(*a,) = list(map(int, input().split()))
tot = sum(a)
ret = tot
l, r = 0, tot
for i in range(n):
    l += a[i]
    r -= a[i]
    ret = min(ret, abs(l - r))
print(ret)

-from itertools import accumulate - -a = list(map(int, input().split())) -acc = tuple(accumulate(a)) -ret = min(abs(acc[-1] - x * 2) for x in acc) +(*a,) = list(map(int, input().split())) +tot = sum(a) +ret = tot +l, r = 0, tot +for i in range(n): +    l += a[i] +    r -= a[i] +    ret = min(ret, abs(l - r))