#include #include #include using namespace std; using ll = long long; #include int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll n,k; cin>>n>>k; vector c(10,0); for(int i = 1;i<=9;i++) cin>>c[i]; if(n==1){ int ans = 0; for(int i = 1;i<=9;i++) if(i%k==0) ans += c[i]; cout< a,b; ll now = 1; for(int i = 0;i,map> m1,m2; vector use(10,0); ll ans = 0; auto calc = [&](vector&now) { vector all; for(int i = 1;i<=9;i++) for(int j = 0;j void { if(res==0){ calc(use); return; } for(int i = ni;i<=9;i++){ if(c[i]==0) continue; c[i]--; use[i]++; dfs(dfs,i,res-1); use[i]--; c[i]++; } }; dfs(dfs,1,a.size()); swap(a,b); swap(m1,m2); dfs(dfs,1,a.size()); for(auto itr:m1){ auto use = itr.first; vector want(10,0); for(int i = 1;i<=9;i++) want[i] = c[i] - use[i]; auto now = m2[want]; for(auto nn:itr.second){ ll w = k - nn.first; w %= k; if(w<0) w += k; ans += nn.second * now[w]; } } cout<