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

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

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

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

    ans = abs(l_a(1)-r_a(2))
    do i=2,n-1
        ans = min(ans, abs(l_a(i)-r_a(i+1)))
    end do
    print'(i0)', ans
end program name