N, K = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
MOD = 10 ** 9 + 7
ans = 0

count = 0
(0...N).each do |i|
  n = as[i]
  (0...N).each do |j|
    count += 1 if n < as[j]
  end
end

def pow_mod(x, n, mod)
  res = 1
  while n > 0
    if n[0] == 1
      res = res * x % mod
    end
    x = x * x % mod
    n >>= 1
  end
  res
end

count = ((count % MOD) * (pow_mod(2, (K - 1), MOD) - 1) % MOD) if K > 1

count2 = 0
(0...N).each do |i|
  n = as[i]
  ((i + 1)...N).each do |j|
    count2 += 1 if n > as[j]
  end
end

ans = (count + (count2 * K)) % MOD
puts ans
