n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
fir = 0
sec = 0
for i in 0..n-1
  for j in 0..i-1
    fir += 1 if a[j] > a[i]
  end
end
for i in 0..n-1
  for j in 0..n-1
    sec += 1 if a[j] > a[i]
  end
end
fir %= 1000000007
fir *= k
fir %= 1000000007
sec %= 1000000007
sec *= k
sec %= 1000000007
sec *= k - 1
sec %= 1000000007
sec /= 2
ans = (fir + sec) % 1000000007
puts ans