#include using namespace std; int dp[1 << 14][14][1000]; int main() { int N,K; cin >> N >> K; vectortmp(N); tmp[0] = 1%K; for(int i = 1; i < N; i++) { tmp[i] = tmp[i-1]*10%K; } dp[0][0][0] = 1; int cnt = 0; for(int i = 1; i <= 9; i++) { int a; cin >> a; for(int j = 0; j < a; j++) { for(int k = 0; k < (1 << N); k++) { if(__builtin_popcount(k) != cnt) { continue; } for(int l = 0; l < N; l++) { for(int o = 0; o < K; o++) { for(int m = l; m < N; m++) { if(1 & (k >> m)) { continue; } if(j+1 == a) { dp[k|(1 << m)][0][(o+tmp[m]*i)%K] += dp[k][l][o]; } else if(m+1 < N) { dp[k|(1 << m)][m+1][(o+tmp[m]*i)%K] += dp[k][l][o]; } } } } } cnt++; } } cout << dp[(1 << N)-1][0][0] << endl; }