n = int(input()) s = list(input().rstrip()) ans = 0 import string for a in string.ascii_uppercase: for b in string.ascii_uppercase: for c in string.ascii_uppercase: for d in string.ascii_uppercase: if a == b or a == c or a == d or b == c or b == d or c == d:continue temp = [0 for j in range(5)] for i in s: if i == a: temp[2] += temp[1] temp[0] += 1 if i == b: temp[1] += temp[0] if i == c: temp[3] += temp[2] if i == d: temp[4] += temp[3] ans += temp[-1] print(ans)