from collections import Counter from copy import deepcopy N=int(input()) S=input().strip() C=Counter(S) Q=[(C,0,0)] ANS=[0]*120 while Q: #print(Q) x,keta,mod=Q.pop() if keta==5 or max(x.values())==0: count=0 for i in range(10): count+=x[str(i)]*int(i) ANS[(mod+40*count)%120]=1 continue for i in range(10): if x[str(i)]>0: x[str(i)]-=1 Q.append((deepcopy(x),keta+1,(mod+int(i)*(10**keta))%120)) x[str(i)]+=1 print(sum(ANS))