import bisect

import itertools



n = int(eval(input()))

s = eval(input())



RGB = [[], [], []]

for i in range(n):

    if s[i] == 'R':

        RGB[0].append(i)

    elif s[i] == 'G':

        RGB[1].append(i)

    else:

        RGB[2].append(i)

total = len(RGB[0]) * len(RGB[1]) * len(RGB[2])

RGB.sort(key=lambda x:len(x))

len_B=len(RGB[2])

max_B=max(RGB[2])

min_B=min(RGB[2])

#for r in RGB[0]:

#    for g in RGB[1]:

bool_B=[False for i in range(n)]

for i in RGB[2]:

    bool_B[i]=True



for rg in itertools.product(RGB[0],RGB[1]):

    r=rg[0]

    g=rg[1]

    dif = abs(r - g)



    up = max(r,g)+dif

    down = min(r,g)-dif



    if max_B >=up:

        if bool_B[up]:

            total-=1

    if min_B <= down and max_B >= down:

        if bool_B[down]:

            total-=1

    if dif % 2 == 0:

        center = (r+g)//2

        if min_B<=center and max_B >= center:

            if bool_B[center]:

                total-=1

print(total)
import bisect

import itertools

 

n = int(eval(input()))

s = eval(input())

 

RGB = [[], [], []]

for i in range(n):

    if s[i] == 'R':

        RGB[0].append(i)

    elif s[i] == 'G':

        RGB[1].append(i)

    else:

        RGB[2].append(i)

total = len(RGB[0]) * len(RGB[1]) * len(RGB[2])

RGB.sort(key=lambda x:len(x))

len_B=len(RGB[2])

max_B=max(RGB[2])

min_B=min(RGB[2])

#for r in RGB[0]:

#    for g in RGB[1]:

for rg in itertools.product(RGB[0],RGB[1]):

    r=rg[0]

    g=rg[1]

    dif = abs(r - g)

 

    up = max(r,g)+dif

    down = min(r,g)-dif

    if max_B >=up:

        if RGB[2][bisect.bisect_left(RGB[2],up)]==up:

            total-=1

    if min_B <= down and max_B >= down:

        if RGB[2][bisect.bisect_left(RGB[2],down)]==down:

            total-=1

    if dif % 2 == 0:

        center = (r+g)/2

        center_posi=bisect.bisect_left(RGB[2], center)

        if center_posi < len_B:

            if RGB[2][center_posi]==center:

                total-=1

print(total)
import bisect
import itertools

n = int(eval(input()))
s = eval(input())
RGB = [[], [], []]
for i in range(n):
    if s[i] == "R":
        RGB[0].append(i)
    elif s[i] == "G":
        RGB[1].append(i)
    else:
        RGB[2].append(i)
total = len(RGB[0]) * len(RGB[1]) * len(RGB[2])
RGB.sort(key=lambda x: len(x))
len_B = len(RGB[2])
max_B = max(RGB[2])
min_B = min(RGB[2])
# for r in RGB[0]:
#    for g in RGB[1]:
bool_B = [False for i in range(n)]
for i in RGB[2]:
    bool_B[i] = True
for rg in itertools.product(RGB[0], RGB[1]):
    r = rg[0]
    g = rg[1]
    dif = abs(r - g)
    up = max(r, g) + dif
    down = min(r, g) - dif
    if max_B >= up:
        if bool_B[up]:
            total -= 1
    if min_B <= down and max_B >= down:
        if bool_B[down]:
            total -= 1
    if dif % 2 == 0:
        center = (r + g) // 2
        if min_B <= center and max_B >= center:
            if bool_B[center]:
                total -= 1
print(total)

import bisect
import itertools

n = int(eval(input()))
s = eval(input())
RGB = [[], [], []]
for i in range(n):
    if s[i] == "R":
        RGB[0].append(i)
    elif s[i] == "G":
        RGB[1].append(i)
    else:
        RGB[2].append(i)
total = len(RGB[0]) * len(RGB[1]) * len(RGB[2])
RGB.sort(key=lambda x: len(x))
len_B = len(RGB[2])
max_B = max(RGB[2])
min_B = min(RGB[2])
# for r in RGB[0]:
#    for g in RGB[1]:
for rg in itertools.product(RGB[0], RGB[1]):
    r = rg[0]
    g = rg[1]
    dif = abs(r - g)
    up = max(r, g) + dif
    down = min(r, g) - dif
    if max_B >= up:
        if RGB[2][bisect.bisect_left(RGB[2], up)] == up:
            total -= 1
    if min_B <= down and max_B >= down:
        if RGB[2][bisect.bisect_left(RGB[2], down)] == down:
            total -= 1
    if dif % 2 == 0:
        center = (r + g) / 2
        center_posi = bisect.bisect_left(RGB[2], center)
        if center_posi < len_B:
            if RGB[2][center_posi] == center:
                total -= 1
print(total)

-bool_B = [False for i in range(n)] -for i in RGB[2]: -    bool_B[i] = True -        if bool_B[up]: +        if RGB[2][bisect.bisect_left(RGB[2], up)] == up: -        if bool_B[down]: +        if RGB[2][bisect.bisect_left(RGB[2], down)] == down: -        center = (r + g) // 2 -        if min_B <= center and max_B >= center: -            if bool_B[center]: +        center = (r + g) / 2 +        center_posi = bisect.bisect_left(RGB[2], center) +        if center_posi < len_B: +            if RGB[2][center_posi] == center: