import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(10 ** 7)



n = int(readline())

s = eval(input())

rgb = [0, 0, 0]

for i in range(n):

    if s[i] == 'R':

        rgb[0] += 1

    elif s[i] == 'G':

        rgb[1] += 1

    else:

        rgb[2] += 1

ans = rgb[0] * rgb[1] * rgb[2]

for i in range(n):

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

        k = 2 * j - i

        if k >= n:

            break

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

            ans -= 1

print(ans)

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(10 ** 7)



n = int(readline())

s = readline().rstrip().decode()

ans = s.count('R') * s.count('G') * s.count('B')

for i, si in enumerate(s):

    for j, sj in enumerate(s[i + 1:]):

        k = 2 * (j + 1) + i

        if k >= n:

            break

        if si != sj and si != s[k] and sj != s[k]:

            ans -= 1

print(ans)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
n = int(readline())
s = eval(input())
rgb = [0, 0, 0]
for i in range(n):
    if s[i] == "R":
        rgb[0] += 1
    elif s[i] == "G":
        rgb[1] += 1
    else:
        rgb[2] += 1
ans = rgb[0] * rgb[1] * rgb[2]
for i in range(n):
    for j in range(i + 1, n):
        k = 2 * j - i
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
            ans -= 1
print(ans)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
n = int(readline())
s = readline().rstrip().decode()
ans = s.count("R") * s.count("G") * s.count("B")
for i, si in enumerate(s):
    for j, sj in enumerate(s[i + 1 :]):
        k = 2 * (j + 1) + i
        if k >= n:
            break
        if si != sj and si != s[k] and sj != s[k]:
            ans -= 1
print(ans)

-s = eval(input()) -rgb = [0, 0, 0] -for i in range(n): -    if s[i] == "R": -        rgb[0] += 1 -    elif s[i] == "G": -        rgb[1] += 1 -    else: -        rgb[2] += 1 -ans = rgb[0] * rgb[1] * rgb[2] -for i in range(n): -    for j in range(i + 1, n): -        k = 2 * j - i +s = readline().rstrip().decode() +ans = s.count("R") * s.count("G") * s.count("B") +for i, si in enumerate(s): +    for j, sj in enumerate(s[i + 1 :]): +        k = 2 * (j + 1) + i -        if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]: +        if si != sj and si != s[k] and sj != s[k]: