N = int(input()) S = input() if N <= 3: s = set() for i in permutations(S): s.add(int(''.join(i)) % 120) exit(print(len(s))) A = [0] * 10 for i in S: A[int(i)] += 1 s = set() for a in range(1, 10): for b in range(1, 10): for c in range(1, 10): A[a] -= 1 A[b] -= 1 A[c] -= 1 if A[a] >= 0 and A[b] >= 0 and A[c] >= 0: s.add((c * 100 + b * 10 + a) % 40) A[a] += 1 A[b] += 1 A[c] += 1 print(len(s))