import Data.List
import Data.Int
import Data.Ratio

main = do
  [n,k] <- map read.words<$>getLine
  a     <- map read.words<$>getLine
  print $ solve (Mod k) a

solve :: ModInt -> [Int] -> ModInt
solve k a = (k * (k-1)/2) * largers + inversion * k where
  count f xs = Mod $ length $ filter f xs
  inversion = snd $ foldl f ([],Mod 0) a
  f (xs,acc) e = (e:xs,acc + count (>e) xs)
  largers = go a' (Mod 0) (Mod 0)
  go (x:y:xs) n m
    | x == y = m + go (y:xs) (n+1) m
    | otherwise = m + go (y:xs) (n+1) (n+1)
  go (_:_) n m = m
  a' = sortBy (flip compare) a


modulo = 10^9+7

newtype ModInt = Mod Int deriving (Eq)

instance Show ModInt where
  show (Mod a) = show a
instance Bounded ModInt where
  maxBound = Mod $ modulo - 1
  minBound = 0
-- Caution! If (value>=modulo), this does not work.
instance Enum ModInt where
  toEnum a = Mod $ mod a modulo
  fromEnum (Mod a) = a
instance Num ModInt where
  (Mod a) + (Mod b) = Mod $ mod (a+b) modulo
  (Mod a) * (Mod b) = Mod $ mod (a*b) modulo
  abs = id
  signum = const 1
  fromInteger a = Mod $ fromIntegral $ mod a $ fromIntegral modulo
  negate 0 = 0
  negate (Mod a) = Mod $ modulo - a
instance Fractional ModInt where
  recip a = a ^ (modulo-2)
  fromRational r = Mod (n * signum d) / Mod (abs d) where
    [n,d] = [fromIntegral] <*> ( [numerator,denominator] <*> [r] )
