n = gets.chomp.to_i
list = gets.chomp.split.map(&:to_i)

s = []
list.each.with_index(0) do |x, i|
  s[i] = s[i - 1].to_i + x
end

min_diff = 1_000_000
0.upto(list.length - 1) do |i|
  x = s[list.length - 1] - s[i] * 2
  min_diff = x.abs if x.abs < min_diff
end
puts min_diff

