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

s1 = 0
count = 0
a = (array.inject(:+)/ 2.to_f).round

array.each do |i|
    if (s1 - a).abs >= (s1 + i - a).abs
        s1 += i
        count += 1
    else
        break
    end
end

s2 = array[count..(n-1)].inject(:+)

puts (s1 - s2).abs
