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