n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
cnt = 0

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

tmp = 0
low = 0
a.sort!{|a,b| b <=> a}
for i in 1..(n-1)
  if a[i-1] > a[i]
    low += 1
  end
  tmp += low
end

puts (cnt*k + tmp*((k*(k-1))/2)) % (10**9 + 7)