a = int(eval(input()))

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



le,ri = 0,sum(l)

ans = 10**10

for i in range(len(l)-1):

    le += l[i]

    ri -= l[i]

    if ans < min(ans,abs(le-ri)):

        print(ans)

        break

    else:

        ans = min(ans,abs(le-ri))

else:

    print(ans)
a = int(eval(input()))

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



le,ri,le2,ri2 = 0,sum(l),sum(l),0

ans,ans2 = 10**10,10**10

for i in range(len(l)//2):

    le += l[i]

    ri -= l[i]

    le2 -= l[-(i+1)]

    ri2 += l[-(i+1)]

    ans = min(ans,abs(le-ri))

    ans2 = min(ans2, abs(le2-ri2))

    # print(ans,ans2)

else:

    print((min(ans,ans2)))
a = int(eval(input()))
l = list(map(int, input().split()))
le, ri = 0, sum(l)
ans = 10**10
for i in range(len(l) - 1):
    le += l[i]
    ri -= l[i]
    if ans < min(ans, abs(le - ri)):
        print(ans)
        break
    else:
        ans = min(ans, abs(le - ri))
else:
    print(ans)

a = int(eval(input()))
l = list(map(int, input().split()))
le, ri, le2, ri2 = 0, sum(l), sum(l), 0
ans, ans2 = 10**10, 10**10
for i in range(len(l) // 2):
    le += l[i]
    ri -= l[i]
    le2 -= l[-(i + 1)]
    ri2 += l[-(i + 1)]
    ans = min(ans, abs(le - ri))
    ans2 = min(ans2, abs(le2 - ri2))
    # print(ans,ans2)
else:
    print((min(ans, ans2)))

-le, ri = 0, sum(l) -ans = 10**10 -for i in range(len(l) - 1): +le, ri, le2, ri2 = 0, sum(l), sum(l), 0 +ans, ans2 = 10**10, 10**10 +for i in range(len(l) // 2): -    if ans < min(ans, abs(le - ri)): -        print(ans) -        break -    else: -        ans = min(ans, abs(le - ri)) +    le2 -= l[-(i + 1)] +    ri2 += l[-(i + 1)] +    ans = min(ans, abs(le - ri)) +    ans2 = min(ans2, abs(le2 - ri2)) +    # print(ans,ans2) -    print(ans) +    print((min(ans, ans2)))