#include using namespace std; int main(){ int N, K; cin >> N >> K; vector c(10); c[0] = 0; for (int i = 1; i < 10; i++){ cin >> c[i]; } vector A; for (int i = 1; i < 10; i++){ for (int j = 0; j < c[i]; j++){ A.push_back(i); } } int N1 = N / 2, N2 = (N + 1) / 2; long long P = 1; for (int i = 0; i < N2; i++){ P *= 10; } set, vector>> st; for (int i = 0; i < (1 << N); i++){ if (__builtin_popcount(i) == N1){ vector B1, B2; for (int j = 0; j < N; j++){ if ((i >> j & 1) == 1){ B1.push_back(A[j]); } else { B2.push_back(A[j]); } } st.insert(make_pair(B1, B2)); } } long long ans = 0; for (auto p : st){ vector B1 = p.first; vector B2 = p.second; map mp1; while (true){ int x = 0; for (int i = 0; i < N1; i++){ x = x * 10 + B1[i]; } mp1[x * P % K]++; if (!next_permutation(B1.begin(), B1.end())){ break; } } while (true){ int x = 0; for (int i = 0; i < N2; i++){ x = x * 10 + B2[i]; } int y = (K - x % K) % K; ans += mp1[y]; if (!next_permutation(B2.begin(), B2.end())){ break; } } } cout << ans << endl; }