Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
dic={}
cntr=s.count("R")
cntg=s.count("G")
cntb=s.count("B")
for i in range(n):
    if s[i]=="R":
        dic[i]="R"
    if s[i]=="G":
        dic[i]="G"
    if s[i]=="B":
        dic[i]="B"

cnt=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        if 2*j-i<=n-1 and dic[i]!= dic[j] and dic[i]!=dic[2*j-i] and dic[j]!=dic[2*j-i]:
                cnt+=1
print(cntr*cntg*cntb-cnt)

        

Fixed submission:
n=int(input())
s=input()
dic={}
cntr=0
cntg=0
cntb=0
for i in range(n):
    if s[i]=="R":
        dic[i]="R"
        cntr+=1
    if s[i]=="G":
        dic[i]="G"
        cntg+=1
    if s[i]=="B":
        dic[i]="B"
        cntb+=1

cnt=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        if 2*j-i<=n-1 and dic[i]!= dic[j]:
            if dic[i]!=dic[2*j-i] and dic[j]!=dic[2*j-i]:
                cnt+=1
print(cntr*cntg*cntb-cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
dic={}
cntr=0
cntg=0
cntb=0
for i in range(n):
    if s[i]=="R":
        dic[i]="R"
        cntr+=1
    if s[i]=="G":
        dic[i]="G"
        cntg+=1
    if s[i]=="B":
        dic[i]="B"
        cntb+=1

cnt=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        if 2*j-i<=n-1 and dic[i]!= dic[j]:
            if dic[i]!=dic[2*j-i] and dic[j]!=dic[2*j-i]:
                cnt+=1
print(cntr*cntg*cntb-cnt)

        

Fixed submission:
n=int(input())
s=input()
dic={}
cntr=0
cntg=0
cntb=0
for i in range(n):
    if s[i]=="R":
        dic[i]="R"
        cntr+=1
    if s[i]=="G":
        dic[i]="G"
        cntg+=1
    if s[i]=="B":
        dic[i]="B"
        cntb+=1

cnt=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        if 2*j-i<=n-1 and dic[i]!= dic[j]:
            if dic[i]!=dic[2*j-i] and dic[j]!=dic[2*j-i]:
                cnt+=1
print(cntr*cntg*cntb-cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
n=int(input())
a=input()


cnt=0
r=[]
g=[]
b=[]
def main():
	cnt=0
	for i in range(n):
		r_a=r.append
		b_a=b.append
		g_a=g.append
		if a[i]=="R":
			r_a(i)
		if a[i]=="B":
			b_a(i)
		if a[i]=="G":
			g_a(i)


	for i1 in r:
		for i2 in b:
			for i3 in g:
				if abs(i1-i2)==abs(i2-i3) or abs(i1-i3)==abs(i2-i3) or abs(i1-i3)==abs(i2-i1):
					cnt+=0
				else:
					cnt+=1
			
	print(cnt)
	
if __name__=="__main__":
	main()

Fixed submission:
n=int(input())
s=input()
dic={}
cntr=0
cntg=0
cntb=0
for i in range(n):
    if s[i]=="R":
        dic[i]="R"
        cntr+=1
    if s[i]=="G":
        dic[i]="G"
        cntg+=1
    if s[i]=="B":
        dic[i]="B"
        cntb+=1

cnt=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        if 2*j-i<=n-1 and dic[i]!= dic[j]:
            if dic[i]!=dic[2*j-i] and dic[j]!=dic[2*j-i]:
                cnt+=1
print(cntr*cntg*cntb-cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
n=int(input())
a=input()

cnt=0
r=[]
g=[]
b=[]
for i in range(n):
	if a[i]=="R":
		r.append(i)
	if a[i]=="B":
		b.append(i)
	if a[i]=="G":
		g.append(i)


for i1 in r:
	for i2 in b:
		for i3 in g:
			if abs(i1-i2)==abs(i2-i3) or abs(i1-i3)==abs(i2-i3) or abs(i1-i3)==abs(i2-i1):
				cnt+=0
			else:
				cnt+=1
			
			
print(cnt)
	

Fixed submission:
n=int(input())
s=input()
dic={}
cntr=0
cntg=0
cntb=0
for i in range(n):
    if s[i]=="R":
        dic[i]="R"
        cntr+=1
    if s[i]=="G":
        dic[i]="G"
        cntg+=1
    if s[i]=="B":
        dic[i]="B"
        cntb+=1

cnt=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        if 2*j-i<=n-1 and dic[i]!= dic[j]:
            if dic[i]!=dic[2*j-i] and dic[j]!=dic[2*j-i]:
                cnt+=1
print(cntr*cntg*cntb-cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
n=int(input())
a=input()

cnt=0
r=[]
g=[]
b=[]
for i in range(n):
	if a[i]=="R":
		r.append(i)
	if a[i]=="B":
		b.append(i)
	if a[i]=="G":
		g.append(i)


for i1 in r:
	for i2 in b:
		for i3 in g:
			if abs(i1-i2)==abs(i2-i3) or abs(i1-i3)==abs(i2-i3) or abs(i1-i3)==abs(i2-i1):
				cnt+=0
			else:
				cnt+=1
			
			
print(cnt)
	

Fixed submission:
n=int(input())
s=input()
dic={}
cntr=0
cntg=0
cntb=0
for i in range(n):
    if s[i]=="R":
        dic[i]="R"
        cntr+=1
    if s[i]=="G":
        dic[i]="G"
        cntg+=1
    if s[i]=="B":
        dic[i]="B"
        cntb+=1

cnt=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        if 2*j-i<=n-1 and dic[i]!= dic[j]:
            if dic[i]!=dic[2*j-i] and dic[j]!=dic[2*j-i]:
                cnt+=1
print(cntr*cntg*cntb-cnt)