import           Data.Maybe
import           Data.List

main :: IO ()
main = do
    input <- getContents
    let [n, m] : list : _ = map read . words <$> lines input :: [[Int]]
    -- n*(n-1) `div` 2
    ( putStrLn
        . show
        . sum
        . map ((`div` 2) . (<*>) (*) ((-) 1))
        . map length
        . group
        . sort
        . map (`mod` m)
        . scanl (+) 0
        )
        list
