ll e[40],d[],n,r;void f(ll a){if(n--)rep(i,9){if(d[i]--)f(10a+i);++d[i];}else r+=!e[a%40]++;++n;}{rd(n);rep(n){char@c;++d[c-49];}n