import Control.Applicative ((<$>))
import Data.List

main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine :: IO [Integer]
  as <- map read . words <$> getLine :: IO [Integer]
  let
    ss = map (`mod` m) $ scanl1 (+) as
    cs = map (\i -> (head i,genericLength i)) $ group $ sort ss

  print $ sum $ map (\(i,c) -> c*(c-1)`div`2 + (if i == 0 then c else 0)) cs