n=gets.to_i
a=gets.split.map(&:to_i)

len=a.sum
half_a=Array.new(n,0)
half_b=Array.new(n,0)
half_a[0]=a[0]
half_b[0]=len
ans=len
1.upto(n-1) do |i|
    half_a[i]=half_a[i-1]+a[i]
    half_b[i]=half_b[i-1]-a[i-1]
    ans=[ans,(half_a[i-1]-half_b[i]).abs].min
end
puts ans
