from itertools import permutations n = int(input()) s = input() if n <= 3: ans = set() for i in permutations(s): ans.add(int(''.join(i)) % 120) print(len(ans)) exit() A = [0 for _ in range(10)] for i in s: A[int(i)] += 1 ans = 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: ans.add((c * 100 + b * 10 + a) % 40) A[a] += 1 A[b] += 1 A[c] += 1 print(len(ans))