{-# LANGUAGE OverloadedStrings #-}
import Data.Maybe
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU

modInt = 10^9+7

main = do
  [n, k] <- getIntList
  ns <- getIntList
  let ms = mkpair [] ns
  print . foldr (((`mod` modInt).).(+)) 0 . map (f k) $ ms
    where
      both f (a, b) = (f a, f b)
      mkpair _ [] = []
      mkpair ps (q:qs) = both (length . filter (<q)) (ps, qs) : mkpair (q:ps) qs
      f k (p, q) = k * ((p + q) * k + (q - p)) `div` 2

-- IO
readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

getInt :: IO Int
getInt = readInt <$> BS.getLine

getIntList :: IO [Int]
getIntList = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

getIntVec :: Int -> IO (VU.Vector Int)
getIntVec n = VU.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
