require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

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

    asum = as.inject(:+)
    # puts asum

    lsum = 0
    min_diff = 2020202020000000
    as.each do |a|
      lsum += a
      rsum = asum - lsum
      diff = (lsum - rsum).abs
      # puts diff
      min_diff = diff if diff < min_diff
    end

    puts min_diff
  end
end

if __FILE__ == $0
  Solver.new.main
end
