program main
  implicit none
  integer(8) i,N,K,b,s,j
  integer(8),allocatable :: A(:) 
  read(*, *) N, K
  allocate(A(N))
  read(*, *) (A(i), i = 1,N)
  b = 0
  s = 0
  do i = 1,N-1
    do j = i+1,N
      if (A(i) > A(j)) then
        b = b + 1
      elseif (A(i) < A(j)) then
        s = s + 1
      end if
    end do
  end do
  b = mod((mod(K*(K+1)/2,10**9+7))*b,10**9+7)
  s = mod((mod(K*(K-1)/2,10**9+7))*s,10**9+7)
  write(*, *) mod(b + s,10**9+7)
end program main
