const_num = 1000000007

N, K = gets.chomp.split(' ').map(&:to_i)
nums = gets.chomp.split(' ').map(&:to_i)

counts = Array.new(N)
N.times do |i|
  target = nums[i]
  counts[i] = [0, 0]
  N.times do |j|
    next if i == j
    compare = nums[j]
    next if target <= compare
    if i < j
      counts[i][1] += 1
    else
      counts[i][0] += 1
    end
  end
end

answer = 0
N.times do |i|
  num1 = counts[i][0]
  num2 = counts[i][1]
  answer = (answer + (K * K * num2 + K * (K - 1) * num1 - (num1 + num2) * (K * (K + 1) / 2 - K))) % const_num;
end

p answer
