# frozen_string_literal: true

n = gets.to_i
a = gets.split.map(&:to_i)

b = []
sum = 0
a.each do |e|
  sum += e
  b.push sum
end

w = a.reduce(&:+)

i = b.bsearch_index { |e| e >= w / 2 }
i -= 1 if i == n - 1

l = b[i]
r = w - b[i]
diff = (r - l).abs

puts diff
