def next_permutation(P): n = len(P) for i in range(n - 2, -1, -1): if P[i] < P[i + 1]: l = i + 1 r = n - 1 while r > l: P[l], P[r] = P[r], P[l] l += 1 r -= 1 for j in range(i + 1, n): if P[i] < P[j]: P[i], P[j] = P[j], P[i] return True return False def all_permutations(P): # 全列挙したい場合はソートしてある状態で渡す yield P while next_permutation(P): yield P def prev_permutation(P): n = len(P) for i in range(n - 2, -1, -1): if P[i] > P[i + 1]: l = i + 1 r = n - 1 while r > l: P[l], P[r] = P[r], P[l] l += 1 r -= 1 for j in range(i + 1, n): if P[i] > P[j]: P[i], P[j] = P[j], P[i] return True return False def rev_all_permutations(P): # 全列挙したい場合は逆順ソートしてある状態で渡す yield P while prev_permutation(P): yield P n = int(input()) S = list(map(int, input())) if n <= 3: tf = [False] * 120 S.sort() for P in all_permutations(S): tot = 0 for p in P: tot = tot * 10 + p tf[tot % 120] = True print(sum(tf)) else: cnt = [0] * 10 for s in S: cnt[s] += 1 tf = [False] * 40 for i in range(1, 10): if cnt[i] == 0: continue cnt[i] -= 1 for j in range(1, 10): if cnt[j] == 0: continue cnt[j] -= 1 for k in range(1, 10): if cnt[k] == 0: continue x = i * 100 + j * 10 + k tf[x % 40] = True cnt[j] += 1 cnt[i] += 1 print(sum(tf))