import Data.List

main = do
    [n, k] <- map read . words <$> getLine :: IO [Integer]
    as <- map read . words <$> getLine :: IO [Int]
    print $ solve k as

solve k as = ((f as) * k + (g as) * k * (k-1) `div` 2) `mod` (10^9+7)
    where f [] = 0
          f (a:as) = fromIntegral (length (filter (a >) as)) + f as
          g as = sum $ map (\a -> fromIntegral (length (filter (a >) as))) as