import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
import Debug.Trace

main :: IO ()
main = breads >>= main'
    where
        main' [n, m] = breads >>= print . solve n m

solve :: Int -> Int -> [Int] -> Int 
solve n m as = foldl' count 0 [(l, r) | l <- [1..n], r <- [l..n]]
    where
        count acc (l, r)
            | val (vs V.! r - vs V.! (l - 1)) == 0 = acc + 1
            | otherwise = acc 

        vs = V.fromList ss
        ss = traceShowId . scanl (\l r -> val $ l + r) 0 $ map val as
        val = (`mod` m)

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine