N = int(eval(input()))

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

S = sum(A)

l = S//2

ans = S

s = 0

for k in range(N):

    s += A[k]

    ans = min(ans,abs(l-s)+abs(S-s-l))

print(ans)

N = int(eval(input()))

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

S = sum(A)

T = 0

ans = float("inf")

for e in A:

    T += e

    ans = min(ans,abs(T-(S-T)))

print(ans)

N = int(eval(input()))
A = list(map(int, input().split()))
S = sum(A)
l = S // 2
ans = S
s = 0
for k in range(N):
    s += A[k]
    ans = min(ans, abs(l - s) + abs(S - s - l))
print(ans)

N = int(eval(input()))
A = list(map(int, input().split()))
S = sum(A)
T = 0
ans = float("inf")
for e in A:
    T += e
    ans = min(ans, abs(T - (S - T)))
print(ans)

-l = S // 2 -ans = S -s = 0 -for k in range(N): -    s += A[k] -    ans = min(ans, abs(l - s) + abs(S - s - l)) +T = 0 +ans = float("inf") +for e in A: +    T += e +    ans = min(ans, abs(T - (S - T)))