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 = sum $ zipWith (\a bs -> length (filter (a >) bs)) as (tail (tails as))
        tentoub = sum $ map (\a -> length (filter (a >) as)) as
        m = flip mod (10^9+7)
        ta = m $ tentoua * k
        tb = (m ((m (tentoub * k)) * (k-1))) `div` 2
    print . m $ ta + tb