program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: i,n,x,ans
    integer(int64),parameter:: md=1000000007
    integer(int64), allocatable:: a(:), ma(:)

    read*, n
    allocate(a(n), ma(n))
    read*, a(:)
    x=0
    do i=n,2,-1
        x=mod(x+a(i), md)
        ma(i) = x
    end do
    ans=0
    do i=2,n
        ans=ans+mod(a(i-1)*ma(i),md)
    end do
    print'(i0)', mod(ans,md)

end program main