n,k = gets.chomp.split(" ").map{|i|i = i.to_i}

shou = (10**9)+7

a = gets.chomp.split(" ").map{|i|i = i.to_i}
#pp n
#pp a
count = 0

n.times do |j|
  j.times do|i|
    if a[i]>a[j] then
      count += 1
    end
  end
end
#puts count
count =( count * k )%shou

j_count = 0
n.times do |i|
  n.times do|j|
    if a[i]>a[j] then
      j_count += 1
    end
  end
end
#puts "j_count = #{j_count}"
new_k = ( ((k-1) *k) / 2)%shou
#puts "new_k = #{new_k}"
j_count = (new_k * (j_count%shou) ) %shou
count =( count + j_count ) % shou
puts count