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

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

as.each_with_index do |a, i|
  ss[i + 1] = ss[i] + a
  diff = (ss[i] + a - (total - ss[i + 1])).abs

  min = diff if diff <= min
end

puts min
