import Data.Int
import Data.List

iogetints :: IO [Int]
iogetints = do 
	s <- getLine
	return $ map read $ words s

solve :: Int -> [Int] -> Int64
solve m xs = ans where
	p = map (\x -> (x `mod` m)) $ scanl1 (+) $ map fromIntegral xs
	ans = (sum $ map ((\x -> x * (pred x) `div` 2) . fromIntegral . length) $ group $ sort p) + (fromIntegral $ length $ filter (== 0) p)

main :: IO ()
main = do
	[n, m] <- iogetints
	a <- iogetints
	print $ solve m a