Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
R=[]
G=[]
B=[]
count=1
for i in S:
    if i=="R":
        R.append(count)
    if i=="G":
        G.append(count)
    if i=="B":
        B.append(count)
    count+=1
x=0
for j in R:
    for k in G:
        if 2*j-k in B:
            x+=1
        if 2*k-j in B:
            x+=1
        if (k+j)/2==(k+j)//2 and (k+j)//2 in B:
            x+=1
print(len(R)*len(G)*len(B)-x)


    









        

    









    

        




    















    



    





    






        






    
















        


























            
    


    


    
    














    


    














Fixed submission:
N=int(input())
S=list(input())
S.insert(0,0)
R=S.count("R")
G=S.count("G")
B=S.count("B")
ans=R*G*B
for i in range(1,N-1):
    for j in range(i+1,N):
        k=2*j-i
        if k<N+1 and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N=int(input())
S=input()
R=deque()
G=deque()
B=deque()
count=1
for i in S:
    if i=="R":
        R.append(count)
    if i=="G":
        G.append(count)
    if i=="B":
        B.append(count)
    count+=1
ans=0
for j in R:
    for k in G:
        x=len(B)
        if 2*j-k in B:
            x-=1
        if 2*k-j in B:
            x-=1
        if (k+j)/2==(k+j)//2 and (k+j)//2 in B:
            x-=1
        ans+=x
print(ans)


    









        

    









    

        




    















    



    





    






        






    
















        


























            
    


    


    
    














    


    














Fixed submission:
N=int(input())
S=list(input())
S.insert(0,0)
R=S.count("R")
G=S.count("G")
B=S.count("B")
ans=R*G*B
for i in range(1,N-1):
    for j in range(i+1,N):
        k=2*j-i
        if k<N+1 and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
R=[]
G=[]
B=[]
count=1
for i in S:
    if i=="R":
        R.append(count)
    if i=="G":
        G.append(count)
    if i=="B":
        B.append(count)
    count+=1
ans=0
for j in R:
    for k in G:
        x=len(B)
        if 2*j-k in B:
            x-=1
        if 2*k-j in B:
            x-=1
        if (k+j)/2==(k+j)//2 and (k+j)//2 in B:
            x-=1
        ans+=x
print(ans)


    









        

    









    

        




    















    



    





    






        






    
















        


























            
    


    


    
    














    


    














Fixed submission:
N=int(input())
S=list(input())
S.insert(0,0)
R=S.count("R")
G=S.count("G")
B=S.count("B")
ans=R*G*B
for i in range(1,N-1):
    for j in range(i+1,N):
        k=2*j-i
        if k<N+1 and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
R=[]
G=[]
B=[]
ans=0
x=0
a=0
b=0
c=0
for i in S:
    if i=="R":
        R.append(x)
    if i=="G":
        G.append(x)
    if i=="B":
        B.append(x)
    x+=1
for j in R:
    for k in G:
        if 2*k-j in B:
            B.pop(B.index(2*k-j))
            a+=1
        if 2*j-k in B:
            B.pop(B.index(2*j-k))   
            b+=1
        if (j+k)/2 in B:
            B.pop(B.index((j+k)/2))
            c+=1
        ans+=len(B)
        if a!=0:
            B.append(2*k-j)
            a=0
        if b!=0:
            B.append(2*j-k)
            b=0
        if c!=0:
            B.append((j+k)/2)
            c=0
print(ans)

Fixed submission:
N=int(input())
S=list(input())
S.insert(0,0)
R=S.count("R")
G=S.count("G")
B=S.count("B")
ans=R*G*B
for i in range(1,N-1):
    for j in range(i+1,N):
        k=2*j-i
        if k<N+1 and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans-=1
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()
R=[]
G=[]
B=[]
ans=0
x=0
a=0
b=0
c=0
for i in S:
    if i=="R":
        R.append(x)
    if i=="G":
        G.append(x)
    if i=="B":
        B.append(x)
    x+=1
for j in R:
    for k in G:
        if 2*k-j in B:
            B.pop(B.index(2*k-j))
            a+=1
        if 2*j-k in B:
            B.pop(B.index(2*j-k))   
            b+=1
        if (j+k)/2 in B:
            B.pop(B.index((j+k)/2))
            c+=1
        count+=len(B)
        if a!=0:
            B.append(2*k-j)
            a=0
        if b!=0:
            B.append(2*j-k)
            b=0
        if c!=0:
            B.append((j+k)/2)
            c=0
print(ans)

Fixed submission:
N=int(input())
S=list(input())
S.insert(0,0)
R=S.count("R")
G=S.count("G")
B=S.count("B")
ans=R*G*B
for i in range(1,N-1):
    for j in range(i+1,N):
        k=2*j-i
        if k<N+1 and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans-=1
print(ans)