N = int(input()) S = input() dat = [0] * 10 for s in S: dat[int(s)] += 1 ans = set() t = 0 for i in range(1,10): if dat[i]: dat[i] -= 1 else: continue for j in range(1,10): if dat[j]: dat[j] -= 1 else: continue for k in range(1,10): if dat[k]: dat[k] -= 1 else: continue t = i + 10 * j + 100 * k for u in range(1,10): t += u * dat[u] * 40 ans.add(t % 120) dat[k] += 1 dat[j] += 1 dat[i] += 1 print(len(ans))