n = gets.to_i
a = gets.split.map(&:to_i)
sum = 0;
(n).times do |i|
    sum += a[i]
end
if sum % 2 == 0
    puts 0
else
    half = 0
    (n).times do |i|
        half += a[i]
        rec = i if half > sum/2
        break if half > sum/2
    end
    dif = half - (sum - half)
    puts dif
end