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

t1 = 0
a.each_with_index do |i,index_i|
  a.each_with_index do |j,index_j|
    next if index_i > index_j
  	t1 += 1 if i > j
  end
end

tn = 0
b = a.sort.reverse
b.each_with_index do |i,index_i|
  b.each_with_index do |j,index_j|
    next if index_i > index_j
  	tn += 1 if i > j
  end
end

t_sum = k*t1 + (k*(k-1)/2)*tn
ans = t_sum % ((10**9) + 7)

puts ans