import sys

import collections



N = int(eval(input()))

S = [ch for ch in eval(input())]

counter = collections.Counter(S)

if len(list(counter.keys())) != 3:

    print((0))

    sys.exit()

total = 1

for k, v in list(counter.items()):

    total *= v



for i in range(len(S)):

    l, r = i - 1, i + 1

    while 0 <= l and r < len(S):

        if len(set([S[i], S[l], S[r]])) == 3:

            total -= 1

        l -= 1

        r += 1

print(total)
from collections import defaultdict



N = int(eval(input()))

S = eval(input())

counter = defaultdict(int)

for s in S:

    counter[s] += 1

total = counter["R"] * counter["G"] * counter["B"]

for i in range(N):

    for j in range(i, N):

        k = j + (j - i)

        if k >= N:

            break

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

            total -= 1

print(total)
import sys
import collections

N = int(eval(input()))
S = [ch for ch in eval(input())]
counter = collections.Counter(S)
if len(list(counter.keys())) != 3:
    print((0))
    sys.exit()
total = 1
for k, v in list(counter.items()):
    total *= v
for i in range(len(S)):
    l, r = i - 1, i + 1
    while 0 <= l and r < len(S):
        if len(set([S[i], S[l], S[r]])) == 3:
            total -= 1
        l -= 1
        r += 1
print(total)

from collections import defaultdict

N = int(eval(input()))
S = eval(input())
counter = defaultdict(int)
for s in S:
    counter[s] += 1
total = counter["R"] * counter["G"] * counter["B"]
for i in range(N):
    for j in range(i, N):
        k = j + (j - i)
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            total -= 1
print(total)

-import sys -import collections +from collections import defaultdict -S = [ch for ch in eval(input())] -counter = collections.Counter(S) -if len(list(counter.keys())) != 3: -    print((0)) -    sys.exit() -total = 1 -for k, v in list(counter.items()): -    total *= v -for i in range(len(S)): -    l, r = i - 1, i + 1 -    while 0 <= l and r < len(S): -        if len(set([S[i], S[l], S[r]])) == 3: +S = eval(input()) +counter = defaultdict(int) +for s in S: +    counter[s] += 1 +total = counter["R"] * counter["G"] * counter["B"] +for i in range(N): +    for j in range(i, N): +        k = j + (j - i) +        if k >= N: +            break +        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]: -        l -= 1 -        r += 1