modulus = (10^9)+7

seqSum :: Int -> Int -> Int -> Int
seqSum a d n = truncate $ (n' / 2) * (2 * a' + fromIntegral (n-1) * d')
  where a' = fromIntegral a :: Double
        d' = fromIntegral d :: Double
        n' = fromIntegral n :: Double

solve :: Int -> [Int] -> Int
solve k xs = seqSum p (q-p-p) k `mod` modulus
  where
    p = f xs
    q = f . concat $ replicate 2 xs
    f [] = 0
    f (x:xs) = (length . filter (x >) $ xs) + f xs

main :: IO ()
main = do
    [_,k] <- map read . words <$> getLine :: IO [Int]
    a <- map read . words <$> getLine :: IO [Int]
    print $ solve k a