from numpy import prod

N = int(eval(input()))

S = eval(input())

appearances = {"R": 0, "G": 0, "B": 0}

for c in S:

    appearances[c] += 1

print((prod(list(appearances.values())) - sum(sum(len(set(S[start] + S[start + step] + S[start + step * 2])) == 3 for start in range(N - step * 2)) for step in range(1, N // 2 + 1))))

from functools import reduce

from operator import mul

N = int(eval(input()))

S = eval(input())

appearances = {"R": 0, "G": 0, "B": 0}

for c in S:

    appearances[c] += 1

print((reduce(mul, list(appearances.values())) - sum(sum(len(set(S[start] + S[start + step] + S[start + step * 2])) == 3 for start in range(N - step * 2)) for step in range(1, N // 2 + 1))))

from numpy import prod

N = int(eval(input()))
S = eval(input())
appearances = {"R": 0, "G": 0, "B": 0}
for c in S:
    appearances[c] += 1
print(
    (
        prod(list(appearances.values()))
        - sum(
            sum(
                len(set(S[start] + S[start + step] + S[start + step * 2])) == 3
                for start in range(N - step * 2)
            )
            for step in range(1, N // 2 + 1)
        )
    )
)

from functools import reduce
from operator import mul

N = int(eval(input()))
S = eval(input())
appearances = {"R": 0, "G": 0, "B": 0}
for c in S:
    appearances[c] += 1
print(
    (
        reduce(mul, list(appearances.values()))
        - sum(
            sum(
                len(set(S[start] + S[start + step] + S[start + step * 2])) == 3
                for start in range(N - step * 2)
            )
            for step in range(1, N // 2 + 1)
        )
    )
)

-from numpy import prod +from functools import reduce +from operator import mul -        prod(list(appearances.values())) +        reduce(mul, list(appearances.values()))