#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); } } vector> dp(1 << N, vector(K, 0)); dp[0][0] = 1; for (int i = 0; i < (1 << N); i++){ for (int j = 0; j < K; j++){ for (int k = 0; k < N; k++){ if ((i >> k & 1) == 0){ int i2 = i | (1 << k); int j2 = (j * 10 + A[k]) % K; dp[i2][j2] += dp[i][j]; } } } } long long ans = dp[(1 << N) - 1][0]; for (int i = 1; i < 10; i++){ for (int j = 1; j <= c[i]; j++){ ans /= j; } } cout << ans << endl; }