#include using namespace std; int dp[1 << 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] = 1; int cnt = 0; for(int i = 1; i <= 9; i++) { int a; cin >> a; cnt += a; if(a == 0) { continue; } for(int j = 0; j < (1 << N); j++) { if(__builtin_popcount(j) != cnt) { continue; } vectorres; for(int k = 0; k < N; k++) { if(1 & (j >> k)) { res.push_back(k); } } for(int k = 0; k < (1 << res.size()); k++) { if(__builtin_popcount(k) != a) { continue; } long long sum = 0; int old = j; for(int l = 0; l < res.size(); l++) { if(1 & (k >> l)) { old -= (1 << res[l]); sum += tmp[res[l]]*i; } } sum %= K; for(int l = 0; l < K; l++) { dp[j][(l+sum)%K] += dp[old][l]; } } } } cout << dp[(1 << N)-1][0] << endl; }