N, K = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)

counter = 0
arr.each_with_index do |num, index|
  a = 0
  (0..(index - 1)).each do |index_2|
    a += 1 if num > arr[index_2]
  end
  counter += (a * K - a) * K / 2

  a = 0
  ((index + 1)..(N-1)).each do |index_2|
    a += 1 if num > arr[index_2]
  end
  counter += (a * K + a) * K / 2
end

puts counter % (10 ** 9 + 7)