#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n, k; cin >> n >> k; vector a; vector c(10); for (int i = 1; i <= 9; i++) { cin >> c[i]; for (int j = 0; j < c[i]; j++) { a.push_back(i); } } long long p10[20]; p10[0] = 1; for (int i = 1; i < 20; i++) { p10[i] = p10[i - 1] * 10 % k; } vector> dp(1 << n, vector(k)); dp[0][0] = 1; for (int st = 0; st < (1 << n); st++) { int next_i = __builtin_popcount(st); for (int j = 0; j < k; j++) { for (int l = 0; l < n; l++) { if (st & (1 << l)) { continue; } int next_j = (j + p10[l] * a[next_i]) % k; dp[st | (1 << l)][next_j] += dp[st][j]; } } } long long ans = dp.back()[0]; for (int i = 1; i < 10; i++) { for (int j = 2; j <= c[i]; j++) { assert(ans % j == 0); ans /= j; } } cout << ans << endl; }