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