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