import Data.List

main = do
    [n, k] <- map read . words <$> getLine :: IO [Integer]
    as <- map read . words <$> getLine :: IO [Integer]
    let tentoua = sumMod $ zipWith (\a bs -> fromIntegral (length (filter (a >) bs))) as (tail (tails as))
        tentoub = sumMod $ map (\a -> fromIntegral (length (filter (a >) as))) as
        ta = mulMod tentoua k
        tb = (mulMod tentoub k) `mulMod` (k-1) `div` 2
    print $ plusMod ta tb

moduloN = 10 ^ 9 + 7
modN = flip mod moduloN
plusMod x y = modN $ x + y
sumMod xs = foldl' (plusMod) 0 xs
mulMod x y = modN $ x * y