import bisect

import sys

input=sys.stdin.readline

def main():

    N=int(eval(input()))

    S=input().rstrip()

    R,G,B=[],[],[]

    for i in range(N):

        if S[i]=='R':

            R.append(i)

        elif S[i]=='G':

            G.append(i)

        elif S[i]=='B':

            B.append(i)

    ans=0

    for i in range(N):

        for j in range(i):

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

                continue

            s=set([S[i],S[j]])

            if('B' not in s):

                lon=len(B)-bisect.bisect_left(B,i)

                mi=bisect.bisect_left(B,i+i-j)

                if(mi<len(B) and B[mi]==i*2-j):

                    lon-=1

            elif('R' not in s):

                lon=len(R)-bisect.bisect_left(R,i)

                mi=bisect.bisect_left(R,i+i-j)

                if(mi<len(R) and R[mi]==i*2-j):

                    lon-=1

            elif('G' not in s):

                lon=len(G)-bisect.bisect_left(G,i)

                mi=bisect.bisect_left(G,i+i-j)

                if(mi<len(G) and G[mi]==i*2-j):

                    lon-=1

            ans+=lon

        

    print(ans)

    

if __name__=='__main__':

    main()
N=int(eval(input()))

S=eval(input())

R,G,B=0,0,0

for i in range(N):

    if(S[i]=='R'):

        R+=1

    elif(S[i]=='G'):

        G+=1

    else:

        B+=1

res=R*G*B

cnt=0

for i in range(N):

    lr=0

    while(i-lr>=0 and i+lr<N):

        s=set([S[i],S[i-lr],S[i+lr]])

        if(len(s)==3):

            res-=1

        lr+=1

print(res)
import bisect
import sys

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    S = input().rstrip()
    R, G, B = [], [], []
    for i in range(N):
        if S[i] == "R":
            R.append(i)
        elif S[i] == "G":
            G.append(i)
        elif S[i] == "B":
            B.append(i)
    ans = 0
    for i in range(N):
        for j in range(i):
            if S[i] == S[j]:
                continue
            s = set([S[i], S[j]])
            if "B" not in s:
                lon = len(B) - bisect.bisect_left(B, i)
                mi = bisect.bisect_left(B, i + i - j)
                if mi < len(B) and B[mi] == i * 2 - j:
                    lon -= 1
            elif "R" not in s:
                lon = len(R) - bisect.bisect_left(R, i)
                mi = bisect.bisect_left(R, i + i - j)
                if mi < len(R) and R[mi] == i * 2 - j:
                    lon -= 1
            elif "G" not in s:
                lon = len(G) - bisect.bisect_left(G, i)
                mi = bisect.bisect_left(G, i + i - j)
                if mi < len(G) and G[mi] == i * 2 - j:
                    lon -= 1
            ans += lon
    print(ans)


if __name__ == "__main__":
    main()

N = int(eval(input()))
S = eval(input())
R, G, B = 0, 0, 0
for i in range(N):
    if S[i] == "R":
        R += 1
    elif S[i] == "G":
        G += 1
    else:
        B += 1
res = R * G * B
cnt = 0
for i in range(N):
    lr = 0
    while i - lr >= 0 and i + lr < N:
        s = set([S[i], S[i - lr], S[i + lr]])
        if len(s) == 3:
            res -= 1
        lr += 1
print(res)

-import bisect -import sys - -input = sys.stdin.readline - - -def main(): -    N = int(eval(input())) -    S = input().rstrip() -    R, G, B = [], [], [] -    for i in range(N): -        if S[i] == "R": -            R.append(i) -        elif S[i] == "G": -            G.append(i) -        elif S[i] == "B": -            B.append(i) -    ans = 0 -    for i in range(N): -        for j in range(i): -            if S[i] == S[j]: -                continue -            s = set([S[i], S[j]]) -            if "B" not in s: -                lon = len(B) - bisect.bisect_left(B, i) -                mi = bisect.bisect_left(B, i + i - j) -                if mi < len(B) and B[mi] == i * 2 - j: -                    lon -= 1 -            elif "R" not in s: -                lon = len(R) - bisect.bisect_left(R, i) -                mi = bisect.bisect_left(R, i + i - j) -                if mi < len(R) and R[mi] == i * 2 - j: -                    lon -= 1 -            elif "G" not in s: -                lon = len(G) - bisect.bisect_left(G, i) -                mi = bisect.bisect_left(G, i + i - j) -                if mi < len(G) and G[mi] == i * 2 - j: -                    lon -= 1 -            ans += lon -    print(ans) - - -if __name__ == "__main__": -    main() +N = int(eval(input())) +S = eval(input()) +R, G, B = 0, 0, 0 +for i in range(N): +    if S[i] == "R": +        R += 1 +    elif S[i] == "G": +        G += 1 +    else: +        B += 1 +res = R * G * B +cnt = 0 +for i in range(N): +    lr = 0 +    while i - lr >= 0 and i + lr < N: +        s = set([S[i], S[i - lr], S[i + lr]]) +        if len(s) == 3: +            res -= 1 +        lr += 1 +print(res)