ll d[9],e[120],g[]={39,30,60},b=3,r;void f(ll a){if(b--)rep(i,9){if(d[i]--)f(a+(i+1)*g[b]);++d[i];}else r+=!e[a%120]++;++b;}{ll@n;rep(n){char@c;++d[c-49];}f(0);wt(r);}