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

ans = 0
sum = a.inject(:+)

ans = 2020202020

left = 0
right = sum - left
n.times do |i|
  left += a[i]
  right = sum - left
  ans = [ans, (left - right).abs].min
end

puts ans


