from collections import defaultdict from itertools import permutations dic = defaultdict(int) N = int(input()) S = input() sum0 = 0 for s in S: s = int(s) dic[s] += 1 sum0 += s X = [] for k, v in dic.items(): X += [k] * (min(3, v)) Y = set() for a, b, c in set(permutations(X, 3)): y = a * 100 + b * 10 + c + 40 * ((sum0 - a - b - c) % 3) y %= 120 Y.add(y) print(len(Y))