data =[]
data2 = []
cnt = 0
cnt2 = 0

n,k = gets.chomp.split(" ").map(&:to_i)
data = gets.chomp.split(" ").map(&:to_i)

for i in 0...n do
 for j in (i+1)...n do
   if data[j] < data[i]
     cnt+=1
   end
 end
end

data2 = data+data
l= n*2

for i in 0...n do
 for j in n...l do
   if data2[j] < data2[i]
     cnt2+=1
   end
 end
end

p cnt
p cnt2

puts (cnt*k+cnt2*k*(k-1)/2)%1000000007
