program MAIN
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i,ans,b
    integer(int64),allocatable:: a(:)


    read*, n
    allocate(a(n))
    read*, a(:)

    do i=2,n
        a(i)=a(i-1)+a(i)
    end do


    ans = a(n)-2*a(1)

    do i=2,n-1
        b = a(n)-a(i)
        ans = min(ans, abs(a(i)-b))
    end do

    print'(i0)', ans
end program MAIN