_n = gets.chomp.to_i
nums = gets.chomp.split(' ').map(&:to_i)
sum = nums.inject(&:+)

s1 = 0
s2 = sum
min = (s2 - s1).abs
nums.each do |num|
  s1 += num
  s2 -= num
  if (s2 - s1).abs < min
    min = (s2 - s1).abs
  elsif s2 >= s1
    next
  else
    break
  end
end

puts min
