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

sum_all = as.inject(:+)

sum = 0
near_half = 0
as.each do |a|
  sum += a
  if (near_half - (sum_all-near_half)).abs > (sum - (sum_all-sum)).abs
      near_half = sum
  end
end
puts (near_half - (sum_all-near_half)).abs
