A = gets().chomp.split(' ').map{|n| n.to_i }

leftsum = 0
rightsum = 0
l = 0
r = size - 1

while l < r
  leftsum = leftsum + A[l]
  rightsum = rightsum + A[r]
  l = l + 1
  r = r - 1
end

if l == r
  if leftsum > rightsum
    rightsum = righsum + A[l]
  else
    leftsum = leftsum + A[l]
  end
end

puts (leftsum - rightsum).abs