n = gets.chop.to_i
a = gets.chop.split.map(&:to_i)

sum_a = a.inject(:+)

tmp = 0
i = 0
while 1 do
  tmp += a[i]
  if tmp >= sum_a/2
    index = i
    break
  end

  i += 1
end

if index == 0
  p (a[0]- a[1..n-1].inject(:+)).abs
else
  ans_1 = a.slice(0..index).inject(:+) - a.slice(index+1..n-1).inject(:+)
  ans_2 = a.slice(index..n-1).inject(:+) - a.slice(0..index-1).inject(:+)


  p [ans_1.abs, ans_2.abs].min
end




