n=gets.to_i
a=gets.split.map(&:to_i)
b=[a[0]]
1.upto(n-1){|i| b[i]=a[i]+b[i-1]}
mid=b[-1]/2
t1=b.bsearch_index{|x| x>mid}
# t2=b[-1]-b[t1]
m2=2020202020*200000
m1=(b[-1]-2*b[t1]).abs
m2=(b[-1]-2*b[t1-1]).abs if t1-1>=0
puts (m1>m2)? m2:m1