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

t1 = 0
0.upto(N-2) do |i|
  (i+1).upto(N-1) do |j|
    t1 += 1 if A[i] > A[j]
  end
end
t1 = (t1 * K) % MOD

t2 = 0
if K > 1
  ns = 0
  0.upto(N-1) do |i|
    ns += A.count {|a| a < A[i] }
  end
  t2 = ns * K * (K-1) / 2
end
puts (t1 + t2) % MOD
