local mod = 1000000007
local mfl = math.floor
local function bmul(x, y)
  local x0, y0 = x % 31623, y % 31623
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end
local n, k = io.read("*n", "*n")
local a = {}
for i = 1, n do a[i] = io.read("*n") end
local sum = 0
local fact1 = bmul(500000004, bmul(k, k - 1))
local fact2 = bmul(500000004, bmul(k, k + 1))
for i = 1, n - 1 do
  for j = i + 1, n do
    if a[i] < a[j] then
      sum = (sum + fact1) % mod
    elseif a[j] < a[i] then
      sum = (sum + fact2) % mod
    end
  end
end
print(sum)
