import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.List

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

readInts :: IO [Int]
readInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine

solve :: Int -> [Int] -> Int
solve m = sum
    . map (\x -> x * (x - 1) `div` 2)
    . map length
    . group
    . sort
    . map (`mod` m)
    . scanl' (+) 0