# DISCO 2020
# 方針：全体の長さn、累積和を取りつつnとの差分も取る
# 正と負の最小の絶対値の小さいほうが答え
n = gets.to_i
a = gets.split.map &:to_i
cs = Array.new(n+1,0)

n.times do |i|
  cs[i+1] = cs[i] + a[i]
end
sum = cs[n]

diff = Array.new(n-1,0)
(n-1).times do |i|
  diff[i] = sum - cs[i+1] * 2
end

p diff
exit

b = diff.select{|v|v >= 0}.min
c = diff.select{|v|v < 0}.map{|v|v.abs}.min
ans = [b,c].compact.min

puts ans
