class BIT
  attr_accessor(:size, :node)
  
  def initialize(size)
    @size = size
    @node = Array.new(size + 1, 0)
  end
  
  def add(i, x)
    while i <= @size
      @node[i] += x
      i += (i & -i)
    end
  end
  
  def sum(i)
    s = 0
    while i > 0
      s += @node[i]
      i -= (i & -i)
    end
    return s
  end
end

MOD = 10 ** 9 + 7

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

bit = BIT.new(a.max)
left = []
0.step(n - 1) do |i|
  bit.add(a[i], 1)
  left << i + 1 - bit.sum(a[i])
end

res = 0
sa = a.sort
0.step(n - 1) do |i|
  res += (k * left[i]) % MOD
  res += (sa.bsearch_index {|x| x >= a[i] } || n) * (k * (k - 1) / 2) % MOD
  res %= MOD
end

puts res