N = gets.to_i
As = gets.split.map(&:to_i)

total_length = As.inject(:+)

# lefts = []
left_sum = 0
# rights = []
right_sum = 0
current_sum = 0

As.each_with_index do |i, idx|
  if current_sum < total_length / 2 && idx != As.size - 1
    # lefts << i if i > 1
    left_sum += i
  else
    # rights << i if i > 1
    right_sum += i
  end
  current_sum += i
end

# p [lefts, rights]
# p [left_sum, right_sum]

puts (left_sum - right_sum).abs