base = 10^9 + 7

-- O(N^2)で十分と解説にあったので比較
doCount :: [Int] -> [(Integer,Integer)]
doCount as = loop [] as
  where
    cnt v xs = fromIntegral $ length $ filter (v >) xs
    loop as (b:bs) = (cnt b as, cnt b bs) : loop (b:as) bs
    loop _ [] = []
  
compute :: Integer -> Integer -> [Int] -> Integer
compute n k as = foldl1 add $ map f $ doCount as
  where
    f (x, y) = k * y + k * (k-1) * (x+y) `div` 2
    add x y = (x+y) `mod` base

main = do
  li <- getLine
  let [n,k] = map read $ words li
  li <- getLine
  let as = map read $ words li
  let ans = compute n k as
  print ans
