{-# LANGUAGE TupleSections #-}

import Control.Arrow
import Control.Applicative
import Data.List
import Prelude hiding (exp)

main :: IO ()
main = do
  { [n, k] <- readLineInputs :: IO [Int]
  ; as <- readLineInputs :: IO [Int]
  ; print $ solve k as
  }

solve :: Int -> [Int] -> Int
solve k as = (k × p) ＋ (k × (k - 1) × q × inv 2)
  where
    p = inversions as
    q = inversions' as

inversions' :: [Int] -> Int
inversions' as = count (runlen (sort as)) as

count :: [(Int, Int)] -> [Int] -> Int
count = iter 0
  where
    iter c _ [] = c
    iter c rs (x:xs) = iter (c + (foldr ((+) . snd) 0 $ takeWhile ((< x) . fst) rs)) rs xs

readLineInputs :: Read a => IO [a]
readLineInputs = map read . words <$> getLine

spanCount :: (a -> Bool) -> [a] -> (Int, [a])
spanCount p [] = (0, [])
spanCount p xxs@(x:xs)
  | p x       = first succ (spanCount p xs)
  | otherwise = (0,xxs)

runlen :: Eq a => [a] -> [(a, Int)]
runlen []     = []
runlen (x:xs) = case spanCount (x ==) xs of
  (m,ys) -> (x, succ m) : runlen ys

inversions :: Ord a => [a] -> Int
inversions = ($ 0) . fst . head . mergeAll . map ((id :: Int -> Int,) . (1 :: Int,) . (: []))

type List a = (Int, [a])

mergeAll :: Ord a => [(Int -> Int, List a)] -> [(Int -> Int, List a)]
mergeAll []   = []
mergeAll [xs] = [xs]
mergeAll (xs:ys:zss) = mergeAll (merge xs ys : mergeAll zss)

merge :: Ord a => (Int -> Int, List a) -> (Int -> Int, List a) -> (Int -> Int, List a)
merge (f, (_,[])) (g, ys) = (f . g, ys)
merge (f, xs) (g, (_,[])) = (f . g, xs)
merge p@(f,(m,xxs@(x:xs))) q@(g,(n,yys@(y:ys)))
  | x > y     = case merge p (g, (pred n, ys)) of
      (h,(_,zs)) -> ((m +) . h,  (m + n, y : zs))
  | otherwise = case merge (f, (pred m, xs)) q of
      (h,(_,zs)) -> (h, (m + n, x : zs))

-- modula arithmetic

base :: Int
base = 10^9 + 7

(＋) :: Int -> Int -> Int
m ＋ n = (m + n) `mod` base

(×) :: Int -> Int -> Int
m × n = (m * n) `mod` base

exp :: Int -> Int -> Int
exp m 0 = 1
exp m 1 = m
exp m n = if even n then p × p else m × exp m (pred n)
  where
    p = exp m (n `div` 2)

inv :: Int -> Int
inv n = exp n (base - 2)
