n=gets.to_i
arr=gets.split(" ").map{|n|n.to_i}
arr_r = []
arr_l = []
ans = []
arr_r[0] = arr[0]
arr_l[n-1-1] = arr[n-1]
for i in 1..n-2
  arr_r[i] = arr[i] + arr_r[i-1]
  arr_l[n-1-i-1] = arr[n-1-i] + arr_l[n-1-i+1-1]
end

for i in 0..n-1-1
 ans[i] = (arr_r[i] - arr_l[i]).abs
end

puts ans.sort[0]