ll@N,c[10]{},b[40]{};char@S[N];rep(i,N)c[S[i]-'0']++;REP(n,1d3){ll T[10]{};rep(d,3)T[n/10**d%10]++;b[n%40]|=AND[ll][i,0,10](T[i]<=c[i]);}wt(sum[i,0,40](b[i]));