import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.ByteString.Char8 as BS

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

mod' :: Integral a => a -> a
mod' n = if n < 1000000007 then n else n `mod` 1000000007

cnt :: Integer -> Integer -> Integer -> Integer
cnt k inv lt = mod' $ (mod' $ inv*k) + (mod' $ lt*(k*(k-1) `div`2))

main :: IO ()
main = do
  [n',k] <- map read.words <$> getLine :: IO [Integer]
  as <- getIntList
  let n = fromInteger n' :: Int
      vec = (V.fromList as)
      inv = toInteger $ (mod' :: Int -> Int) $ foldl' (\x y -> mod' $ x + y) 0 [if (vec V.! i) > (vec V.! j) then 1 else 0 | i <- [0..n-1], j <- [0..n-1], i < j]
      lt  = mod' $ (+inv) $ toInteger $ (mod' :: Int -> Int) $ foldl' (\x y -> mod' $ x + y) 0 [if (vec V.! i) > (vec V.! j) then 1 else 0 | i <- [0..n-1], j <- [0..n-1], i > j]
  print $ cnt k inv lt
