N=int(eval(input()))

S=eval(input())

M=[0 if s=='R' else 1 if s=='G' else 2 for s in S]



C = [[0] * (N+1) for _ in range(3)]

for i in range(N-1,-1,-1):

    for j in range(3):

        C[j][i] = C[j][i+1]+1 if M[i]==j else C[j][i+1]



ans=0

for i in range(N):

    for j in range(i+1,N):

        if M[i]==M[j]: continue

        k=3-M[i]-M[j]

        ans+=C[k][j+1]

        if j+(j-i) < N and M[j+(j-i)]==k: ans-=1

print(ans)

N=int(eval(input()))

S=eval(input())

from collections import Counter

C=Counter(S)

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

for i in range(N):

    for j in range(i+1,N):

        if j+(j-i) >= N: break

        if S[i] != S[j] and S[j] != S[j+(j-i)] and S[i] != S[j+(j-i)]:

            ans-=1

print(ans)
N = int(eval(input()))
S = eval(input())
M = [0 if s == "R" else 1 if s == "G" else 2 for s in S]
C = [[0] * (N + 1) for _ in range(3)]
for i in range(N - 1, -1, -1):
    for j in range(3):
        C[j][i] = C[j][i + 1] + 1 if M[i] == j else C[j][i + 1]
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        if M[i] == M[j]:
            continue
        k = 3 - M[i] - M[j]
        ans += C[k][j + 1]
        if j + (j - i) < N and M[j + (j - i)] == k:
            ans -= 1
print(ans)

N = int(eval(input()))
S = eval(input())
from collections import Counter

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

-M = [0 if s == "R" else 1 if s == "G" else 2 for s in S] -C = [[0] * (N + 1) for _ in range(3)] -for i in range(N - 1, -1, -1): -    for j in range(3): -        C[j][i] = C[j][i + 1] + 1 if M[i] == j else C[j][i + 1] -ans = 0 +from collections import Counter + +C = Counter(S) +ans = C["R"] * C["G"] * C["B"] -        if M[i] == M[j]: -            continue -        k = 3 - M[i] - M[j] -        ans += C[k][j + 1] -        if j + (j - i) < N and M[j + (j - i)] == k: +        if j + (j - i) >= N: +            break +        if S[i] != S[j] and S[j] != S[j + (j - i)] and S[i] != S[j + (j - i)]: