n = int(eval(input()))

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



from itertools import accumulate



tot=sum(l)

ans=2020202020*100000

for i in list(accumulate(l)):

    ans=min(ans, abs(tot-(i*2)))



for i in list(accumulate(l[::-1])):

    ans=min(ans, abs(tot--(i*2)))



print(ans)

n = int(eval(input()))

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



from itertools import accumulate

cum=list(accumulate(l))



tot=sum(l)

ans=2020202020*100000

for i in cum:

    ans=min(ans, abs(tot-i*2))

print(ans)

n = int(eval(input()))
l = list(map(int, input().split()))
from itertools import accumulate

tot = sum(l)
ans = 2020202020 * 100000
for i in list(accumulate(l)):
    ans = min(ans, abs(tot - (i * 2)))
for i in list(accumulate(l[::-1])):
    ans = min(ans, abs(tot - -(i * 2)))
print(ans)

n = int(eval(input()))
l = list(map(int, input().split()))
from itertools import accumulate

cum = list(accumulate(l))
tot = sum(l)
ans = 2020202020 * 100000
for i in cum:
    ans = min(ans, abs(tot - i * 2))
print(ans)

+cum = list(accumulate(l)) -for i in list(accumulate(l)): -    ans = min(ans, abs(tot - (i * 2))) -for i in list(accumulate(l[::-1])): -    ans = min(ans, abs(tot - -(i * 2))) +for i in cum: +    ans = min(ans, abs(tot - i * 2))