#include using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N, K; cin >> N >> K; vector c(10); for (int i = 1; i < 10; ++i) cin >> c[i]; map, vector> cnt; cnt[c] = vector(K); cnt[c][0] = 1; queue> que; que.push(c); while (!que.empty()) { auto v = que.front(); auto u = v; que.pop(); for (int i = 1; i < 10; ++i) { if (u[i] == 0) continue; --u[i]; if (!cnt.count(u)) { cnt[u] = vector(K); que.push(u); } for (int r = 0; r < K; ++r) { int n = (10 * r + i) % K; cnt[u][n] += cnt[v][r]; } ++u[i]; } } cout << cnt[vector(10)][0] << endl; }