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

sum = bars.inject(:+)
current_sum = 0
answer = Float::INFINITY

0.upto(bars.size - 1).each do |index|
  current_sum += bars[index]

  remain = sum - current_sum
  diff = (remain - current_sum).abs

  answer = diff if diff < answer
end

puts answer
