n = gets.to_i
a = gets.split.map(&:to_i)
left = 0
right = n-1
l = 0
r = 0
flag = false
until left>right
  if (l+a[left]-r).abs < (l-r-a[right]).abs
    l += a[left]
    left += 1
  else
    r += a[right]
    right -= 1
  end
end
p (l-r).abs
