integer N
integer(16),allocatable,dimension(:)::A,B
integer(16) ans
read*,N
allocate(A(N),B(0:N))
read*,A
B(0)=0
do i=1,N
  B(i)=A(i)+B(i-1)
end do
ans=huge(ans)
do i=1,N-1
  ans=min(ans,abs(2*B(i)-B(N)))
end do
print"(I0)",ans
end