N, K = gets.split(' ').map(&:to_i)
A = gets.split(' ').map(&:to_i)
r = 1000 * 1000 * 1000 + 7
A_MAX = 2000

tento = 0
cnts = (0..A.size).to_a.map { |i| Array(A[i+1..-1]).select { |n| n < A[i] }.size }
cnts.each do |c|
  tento += c 
  tento %= r
end

cnt = [0] * (A_MAX + 1)
A.each do |n|
  cnt[n] += 1
end

belows = 0
aboves = 0
(1..A_MAX).each do |n|
  belows += cnt[n - 1]
  aboves += (belows * cnt[n]) % r
  # pp [n, belows, aboves]
end

betweens = (K - 1) * K / 2

hoge = aboves * betweens % r

puts ((tento * K % r) +  hoge ) % r
