N = int(eval(input()))

S = list(str(eval(input())))

from collections import Counter



c = Counter(S)

ans = c['B']*c['G']*c['R']

for i in range(N-1):

    for j in range(i, N):

        if S[i]==S[j]:

            continue

        elif i+(j-i)*2>N-1:

            break

        s = S[i+(j-i)*2]

        if s!=S[i] and s!=S[j]:

            ans -= 1

print(ans)
import sys

def input(): return sys.stdin.readline().strip()

def mapint(): return list(map(int, input().split()))

sys.setrecursionlimit(10**9)



N = int(eval(input()))

S = list(eval(input()))

from collections import Counter



c = Counter(S)

ans = c['R']*c['G']*c['B']



for i in range(1, N):

    for j in range(N):

        first, second, third = j, j+i, j+i*2

        if third>=N:

            break

        if len(set((S[first], S[second], S[third])))==3:

            ans -= 1



print(ans)
N = int(eval(input()))
S = list(str(eval(input())))
from collections import Counter

c = Counter(S)
ans = c["B"] * c["G"] * c["R"]
for i in range(N - 1):
    for j in range(i, N):
        if S[i] == S[j]:
            continue
        elif i + (j - i) * 2 > N - 1:
            break
        s = S[i + (j - i) * 2]
        if s != S[i] and s != S[j]:
            ans -= 1
print(ans)

import sys


def input():
    return sys.stdin.readline().strip()


def mapint():
    return list(map(int, input().split()))


sys.setrecursionlimit(10**9)
N = int(eval(input()))
S = list(eval(input()))
from collections import Counter

c = Counter(S)
ans = c["R"] * c["G"] * c["B"]
for i in range(1, N):
    for j in range(N):
        first, second, third = j, j + i, j + i * 2
        if third >= N:
            break
        if len(set((S[first], S[second], S[third]))) == 3:
            ans -= 1
print(ans)

+import sys + + +def input(): +    return sys.stdin.readline().strip() + + +def mapint(): +    return list(map(int, input().split())) + + +sys.setrecursionlimit(10**9) -S = list(str(eval(input()))) +S = list(eval(input())) -ans = c["B"] * c["G"] * c["R"] -for i in range(N - 1): -    for j in range(i, N): -        if S[i] == S[j]: -            continue -        elif i + (j - i) * 2 > N - 1: +ans = c["R"] * c["G"] * c["B"] +for i in range(1, N): +    for j in range(N): +        first, second, third = j, j + i, j + i * 2 +        if third >= N: -        s = S[i + (j - i) * 2] -        if s != S[i] and s != S[j]: +        if len(set((S[first], S[second], S[third]))) == 3: