N = gets.to_i
As = gets.split(' ').map(&:to_i)
total_length = As.inject(&:+)
half_length = total_length / 2.0
length_from_start = 0
As.each_with_index do |a, i|
  length_from_start += a
  if length_from_start == half_length
    puts 0
    break
  elsif length_from_start > half_length
    mid_point = i
    length_to_end = As[(i + 1)..(N - 1)].inject(&:+)
    shorter, longer = [length_from_start - a, length_to_end].min, [length_from_start - a, length_to_end].max
    puts ((shorter + a) - longer).abs
    break
  end
end