import Data.List
import Data.Array
import Data.Array.IO
import Data.Maybe
import Data.Bits
import qualified Data.Map as Map 
import Control.Monad
import Control.Applicative

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

listToTuple2 (a:b:_) = (a,b)
listToTuple3 (a:b:c:_) = (a,b,c)
listToTuple4 (a:b:c:d:_) = (a,b,c,d)

main :: IO ()
main = do
  (n:m:_) <- getLine >>= return . map read . words :: IO [Integer]
  as <- getLine >>= return . map read . words :: IO [Integer]

  let
    buildHashmap [] = Map.empty
    buildHashmap (x:xs) = if isNothing lkup then Map.insert x 1 next else Map.insert x (fromJust lkup + 1) next
      where
        next = buildHashmap xs
        lkup = Map.lookup x next


  print $ sum $ map (\a -> a*(a-1)`div`2) (Map.elems $ buildHashmap (map (`mod` m) (scanl (+) 0 as)))

