from collections import Counter, deque

N = int(input())
S = deque(input())
s_c = Counter(S)

a = s_c["R"] * s_c["B"] * s_c["G"]

for i in range(N):
    for j in range(i + 1, N):
        for _ in range(j + 1, N):
            if (S[i] != S[j] and S[i] != S[_] and S[j] != S[_]) and \
                not (j - i != _ - j):
                a -= 1
print(a)