import sys



n = int(eval(input()))



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



cnt = 0

ave = sum(a)/2



for i in range(n):

    cnt += a[i]

    if cnt == ave:

        print((0))

        sys.exit()

    

    elif cnt > ave:

        x = ave -cnt +a[i]

        if x >= cnt -ave:

            x = cnt -ave

        break



print((int(x*2)))
n = int(eval(input()))



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



cnt = 0

ave = sum(a)/2



for i in range(n):

    cnt += a[i]

    if cnt >= ave:

        ans = min(cnt*2-ave*2, ave*2-(cnt-a[i])*2)

        break



print((int(ans)))
import sys

n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
ave = sum(a) / 2
for i in range(n):
    cnt += a[i]
    if cnt == ave:
        print((0))
        sys.exit()
    elif cnt > ave:
        x = ave - cnt + a[i]
        if x >= cnt - ave:
            x = cnt - ave
        break
print((int(x * 2)))

n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
ave = sum(a) / 2
for i in range(n):
    cnt += a[i]
    if cnt >= ave:
        ans = min(cnt * 2 - ave * 2, ave * 2 - (cnt - a[i]) * 2)
        break
print((int(ans)))

-import sys - -    if cnt == ave: -        print((0)) -        sys.exit() -    elif cnt > ave: -        x = ave - cnt + a[i] -        if x >= cnt - ave: -            x = cnt - ave +    if cnt >= ave: +        ans = min(cnt * 2 - ave * 2, ave * 2 - (cnt - a[i]) * 2) -print((int(x * 2))) +print((int(ans)))