#include #include #include using namespace std; typedef long long LL; const int N = 1<<14; LL f[N][400]; int cnt[12]; int a[N]; int main(){ int n,m; scanf("%d%d",&n,&m); LL ttt=1,tot=0; for(int i=1;i<=9;i++){ scanf("%d",&cnt[i]); LL tt=1; for(int j=1;j<=cnt[i];j++){ tt=tt*j; a[++tot]=i; } ttt=tt*ttt; } f[0][0]=1; for(int i=0;i<(1<>k&1)continue; int t=j*10+a[k+1]; t%=m; f[i|(1<