import Control.Monad
import Data.List
import Data.Maybe
import Data.Bits
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as B

query :: Int -> [Int] -> Int
query m = sum . map ((\n -> (n * (n-1)) `div` 2)) . M.elems
  . foldl (\m i -> M.insertWith (+) i 1 m) M.empty
  . scanl' (\x y -> (x + y) `mod` m) 0 

main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine
  ais <- unfoldr (B.readInt . B.dropWhile (=' ')) <$> B.getLine
  putStrLn $ show $ query m ais