import qualified Data.IntMap as M

main :: IO ()
main = do
    [_, m] <- readInts
    as <- readInts
    print $ solve m as

readInts :: IO [Int]
readInts = map read . words <$> getLine

solve :: Int -> [Int] -> Int
solve m =  M.foldr (\x y -> (x * (x - 1) `div` 2) + y) 0
     . foldr (M.alter $ return . maybe 1 succ)  M.empty
     . map (`mod` m)
     . scanl (+) 0
