N = gets.chomp.to_i
a = Array.new(N+1)
total = Array.new(N+1,0)
str = gets.split
for i in 1..N do
    a[i] = str[i-1].to_i
    total[i] = total[i-1] + a[i]
end

min = total[N]
for i in 1...N do
    dif = total[i] - (total[N] - total[i])
    dif = dif.abs
    if dif < min
        min = dif
    end
end

puts min