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

total = as.inject(:+)
ss = Array.new(n + 1, 0)
ds = Array.new(n + 1, 0)

min = 2020202020
index = 0

as.each_with_index do |a, i|
  ss[i + 1] = ss[i] + a
  ds[i + 1] = total - ss[i + 1]

  if (ss[i + 1] - ds[i + 1]).abs <= min
    index = i
    min = (ss[i + 1] - ds[i + 1]).abs
  end
end

puts (ss[index + 1] - ds[index + 1]).abs
