local mod = 1000000007

local function bmul(x, y)
  return (x * y) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

local function bsub(x, y)
  return x < y and x - y + mod or x - y
end

local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = pow // 2
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
end

local n, k = io.read("*n", "*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
local s, t = 0, 0
for i = 1, n do
  local v = 0
  for j = 1, i - 1 do
    if a[i] < a[j] then
      v = v + 1
    end
  end
  s = badd(s, v)
  for j = i + 1, n do
    if a[i] < a[j] then
      v = v + 1
    end
  end
  t = badd(t, v)
end
local ret = bmul(k, s)
local z = bmul(bmul(k - 1, k), 500000004)
ret = badd(ret, bmul(z, t))
print(ret)
