#include #include int main() { int N, K; std::cin >> N >> K; std::vector X(N, 0); int ct = 0; int div = 1; for (int i = 1; i < 10; i++) { int c; std::cin >> c; for (int j = 1; j <= c; j++) { div *= j; } for (int j = 0; j < c; j++) { X.at(ct) = i; ct++; } } std::vector> A(1 << N, std::vector(K)); A.at(0).at(0) = 1; for (int b = 0; b < 1 << N; b++) { for (int i = 0; i < N; i++) { if (!(b & (1 << i))) { int c = b | (1 << i); for (int k = 0; k < K; k++) { int next_k = (k * 10 + X.at(i)) % K; A.at(c).at(next_k) += A.at(b).at(k); } } } } std::cout << A.at((1 << N) - 1).at(0) / div << std::endl; }