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


ans = 0

# 超えるインデックスを調べる

sum_a = a.sum

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

  i += 1
end

ans_1 = a.slice(0..i).sum - a.slice(i+1..n-1).sum
ans_2 = a.slice(i..n-1).sum - a.slice(0..i-1).sum


p [ans_1, ans_2].min
