# Your code here!

n = gets.chomp.to_i
array = gets.split(" ").map(&:to_i)
difference = []
i = 0
sums = array.sum/2
part = 0

(n).times do |i|
    part += array[i]
    if sums == part
        puts 0
        break
    end
    if sums < part
        puts [(part - (part-array[i])).abs,(part - (part+array[i+1])).abs].min
        break
    end
    i += 1
end
