import copy import sys sys.setrecursionlimit(1000000) from functools import lru_cache def main(): N,K = map(int,input().split()) #global K C = list(map(int,input().split())) #A = [] #for i in range(N): # for j in range(C[i]): # A.append(i+1) #print(A) MAX = 200000 popcount = [0]*MAX for i in range(1,MAX): popcount[i] = popcount[i//2] + i%2 @lru_cache(maxsize=None) def solve(X): #Xというタプルまで見た時次の遷移 X = list(X) pcnt = 0 for a in X: pcnt += a if pcnt == 0: ret = [0]*K ret[0] = 1 return ret base = pow(10,pcnt-1) ret = [0]*K for i in range(9): if X[i] >= 1: val = base*(i+1) TX = copy.copy(X) TX[i] -= 1 TX = tuple(TX) for i in range(K): temp = solve(TX) ret[(i+val)%K] += temp[i] #print(X,ret) return ret d = solve(tuple(C)) print(d[0]) exit() #print(popcount) #dp[mask][j]:maskを使った時の余りがj dp = [[0]*(K) for _ in range(1<>i)&1 == 1: continue #既に含まれている val = A[i]*base%K for j in range(K): print(mask|1<