Buggy python submission (verdict: Runtime Error):
import sys
#sys.exit()
#sorted( ,reverse=True)
N = int(input())
#S,T = map(int, input().split())
#A = list(map(int, input().split()))
#print(N)
#print(S,T)
#print(A)
S = str(input())
r = S.count("R")
g = S.count("G")
b = S.count("B")
ans = (r*g*b)
#r2 = [i for i, x in enumerate(S) if x == 'R']
#g2 = [i for i, x in enumerate(S) if x == 'G']
#b2 = [i for i, x in enumerate(S) if x == 'B']
ans = (len(r2)*len(g2)*len(b2))
for i in range (N-2):
    for j in range (i+1,N-1):
        k = 2*j-i
        if k < N and S[i]!=S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -=1
                #print(r2[i],g2[j],b2[k])
print(ans)


Fixed submission:
import sys
#sys.exit()
#sorted( ,reverse=True)
N = int(input())
S = str(input())
r = S.count("R")
g = S.count("G")
b = S.count("B")
ans = (r*g*b)
for i in range (N-2):
    for j in range (i+1,N-1):
        k = 2*j-i
        if k < N and S[i]!=S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -=1
                #print(r2[i],g2[j],b2[k])
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
#sys.exit()
#sorted( ,reverse=True)
N = int(input())
#S,T = map(int, input().split())
#A = list(map(int, input().split()))
#print(N)
#print(S,T)
#print(A)
S = str(input())
r = S.count("R")
g = S.count("G")
b = S.count("B")
ans = (r*g*b)
#r2 = [i for i, x in enumerate(S) if x == 'R']
#g2 = [i for i, x in enumerate(S) if x == 'G']
#b2 = [i for i, x in enumerate(S) if x == 'B']
ans = (len(r2)*len(g2)*len(b2))
for i in range (N-2):
    for j in range (i+1,N-1):
        k = 2*j-i
        if k < N and S[i]!=S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -=1
                #print(r2[i],g2[j],b2[k])
print(ans)


Fixed submission:
import sys
#sys.exit()
#sorted( ,reverse=True)
N = int(input())
S = str(input())
r = S.count("R")
g = S.count("G")
b = S.count("B")
ans = (r*g*b)
for i in range (N-2):
    for j in range (i+1,N-1):
        k = 2*j-i
        if k < N and S[i]!=S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -=1
                #print(r2[i],g2[j],b2[k])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
#sys.exit()
#sorted( ,reverse=True)
N = int(input())
#S,T = map(int, input().split())
#A = list(map(int, input().split()))
#print(N)
#print(S,T)
#print(A)
S = str(input())
#r = S.count("R")
#g = S.count("G")
#b = S.count("B")
#ans = (r*g*b)
r2 = [i for i, x in enumerate(S) if x == 'R']
g2 = [i for i, x in enumerate(S) if x == 'G']
b2 = [i for i, x in enumerate(S) if x == 'B']
ans = (len(r2)*len(g2)*len(b2))
for i in range (0,len(r2)):
    for j in range (0,len(g2)):
        for k in range (0,len(b2)):
            lis2 =[r2[i], g2[j], b2[k]]
            lis= sorted(lis2)
            if lis[1]-lis[0] == lis[2]-lis[1]:
                ans -=1
                #print(r2[i],g2[j],b2[k])
print(ans)


Fixed submission:
import sys
#sys.exit()
#sorted( ,reverse=True)
N = int(input())
S = str(input())
r = S.count("R")
g = S.count("G")
b = S.count("B")
ans = (r*g*b)
for i in range (N-2):
    for j in range (i+1,N-1):
        k = 2*j-i
        if k < N and S[i]!=S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -=1
                #print(r2[i],g2[j],b2[k])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
#sys.exit()
#sorted( ,reverse=True)
N = int(input())
#S,T = map(int, input().split())
#A = list(map(int, input().split()))
#print(N)
#print(S,T)
#print(A)
S = str(input())
r = S.count("R")
g = S.count("G")
b = S.count("B")
ans = (r*g*b)
r2 = [i for i, x in enumerate(S) if x == 'R']
g2 = [i for i, x in enumerate(S) if x == 'G']
b2 = [i for i, x in enumerate(S) if x == 'B']

for i in range (0,len(r2)):
    for j in range (0,len(g2)):
        for k in range (0,len(b2)):
            lis2 =[r2[i], g2[j], b2[k]]
            lis= sorted(lis2)
            if lis[1]-lis[0] == lis[2]-lis[1]:
                ans -=1
                #print(r2[i],g2[j],b2[k])
print(ans)


Fixed submission:
import sys
#sys.exit()
#sorted( ,reverse=True)
N = int(input())
S = str(input())
r = S.count("R")
g = S.count("G")
b = S.count("B")
ans = (r*g*b)
for i in range (N-2):
    for j in range (i+1,N-1):
        k = 2*j-i
        if k < N and S[i]!=S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -=1
                #print(r2[i],g2[j],b2[k])
print(ans)