n,k=gets.split.map &:to_i
a=gets.split.map &:to_i
kl=(k-1)*k/2%1000000007
kr=k*(k+1)/2%1000000007
ans = 0
n.times do |i|
  c = 0
  i.times do |j|
    c += 1 if a[j] < a[i]
  end
  ans += c*kl
  c = 0
  (n-i).times do |j|
    c += 1 if a[i+j] < a[i]
  end
  ans += c*kr
  ans %= 1000000007
end
p ans
