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

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 =  M.foldl' (+) 0
     . fmap (\x -> x * (x - 1) `div` 2)
     . foldr (\k mp -> M.insertWith (+) k 1 mp)  M.empty
     . map (`mod` m)
     . scanl' (+) 0
