import Data.Bits
import Data.List
import Data.Foldable(foldlM)
import Data.Maybe(fromJust)
import Control.Monad
import Data.Array as A ((!),accumArray)
import Data.Graph
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Char8 as BS
import Debug.Trace

toTuple :: [a] -> (a,a)
toTuple (x:y:_) = (x,y)
toTuple _ = undefined

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

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

getLineB :: (Read a) => IO [a] --直接入力
getLineB = map (read.BS.unpack) . BS.words <$> BS.getLine

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

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

main :: IO ()
main = do
  [n,k] <- getIntList
  as <- getIntList
  let vec = (V.fromList as)
      inv = mod' $ foldl' (\x y -> mod' $ x + y) 0 [if traceShow (i,j,(vec V.! i) > (vec V.! j)) $ (vec V.! i) > (vec V.! j) then 1 else 0 | i <- [0..n-1], j <- [0..n-1], i < j]
      lt = mod' $ (inv+) $ mod' $  foldl' (\x y -> mod' $ x + y) 0 [if traceShow (i,j,(vec V.! i) > (vec V.! j)) $ (vec V.! i) > (vec V.! j) then 1 else 0 | i <- [0..n-1], j <- [0..n-1], i > j]
  print as
  print $ cnt2 k inv lt
