# frozen_string_literal: true

MOD = 10**9 + 7
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

c = Array.new(n) { 0 }
d = Array.new(n) { 0 }

0.upto(n - 1) do |i|
  0.upto(n - 1) do |j|
    c[i] += 1 if a[i] > a[j] && i < j
    d[i] += 1 if a[i] > a[j]
  end
end

sum = 0
0.upto(n - 1) do |i|
  sum += d[i] * (k * (k + 1) / 2 - k) + c[i] * k
end

puts sum % MOD
