N = int(input())
S = input()
s = list(S)
r = 0
g = 0
b = 0
for i in range(N):
    if s[i] == 'R':
        r = r + 1
    if s[i] == 'G':
        g = g + 1
    if s[i] == 'B':
        b = b + 1
p = 0
for i in range(N-1):
    for j in range(i+1,N):
        if 2*j-i < N:
            if s[j+j-i] != s[i] and s[j+j-i] != s[j] and s[i] != s[j]:
                p = p+1
print(r*g*b-p)