import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

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

moduloN :: Int
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