#include #include #include #include #include #include #include #include #include #include #define mkp make_pair #define mkt make_tuple #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; template void chmin(T &a, const T &b) { if (a > b) a = b; } template void chmax(T &a, const T &b) { if (a < b) a = b; } void add(ll &a, ll b) { a = (a + b) % MOD; } void mul(ll &a, ll b) { a %= MOD; b %= MOD; a = a * b % MOD; } const int L = 10; void solve() { int N, K; cin >> N >> K; vector C(L, 0); for (int i = 1; i < L; i++) cin >> C[i]; map, int>, ll> mdp; mdp[mkp(C, 0)] = 1; for (int i = 0; i < N; i++) { map, int>, ll> n_mdp; for (auto [key, val] : mdp) { auto [ds, rem] = key; for (int k = 1; k < L; k++) { if (ds[k] == 0) continue; ds[k]--; int n_rem = (rem * 10 + k) % K; add(n_mdp[mkp(ds, n_rem)], val); ds[k]++; } } swap(mdp, n_mdp); } ll ans = mdp[mkp(vector(L, 0), 0)]; cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }