split :: String -> String -> [String]
split _ "" = [""]
split t (s:sr)
  |t == [s] = [] : (split t sr)
  |otherwise = (s : (head (split t sr))) : (tail (split t sr))

search :: (Eq a) => a -> [a] -> Bool
search _ [] = False
search f (h:t)
  |(f == h) = True
  |otherwise = search f t

cul :: Int -> Int -> [Int] -> Int
cul 0 0 _ = 1
cul n s l
  |(n * s) == 0 = 0
  |otherwise = sum [cul (n - 1) (s - x * n) (x : l) | x <- [0..9], not (search x l)]

chomp :: [a] -> [a]
chomp (x:[]) = []
chomp (x:xr) = x : (chomp xr)

main = do
  input <- getContents
  mapM_ (\l -> print ((\n -> cul (head n) (head (tail n)) [] ) ((map (\n -> (read n) :: Int) (split " " l))))) (split "\n" (chomp input))