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

cnt = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        nn = n-j
        if s[i] == s[j]:
            continue
        w = j - i
        if j+w < n and (s[j+w] != s[j] and s[j+w] != s[i]):
            cnt -= 1
        not_same = nn - (s[j:].count(s[i]) + s[j:].count(s[j]))
        cnt += not_same

print(cnt)
