n = int(input())
if n < 3:
print(0)
else:
s = input()
dp = [{} for i in range(n)] # dp[i]记录i之后各个字母出现的次数
ans = 0
for i in range(n-2, -1, -1):
dp[i] = dp[i + 1].copy()
key = s[i + 1]
val = dp[i+1].get(key, 0) + 1
dp[i][key] = val
for i in range(n - 3, -1, -1):
for key, val in dp[i].items(): # 和字母i不同且在之后出现超过两次
if key != s[i] and val >= 2:
ans += val * (val - 1) // 2
print(ans)