program jsc2019qualb
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,k,i,j,fst,ots
    integer(int64),parameter:: md=1000000007
    integer(int64), allocatable:: a(:)
    
    read*, n,k
    allocate(a(n))
    read*, a(:)
    fst=0; ots=0
    do i=1,n
        do j=1,n
            if (a(i) > a(j)) then
                if (i < j) fst=fst+1
                ots=ots+1
            end if
        end do
    end do
    
    print'(i0)', mod(mod(fst*k,md) + mod(mod(k*(k-1)/2,md)*ots,md),md)
end program jsc2019qualb