import sys



N = int(eval(input()))

A = list(map(int, sys.stdin.readline().rsplit()))

S = [0] * (N + 1)

s = sum(A)



for i in range(N):

    S[i + 1] += S[i] + A[i]



mini = 10 ** 18

for i in range(1, N + 1):

    mini = min(mini, abs(S[N] - 2 * S[i]))



print(mini)

import sys, itertools



N = int(eval(input()))

A = list(map(int, sys.stdin.readline().rsplit()))



S = list(itertools.accumulate(A))



mini = 10 ** 18

for i in range(N):

    mini = min(mini, abs(S[N - 1] - 2 * S[i]))



print(mini)

import sys

N = int(eval(input()))
A = list(map(int, sys.stdin.readline().rsplit()))
S = [0] * (N + 1)
s = sum(A)
for i in range(N):
    S[i + 1] += S[i] + A[i]
mini = 10**18
for i in range(1, N + 1):
    mini = min(mini, abs(S[N] - 2 * S[i]))
print(mini)

import sys, itertools

N = int(eval(input()))
A = list(map(int, sys.stdin.readline().rsplit()))
S = list(itertools.accumulate(A))
mini = 10**18
for i in range(N):
    mini = min(mini, abs(S[N - 1] - 2 * S[i]))
print(mini)

-import sys +import sys, itertools -S = [0] * (N + 1) -s = sum(A) +S = list(itertools.accumulate(A)) +mini = 10**18 -    S[i + 1] += S[i] + A[i] -mini = 10**18 -for i in range(1, N + 1): -    mini = min(mini, abs(S[N] - 2 * S[i])) +    mini = min(mini, abs(S[N - 1] - 2 * S[i]))