Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()

r=[]
g=[]
b=[]

for i in range(n):
    if s[i]=="R":
        r.append(i+1)
    elif s[i]=="G":
        g.append(i+1)
    else:
        b.append(i+1)

lenr=len(r)
leng=len(g)
lenb=len(b)

isum=0
for ir in r:
    for ig in g:
        if (ir+ig)/2 in b: 
            isum=isum+1
for ir in r:
    for ib in b:
        if (ir+ib)/2  in g: 
            isum=isum+1
for ig in g:
    for ib in b:
        if (ig+ib)/2  in r: 
            isum=isum+1

isum=lenr*leng*lenb-isum
                
print(isum)


Fixed submission:
n=int(input())
s=input()

r=set()
g=set()
b=set()

for i in range(n):
    if s[i]=="R":
        r.add(i+1)
    elif s[i]=="G":
        g.add(i+1)
    else:
        b.add(i+1)

lenr=len(r)
leng=len(g)
lenb=len(b)

isum=0
for ir in r:
    for ig in g:
        if (ir+ig)/2 in b: 
            isum=isum+1
for ir in r:
    for ib in b:
        if (ir+ib)/2  in g: 
            isum=isum+1
for ig in g:
    for ib in b:
        if (ig+ib)/2  in r: 
            isum=isum+1

isum=lenr*leng*lenb-isum
                
print(isum)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()

r=[]
g=[]
b=[]

for i in range(n):
    if s[i]=="R":
        r.append(i+1)
    elif s[i]=="G":
        g.append(i+1)
    else:
        b.append(i+1)

lenr=len(r)
leng=len(g)
lenb=len(b)

isum=0
for ir in r:
    for ig in g:
        if (ir+ig)/2 in b: 
            isum=isum+1
for ir in r:
    for ib in b:
        if (ir+ib)/2  in g: 
            isum=isum+1
for ig in g:
    for ib in b:
        if (ig+ib)/2  in r: 
            isum=isum+1

isum=lenr*leng*lenb-isum
                
print(isum)

Fixed submission:
n=int(input())
s=input()

r=set()
g=set()
b=set()

for i in range(n):
    if s[i]=="R":
        r.add(i+1)
    elif s[i]=="G":
        g.add(i+1)
    else:
        b.add(i+1)

lenr=len(r)
leng=len(g)
lenb=len(b)

isum=0
for ir in r:
    for ig in g:
        if (ir+ig)/2 in b: 
            isum=isum+1
for ir in r:
    for ib in b:
        if (ir+ib)/2  in g: 
            isum=isum+1
for ig in g:
    for ib in b:
        if (ig+ib)/2  in r: 
            isum=isum+1

isum=lenr*leng*lenb-isum
                
print(isum)

Buggy python submission (verdict: Time Limit Exceeded):
 
n=int(input())
s=input()
#n=39
#s="RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"

r=[]
g=[]
b=[]

for i in range(n):
    if s[i]=="R":
        r.append(i+1)
    elif s[i]=="G":
        g.append(i+1)
    else:
        b.append(i+1)

lenr=len(r)
leng=len(g)
lenb=len(b)

isum=0
for ir in range(len(r)):
    for ig in range(len(g)):
        imin=max(r[ir],g[ig])
        if abs(r[ir]-g[ig])+imin in b: 
            isum=isum+1
for ir in range(len(r)):
    for ib in range(len(b)):
        imin=max(r[ir],b[ib])
        if abs(r[ir]-b[ib])+imin in g: 
            isum=isum+1
for ig in range(len(g)):
    for ib in range(len(b)):
        imin=max(g[ig],b[ib])
        if abs(g[ig]-b[ib])+imin in r: 
            isum=isum+1

isum=lenr*leng*lenb-isum
                
print(isum)

Fixed submission:
n=int(input())
s=input()

r=set()
g=set()
b=set()

for i in range(n):
    if s[i]=="R":
        r.add(i+1)
    elif s[i]=="G":
        g.add(i+1)
    else:
        b.add(i+1)

lenr=len(r)
leng=len(g)
lenb=len(b)

isum=0
for ir in r:
    for ig in g:
        if (ir+ig)/2 in b: 
            isum=isum+1
for ir in r:
    for ib in b:
        if (ir+ib)/2  in g: 
            isum=isum+1
for ig in g:
    for ib in b:
        if (ig+ib)/2  in r: 
            isum=isum+1

isum=lenr*leng*lenb-isum
                
print(isum)

Buggy python submission (verdict: Time Limit Exceeded):
 
n=int(input())
s=input()
#n=39
#s="RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"

r=[]
g=[]
b=[]

for i in range(n):
    if s[i]=="R":
        r.append(i+1)
    elif s[i]=="G":
        g.append(i+1)
    else:
        b.append(i+1)

lenr=len(r)
leng=len(g)
lenb=len(b)

isum=0
for ir in range(len(r)):
    for ig in range(len(g)):
        imin=max(r[ir],g[ig])
        if abs(r[ir]-g[ig])+imin in b: 
            isum=isum+1
for ir in range(len(r)):
    for ib in range(len(b)):
        imin=max(r[ir],b[ib])
        if abs(r[ir]-b[ib])+imin in g: 
            isum=isum+1
for ig in range(len(g)):
    for ib in range(len(b)):
        imin=max(g[ig],b[ib])
        if abs(g[ig]-b[ib])+imin in r: 
            isum=isum+1

isum=lenr*leng*lenb-isum
                
print(isum)

Fixed submission:
n=int(input())
s=input()

r=set()
g=set()
b=set()

for i in range(n):
    if s[i]=="R":
        r.add(i+1)
    elif s[i]=="G":
        g.add(i+1)
    else:
        b.add(i+1)

lenr=len(r)
leng=len(g)
lenb=len(b)

isum=0
for ir in r:
    for ig in g:
        if (ir+ig)/2 in b: 
            isum=isum+1
for ir in r:
    for ib in b:
        if (ir+ib)/2  in g: 
            isum=isum+1
for ig in g:
    for ib in b:
        if (ig+ib)/2  in r: 
            isum=isum+1

isum=lenr*leng*lenb-isum
                
print(isum)

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
#n=39
#s="RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"

r=[]
g=[]
b=[]

for i in range(n):
    if s[i]=="R":
        r.append(i+1)
    elif s[i]=="G":
        g.append(i+1)
    else:
        b.append(i+1)

lenr=len(r)
leng=len(g)
lenb=len(b)

isum=0
for ir in range(len(r)):
    for ig in range(len(g)):
        imin=max(r[ir],g[ig])
        bi=bisect(b,imin)
        if abs(r[ir]-g[ig])+imin in b: 
            isum=isum+lenb-bi-1
        else:
            isum=isum+lenb-bi
for ir in range(len(r)):
    for ib in range(len(b)):
        imin=max(r[ir],b[ib])
        gi=bisect(g,imin)
        if abs(r[ir]-b[ib])+imin in g: 
            isum=isum+leng-gi-1
        else:
            isum=isum+leng-gi
for ig in range(len(g)):
    for ib in range(len(b)):
        imin=max(g[ig],b[ib])
        ri=bisect(r,imin)
        if abs(g[ig]-b[ib])+imin in r: 
            isum=isum+lenr-ri-1
        else:
            isum=isum+lenr-ri
                
print(isum)
                


Fixed submission:
n=int(input())
s=input()

r=set()
g=set()
b=set()

for i in range(n):
    if s[i]=="R":
        r.add(i+1)
    elif s[i]=="G":
        g.add(i+1)
    else:
        b.add(i+1)

lenr=len(r)
leng=len(g)
lenb=len(b)

isum=0
for ir in r:
    for ig in g:
        if (ir+ig)/2 in b: 
            isum=isum+1
for ir in r:
    for ib in b:
        if (ir+ib)/2  in g: 
            isum=isum+1
for ig in g:
    for ib in b:
        if (ig+ib)/2  in r: 
            isum=isum+1

isum=lenr*leng*lenb-isum
                
print(isum)

Buggy python submission (verdict: Time Limit Exceeded):

from bisect import bisect_left,bisect
 
n=int(input())
s=input()
#n=39
#s="RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"

#n=7
#s="RBRBGRB"

r=[]
g=[]
b=[]

for i in range(n):
    if s[i]=="R":
        r.append(i+1)
    elif s[i]=="G":
        g.append(i+1)
    else:
        b.append(i+1)

lenr=len(r)
leng=len(g)
lenb=len(b)

#print(r)
#print(g)
#print(b)

isum=0
for ir in range(len(r)):
    for ig in range(len(g)):
        imin=max(r[ir],g[ig])
        bi=bisect(b,imin)
#        print(ir,ig,imin,bi)
        if abs(r[ir]-g[ig])+imin in b: 
            isum=isum+lenb-bi-1
        else:
            isum=isum+lenb-bi
for ir in range(len(r)):
    for ib in range(len(b)):
        imin=max(r[ir],b[ib])
        gi=bisect(g,imin)
        if abs(r[ir]-b[ib])+imin in g: 
            isum=isum+leng-gi-1
        else:
            isum=isum+leng-gi
for ig in range(len(g)):
    for ib in range(len(b)):
        imin=max(g[ig],b[ib])
        ri=bisect(r,imin)
        if abs(g[ig]-b[ib])+imin in r: 
            isum=isum+lenr-ri-1
        else:
            isum=isum+lenr-ri
                
print(isum)
                

        

Fixed submission:
n=int(input())
s=input()

r=set()
g=set()
b=set()

for i in range(n):
    if s[i]=="R":
        r.add(i+1)
    elif s[i]=="G":
        g.add(i+1)
    else:
        b.add(i+1)

lenr=len(r)
leng=len(g)
lenb=len(b)

isum=0
for ir in r:
    for ig in g:
        if (ir+ig)/2 in b: 
            isum=isum+1
for ir in r:
    for ib in b:
        if (ir+ib)/2  in g: 
            isum=isum+1
for ig in g:
    for ib in b:
        if (ig+ib)/2  in r: 
            isum=isum+1

isum=lenr*leng*lenb-isum
                
print(isum)