d = 10**9+7
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
x = 0
(0..n-1).each do |i|
  (i+1..n-1).each do |j|
    x += 1 if a[i] > a[j]
  end
end
a = a.sort.reverse
y = 0
(0..n-1).each do |i|
  (i+1..n-1).each do |j|
    y += 1 if a[i] > a[j]
  end
end
ans = (x * k) % d
s = (k * k) % d
t = (k * (k + 1) / 2) % d
z = y * (s - t) % d
ans += z
puts ans % d