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

len=a.sum
half_a=0
half_b=0
i=0
while (half_a+a[i])<=len/2
    half_a+=a[i]
    i+=1
end
i.upto(n-1) do |j|
    half_b+=a[j]
end
puts [half_b-half_a,(half_a+a[i])-(half_b-a[i])].min
