N = gets.chomp.to_i
 
input = gets.chomp.split(" ").map(&:to_i)
 
summation = 0
 
input.each do |e|
  summation += e
end
 
border = summation / 2
 
summation2 = 0
number = 0
input.each do |e|
  break if summation2 > border 
  summation2 += e
  number = e
end
 
if summation2 - border > border - (summation2 - number)
	money =  summation - 2 * (summation2 - number)
else
	money = 2 * summation2 - summation
end
 
puts money