N, K = gets.chomp.split.map(&:to_i)
A = gets.chomp.split.map(&:to_i)
MOD = 10 ** 9 + 7

# p N, K
# p A
MAX_SIZE = 2005
d = Array.new(MAX_SIZE)
d.each.with_index do |_, i|
  d[i] = Array.new(MAX_SIZE, 0)
end

A.each.with_index do |a, i|
  1.upto(MAX_SIZE-1).each do |j|  # d[i]d[0] is ignored. They are always 0.
    if j < a  # j is larger than a
      d[i+1][j] = d[i][j] + 1
    else
      d[i+1][j] = d[i][j]
    end
  end
end

r = 0

# We use d[A.size] for the loop of k. If k = 2, then (d[i][i] + d[A.size][i]) should be added.
# If k, then (d[i][i] + (k-1) * d[A.size][i])) should be added.
# 0 + 1 + 2 + ... + (k-1) = k * (k-1) / 2

A.each.with_index do |a, i|
  # For Debug
  # p "d[last][#{a}]: #{d[A.size][a]}"
  r += (K * d[i][a]) % MOD
  r += (d[A.size][a] * K * (K-1) / 2) % MOD
  r = r % MOD
end

p r