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