import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import qualified Data.IntMap as IM
import Data.List

bsReadInts = map (fst . fromJust . B.readInt) . B.words

solve n m as = sum $ map g $ IM.toList im
  where
    g (_,c) = (c*(c-1)) `div` 2
    accs = scanl' op 0 as
      where op a1 a2 = (a1 + a2) `mod` m
    im = foldr (IM.alter f) IM.empty accs
      where f Nothing = Just 1
            f (Just a) = Just (a+1)

tmain cont =
  let n : m : as = bsReadInts cont
  in solve n m as

main = putStrLn . show . tmain =<< B.getContents
