require 'pp'

n = gets.chomp!.to_i
a_n = gets.chomp!.split(" ").map(&:to_i)

sum = a_n.inject(&:+)

left = [a_n[0]]
right = [sum - a_n[0]]
sum
0.upto(n-2) do |i|
    left[i+1] = left[i] + a_n[i+1]
    right[i+1] = sum - left[i+1]
end

ans = 10 ** 20
left.length.times do |i|
    t = (left[i] - right[i]).abs
    if t < ans
        ans = t
    end
end

puts ans
