import itertools



N = int(eval(input()))

A = [int(_) for _ in input().split()]



ts = list(itertools.accumulate(A))

total = ts[-1]

total_half = total / 2



r = sorted(ts[:-1], key=lambda x:abs(x - total_half))[0]

print((abs(total - r - r)))

import itertools



N = int(eval(input()))

A = [int(_) for _ in input().split()]



ts = list(itertools.accumulate(A))

total = ts[-1]



r = list(itertools.accumulate((abs(total - t * 2) for t in ts[:-1]), min))[-1]



print(r)

import itertools

N = int(eval(input()))
A = [int(_) for _ in input().split()]
ts = list(itertools.accumulate(A))
total = ts[-1]
total_half = total / 2
r = sorted(ts[:-1], key=lambda x: abs(x - total_half))[0]
print((abs(total - r - r)))

import itertools

N = int(eval(input()))
A = [int(_) for _ in input().split()]
ts = list(itertools.accumulate(A))
total = ts[-1]
r = list(itertools.accumulate((abs(total - t * 2) for t in ts[:-1]), min))[-1]
print(r)

-total_half = total / 2 -r = sorted(ts[:-1], key=lambda x: abs(x - total_half))[0] -print((abs(total - r - r))) +r = list(itertools.accumulate((abs(total - t * 2) for t in ts[:-1]), min))[-1] +print(r)