n=io.read("*n","*l")
a={0}
for i=1,n do
    a[i]=io.read("*n")
end

b={a[1]}
for i=2,n do
    b[i]=b[i-1]+a[i]
end
c={b[n]}
for i=2,n do
    c[i]=c[i-1]-a[i-1]
end

minyen=2020202020
for i=1,n-1 do
    minyen=math.min(minyen,math.abs(b[i]-c[i+1]))
end
print(minyen)