integer(8) N,K,i
integer(8),allocatable,dimension(:)::A,B,C
integer(8) cnt
integer(8) ans
read*,N,K
allocate(A(N),B(N),C(N))
read*,A
do i=1,N
  cnt=0
  do j=i+1,N
    if(A(i)>A(j))cnt=cnt+1
  end do
  B(i)=cnt
end do
do i=1,N
  cnt=0
  do j=1,N
    if(A(i)>A(j))cnt=cnt+1
  end do
  C(i)=cnt
end do
ans=0
do i=1,N
  ans=mod(ans+B(i)*K,10**9+7)
  ans=mod(ans+C(i)*((K-1)*K)/2,10**9+7)
end do
print"(i0)",ans
end