#include using namespace std; using ll=long long; using ull=unsigned long long; const ll MOD=1000000000+7; #define rep(I,N) for(int I=0;I; using vvec = vector>; ll lcm(ll a,ll b){ return a/__gcd(a,b)*b; } template void HorRot(vector>& v){ for(int i=0;i void DiaRot(vector>& v){ for(int i=0;i void Rot90(vector>& v){ HorRot(v); DiaRot(v); } int main(){ int n,k; cin >> n >> k; string s=""; int ans=0; rep(i,9){ int x; cin >> x; rep(j,x){ s=s+to_string(i+1); } } while(1){ if(stoll(s)%k==0)ans++; if(!next_permutation(ALL(s)))break; } printf("%d\n",ans); }