n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
l = Array.new(n, 0)
r = Array.new(n, 0)
for i in 0...(n - 1) do
  for j in (i + 1)...n do
    if a[i] > a[j]
      r[i] += 1
    elsif a[i] < a[j]
      l[j] += 1
    end
  end
end
r[n - 1] = 0
l[0] = 0
count = 0
for i in 0...n do
  count += r[i] * (k * (k + 1) / 2) + l[i] * ((k - 1) * k / 2)
end
puts count % 1000000007
