renzoku :: [a] -> [[a]]
renzoku [] = [[]]
renzoku (x:xs) = (x:xs): renzoku xs
 
renzoku_l :: [a] -> [[a]]
renzoku_l [] = []
renzoku_l (x:xs) = [x] : (map (x:) (renzoku_l xs))
-- xyz -> x, xy, xyz
 
 
realRenzoku :: [a] -> [[a]]
realRenzoku s = renzoku_l =<< renzoku s
 
main = do
  [n,p] <- (map read) . words <$> getLine :: IO [Int]
  s <- getLine
  print $ length $ filter ( (==0). (`mod` p)) $ map read $ realRenzoku s
