MOD=10**9+7
N,K=gets.split.map(&:to_i)
A=gets.split.map(&:to_i)
AA=A+A

cnt1, cnt2 = 0, 0
(0..N-2).each do |i|
    (i+1..N-1).each do |j|
        cnt1 = (cnt1 + 1) % MOD if A[i] > A[j]
    end
end

(0..2*N-2).each do |i|
    (i+1..2*N-1).each do |j|
        cnt2 = (cnt2 + 1) % MOD if AA[i] > AA[j]
    end
end
cnt2 -= cnt1 * 2

x = (K*cnt1) % MOD
y = (cnt2*((K-1)*K)/2) % MOD
puts (x + y) % MOD
