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

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

readInts :: B.ByteString -> [Int]
readInts = map readInt . B.split 0x20

readInt :: B.ByteString -> Int
readInt xs
    | B.null xs = 0
    | y == 0x20 = 0
    | otherwise = (fromIntegral y - 0x30) + 10 * readInt ys
    where Just (ys, y) = B.unsnoc xs

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