# coding: utf-8

import sys

from collections import Counter



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



# １の条件を満たすものを調べたのち、２の条件のものを引く

N = ir()

S = list(sr())

counter = Counter(S)

r = counter['R']

g = counter['G']

b = counter['B']

answer = r * g * b

for i in range(N-1):

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

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

            continue

        x = S[i]; y = S[j]; z = S[j+j-i]

        if x != y and y != z and z != x:

            answer -= 1



print(answer)

# coding: utf-8

import sys

from collections import Counter



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N = ir()

S = sr()

counter = Counter(S)

r = counter['R']; g = counter['G']; b = counter['B']

answer = r * g * b

for i in range(N):

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

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

            continue

        diff = j - i

        if j + diff >= N:

            break

        x = S[i]; y = S[j]

        z = S[j+diff]

        if x != z and y != z:

            answer -= 1



print(answer)

# coding: utf-8
import sys
from collections import Counter

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# １の条件を満たすものを調べたのち、２の条件のものを引く
N = ir()
S = list(sr())
counter = Counter(S)
r = counter["R"]
g = counter["G"]
b = counter["B"]
answer = r * g * b
for i in range(N - 1):
    for j in range(i + 1, N):
        if j + (j - i) >= N:
            continue
        x = S[i]
        y = S[j]
        z = S[j + j - i]
        if x != y and y != z and z != x:
            answer -= 1
print(answer)

# coding: utf-8
import sys
from collections import Counter

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
S = sr()
counter = Counter(S)
r = counter["R"]
g = counter["G"]
b = counter["B"]
answer = r * g * b
for i in range(N):
    for j in range(i + 1, N):
        if S[i] == S[j]:
            continue
        diff = j - i
        if j + diff >= N:
            break
        x = S[i]
        y = S[j]
        z = S[j + diff]
        if x != z and y != z:
            answer -= 1
print(answer)

-# １の条件を満たすものを調べたのち、２の条件のものを引く -S = list(sr()) +S = sr() -for i in range(N - 1): +for i in range(N): -        if j + (j - i) >= N: +        if S[i] == S[j]: +        diff = j - i +        if j + diff >= N: +            break -        z = S[j + j - i] -        if x != y and y != z and z != x: +        z = S[j + diff] +        if x != z and y != z: