N=int(eval(input()))

A=eval(input())

c=0

B1B=0

B1R=0

B1G=0

if A[0]=="B":

 B1B+=1

elif A[0]=="R":

 B1R+=1

else:

 B1G+=1

for i in range(N-2):

 B2=A[i+1]

 for k in range(N-i-2):

  B3=A[i+2+k]

  if (B2=="B" and B3=="R")or (B2=="R" and B3=="B"):

   c+=B1G

   if (i+2+k)<=(i+1)*2:

    if A[(i+1)*2-(i+2+k)]=="G":

     c-=1

  if (B2=="G" and B3=="R")or (B2=="R" and B3=="G"):

   c+=B1B

   if (i+2+k)<=(i+1)*2:

    if A[(i+1)*2-(i+2+k)]=="B":

     c-=1

  if (B2=="B" and B3=="G")or (B2=="G" and B3=="B"):

   c+=B1R

   if (i+2+k)<=(i+1)*2:

    if A[(i+1)*2-(i+2+k)]=="R":

     c-=1

 if B2=="B":

  B1B+=1

 elif B2=="R":

  B1R+=1

 else:

  B1G+=1

print(c)

N=int(eval(input()))

S=eval(input())

R=0

G=1

B=2

chk=[0]*N

lst=[[0 for e in range(3)] for f in range(N)]

if S[N-1]=="R":

 chk[N-1]=0

 lst[N-1][0]+=1

elif S[N-1]=="G":

 chk[N-1]=1

 lst[N-1][1]+=1

else:

 chk[N-1]=2

 lst[N-1][2]+=1

if N>=2:

 for i in range(1,N):

  lst[N-1-i][0]+=lst[N-i][0]

  lst[N-1-i][1]+=lst[N-i][1]

  lst[N-1-i][2]+=lst[N-i][2]

  if S[N-1-i]=="R":

   chk[N-1-i]=0

   lst[N-1-i][0]+=1

  elif S[N-1-i]=="G":

   chk[N-1-i]=1

   lst[N-1-i][1]+=1

  else:

   chk[N-1-i]=2

   lst[N-1-i][2]+=1

ans=0

if N<=2:

 print((0))

else:

 for i in range(N-2):

  for j in range(i+1,N-1):

   if chk[i]!=chk[j]:

    ans+=lst[j+1][3-chk[i]-chk[j]]

    if 2*j-i<=N-1:

     if chk[2*j-i]==3-chk[i]-chk[j]:

      ans-=1

print(ans)
N = int(eval(input()))
A = eval(input())
c = 0
B1B = 0
B1R = 0
B1G = 0
if A[0] == "B":
    B1B += 1
elif A[0] == "R":
    B1R += 1
else:
    B1G += 1
for i in range(N - 2):
    B2 = A[i + 1]
    for k in range(N - i - 2):
        B3 = A[i + 2 + k]
        if (B2 == "B" and B3 == "R") or (B2 == "R" and B3 == "B"):
            c += B1G
            if (i + 2 + k) <= (i + 1) * 2:
                if A[(i + 1) * 2 - (i + 2 + k)] == "G":
                    c -= 1
        if (B2 == "G" and B3 == "R") or (B2 == "R" and B3 == "G"):
            c += B1B
            if (i + 2 + k) <= (i + 1) * 2:
                if A[(i + 1) * 2 - (i + 2 + k)] == "B":
                    c -= 1
        if (B2 == "B" and B3 == "G") or (B2 == "G" and B3 == "B"):
            c += B1R
            if (i + 2 + k) <= (i + 1) * 2:
                if A[(i + 1) * 2 - (i + 2 + k)] == "R":
                    c -= 1
    if B2 == "B":
        B1B += 1
    elif B2 == "R":
        B1R += 1
    else:
        B1G += 1
print(c)

N = int(eval(input()))
S = eval(input())
R = 0
G = 1
B = 2
chk = [0] * N
lst = [[0 for e in range(3)] for f in range(N)]
if S[N - 1] == "R":
    chk[N - 1] = 0
    lst[N - 1][0] += 1
elif S[N - 1] == "G":
    chk[N - 1] = 1
    lst[N - 1][1] += 1
else:
    chk[N - 1] = 2
    lst[N - 1][2] += 1
if N >= 2:
    for i in range(1, N):
        lst[N - 1 - i][0] += lst[N - i][0]
        lst[N - 1 - i][1] += lst[N - i][1]
        lst[N - 1 - i][2] += lst[N - i][2]
        if S[N - 1 - i] == "R":
            chk[N - 1 - i] = 0
            lst[N - 1 - i][0] += 1
        elif S[N - 1 - i] == "G":
            chk[N - 1 - i] = 1
            lst[N - 1 - i][1] += 1
        else:
            chk[N - 1 - i] = 2
            lst[N - 1 - i][2] += 1
ans = 0
if N <= 2:
    print((0))
else:
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            if chk[i] != chk[j]:
                ans += lst[j + 1][3 - chk[i] - chk[j]]
                if 2 * j - i <= N - 1:
                    if chk[2 * j - i] == 3 - chk[i] - chk[j]:
                        ans -= 1
print(ans)

-A = eval(input()) -c = 0 -B1B = 0 -B1R = 0 -B1G = 0 -if A[0] == "B": -    B1B += 1 -elif A[0] == "R": -    B1R += 1 +S = eval(input()) +R = 0 +G = 1 +B = 2 +chk = [0] * N +lst = [[0 for e in range(3)] for f in range(N)] +if S[N - 1] == "R": +    chk[N - 1] = 0 +    lst[N - 1][0] += 1 +elif S[N - 1] == "G": +    chk[N - 1] = 1 +    lst[N - 1][1] += 1 -    B1G += 1 -for i in range(N - 2): -    B2 = A[i + 1] -    for k in range(N - i - 2): -        B3 = A[i + 2 + k] -        if (B2 == "B" and B3 == "R") or (B2 == "R" and B3 == "B"): -            c += B1G -            if (i + 2 + k) <= (i + 1) * 2: -                if A[(i + 1) * 2 - (i + 2 + k)] == "G": -                    c -= 1 -        if (B2 == "G" and B3 == "R") or (B2 == "R" and B3 == "G"): -            c += B1B -            if (i + 2 + k) <= (i + 1) * 2: -                if A[(i + 1) * 2 - (i + 2 + k)] == "B": -                    c -= 1 -        if (B2 == "B" and B3 == "G") or (B2 == "G" and B3 == "B"): -            c += B1R -            if (i + 2 + k) <= (i + 1) * 2: -                if A[(i + 1) * 2 - (i + 2 + k)] == "R": -                    c -= 1 -    if B2 == "B": -        B1B += 1 -    elif B2 == "R": -        B1R += 1 -    else: -        B1G += 1 -print(c) +    chk[N - 1] = 2 +    lst[N - 1][2] += 1 +if N >= 2: +    for i in range(1, N): +        lst[N - 1 - i][0] += lst[N - i][0] +        lst[N - 1 - i][1] += lst[N - i][1] +        lst[N - 1 - i][2] += lst[N - i][2] +        if S[N - 1 - i] == "R": +            chk[N - 1 - i] = 0 +            lst[N - 1 - i][0] += 1 +        elif S[N - 1 - i] == "G": +            chk[N - 1 - i] = 1 +            lst[N - 1 - i][1] += 1 +        else: +            chk[N - 1 - i] = 2 +            lst[N - 1 - i][2] += 1 +ans = 0 +if N <= 2: +    print((0)) +else: +    for i in range(N - 2): +        for j in range(i + 1, N - 1): +            if chk[i] != chk[j]: +                ans += lst[j + 1][3 - chk[i] - chk[j]] +                if 2 * j - i <= N - 1: +                    if chk[2 * j - i] == 3 - chk[i] - chk[j]: +                        ans -= 1 +print(ans)