program main
	implicit none
	integer N, i
	integer(8) S, Sall, ans
	integer(8), allocatable :: a(:)
	read(*, *) N
	allocate(a(1: N))
	read(*, *) a(1: N)
	Sall = sum(a)
	S    = Sall
	ans  = 2d14
	do i = 1, N-1
		S   = S - a(i)
		ans = min(ans ,abs((Sall - S) - S))
	end do
	write(*, *) ans
end program main