program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i,ans,l_a, r_a
    integer(int64), allocatable:: a(:)

    read*, n
    allocate(a(n))
    read*, a(:)
    l_a=a(1)
    r_a=sum(a(2:))
    ans=abs(l_a-r_a)

    do i=2,n-1
        l_a=l_a+a(i)
        r_a=r_a-a(i)
        ans=min(ans,abs(l_a-r_a))
    end do

    print'(i0)', ans
end program name