n,k=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
c=0
m=Array.new(n,0)
p=Array.new(n,0)
0.upto(n-1){|i|(i+1).upto(n-1){|j|
  m[i]+=1 if a[i]>a[j]; p[j]+=1 if a[i]<a[j];}}

s=m.inject(0){|sum,i|sum+i}
x=p.inject(0){|sum,i|sum+i}
puts (k*(k-1)/2*(s+x) + s*k)%(10**9+7)
