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

ss = Array.new(n + 1, 0)
min = 2020202020

as.each_with_index do |a, i|
  ss[i + 1] = ss[i] + a
end

total = ss.last
ss.each do |sl|
  sr = total - sl
  diff = (sl - sr).abs

  min = diff if diff <= min
end

puts min
