#include #include #include #include int limit,a,b; std::vector V,V1,V2; std::map M,check1,check2; long long int P[110]; long long int ans = 0; void func(int k) { if(k>=a) { if(V1.size()!=limit) return; M.clear(); check2.clear(); std::vector W1 = V1, W2 = V2; std::sort(W1.begin(),W1.end()); std::sort(W2.begin(),W2.end()); do{ long long int sum = 0; for(int i=0;i0) continue; check1[sum] = 1; M[sum%b]++; }while(std::next_permutation(W1.begin(),W1.end())); do{ long long int sum = 0; for(int i=limit;i0) continue; check2[sum] = 1; ans += M[(b-sum%b)%b]; }while(std::next_permutation(W2.begin(),W2.end())); return; } V1.push_back(V[k]); func(k+1); V1.pop_back(); V2.push_back(V[k]); func(k+1); V2.pop_back(); } int c[110]; int main() { scanf("%d%d",&a,&b); for(int i=1;i<=9;i++) scanf("%d",&c[i]); if(a==1) { for(int i=1;i<=9;i++) { if(c[i]==1) { if(i%b==0) printf("1"); else printf("0"); return 0; } } } for(int i=1;i<=9;i++) while(c[i]--) V.push_back(i); P[0] = 1; for(int i=1;i