{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Char
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as M
import Debug.Trace

solve :: Int -> Int -> VU.Vector Int -> Int
solve !n !m !an = sum $ map snd $ M.toList $ M.map
  (\i -> if i == 1 then 0 else comb2 i)
  modBnMaps
 where
  comb2 !n = n * (n - 1) `div` 2

  bn        = VU.tail $ VU.scanl' (+) 0 an

  modBnMaps = VU.foldl' (\(!mp) (!bi) -> M.insertWith (+) (bi `mod` m) 1 mp)
                        M.empty
                        (VU.cons (VU.head bn) bn)

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (n, m) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  an <- VU.unfoldrN n readInt <$> B.getLine
  print $ solve n m an
