N = gets.strip.to_i
a = gets.strip.split.map(&:to_i)

b=a.inject(:+)
c=0

minval=99999999
(0..N-1).each do |i|
    c+=a[i]
    b-=a[i]
    tmp=(b-c).abs
    if tmp<minval
        minval=tmp
    end
end

puts minval
