n = int(input())
s = input()

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if j - i == k - j:
                continue
            elif s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                ans += 1
print(ans)