import Control.Applicative ((<$>), (<*>))
import Data.List (unfoldr, sort)
import Data.Char (isSpace)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B

getL :: (ByteString -> [Integer]) -> IO [Integer]
getL f = f <$> B.getLine

readIL :: (ByteString -> Maybe (Integer, ByteString)) -> (ByteString -> [Integer])
readIL f = unfoldr g
    where
        g s = do
            (n, s') <- f s
            return (n, B.dropWhile isSpace s')

main :: IO ()
main = do
    [n, k] <- getL (readIL B.readInteger)
    as <- getL (readIL B.readInteger)
    print $ solve n k as

solve :: Integer -> Integer -> [Integer] -> Integer
solve n k as = (innerInv + outerInv) `mod` 1000000007
    where
        innerInv = (inversion' as) * k `mod` 1000000007
        outerInv = ((inversion' $ reverse $ sort as) * k * (k - 1) `div` 2) `mod` 1000000007

inversion :: [Integer] -> Integer
inversion []       = 0
inversion [x]      = 0
inversion (x:y:xs)
    | x > y        = 1 + inversion (x:xs)
    | otherwise    = inversion (x:xs)

inversion' :: [Integer] -> Integer
inversion' []        = 0
inversion' [x]       = 0
inversion' ys@(x:xs) = (inversion ys) `mod` 1000000007 + (inversion' xs) `mod` 1000000007