n,k=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
#ak=a*k
#ad=a.uniq.size
#add=(ad*(ad-1))/2
as=a.size
rn=0

a.each do |ae|
  rn+=a.select{|s|s<ae}.size
end

r=0
as.times do
  ai = a.pop
  r+=a.select{|s|s<ai}.size
end

add=rn
ks = ((k*(k+1))/2)
e = 1000000007
p (ks*add-r*k)%e
