Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(input())
ans = S.count('R')*S.count('G')*S.count('B') 
for i in range(N): 
    if S[i]=='R':
       S[i] =1
    elif S[i]=='G':
       S[i] =2
    elif S[i]=='B':
       S[i] =4
    for j in range(i+1,N):
        k=2*j-i
        if k>=N : 
           continue  
        if S[i]+S[j]+S[k]==7 : 
           ans-=1 
print(ans)

Fixed submission:
N = int(input())
S = list(input())
ans = S.count('R')*S.count('G')*S.count('B') 
for i in range(N): 
   if S[i]=='R':
       S[i] =1
   elif S[i]=='G':
       S[i] =2
   elif S[i]=='B':
       S[i] =4
for i in range(N): 
   for j in range(i+1,N):
     k=2*j-i
     if k>=N : 
       continue  
     if S[i]+S[j]+S[k]==7 : 
         ans-=1 
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(input())
ans = S.count('R')*S.count('G')*S.count('B') 
for i in range(N): 
   if S[i]=='R':
       S[i]=1
   elif S[i]=='G':
       S[i]
   elif S[i]=='B':
       S[i]=4
for i in range(N): 
   for j in range(i+1,N):
     k=2*j-i
     if k>=N : 
       continue  
     if S[i]+S[j]+S[k]==7 : 
         ans-=1   
print(ans)

Fixed submission:
N = int(input())
S = list(input())
ans = S.count('R')*S.count('G')*S.count('B') 
for i in range(N): 
   if S[i]=='R':
       S[i] =1
   elif S[i]=='G':
       S[i] =2
   elif S[i]=='B':
       S[i] =4
for i in range(N): 
   for j in range(i+1,N):
     k=2*j-i
     if k>=N : 
       continue  
     if S[i]+S[j]+S[k]==7 : 
         ans-=1 
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(input())
ans = S.count('R')*S.count('G')*S.count('B') 
for i in range(N): 
   if S[i]=='R':
       S[i]=1
   elif S[i]=='G':
       S[i]
   elif S[i]=='B':
       S[i]=4
for i in range(N): 
   for j in range(i+1,N):
     k=2*j-i
     if k>N : 
       continue  
     if S[i]+S[j]+S[k]==7 : 
         ans-=1   
print(ans)

Fixed submission:
N = int(input())
S = list(input())
ans = S.count('R')*S.count('G')*S.count('B') 
for i in range(N): 
   if S[i]=='R':
       S[i] =1
   elif S[i]=='G':
       S[i] =2
   elif S[i]=='B':
       S[i] =4
for i in range(N): 
   for j in range(i+1,N):
     k=2*j-i
     if k>=N : 
       continue  
     if S[i]+S[j]+S[k]==7 : 
         ans-=1 
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(input())
ans = S.count('R')*S.count('G')*S.count('B') 
 #1番目の条件を満たすものの総数は(Rの個数)*(Gの個数)*(Bの個数)
for i in range(N): #判定を簡単にするためR:=1,G:=2,B:=4と置き換える
   if S[i]=='R':
       S[i]=1
   elif S[i]=='G':
       S[i]
   elif S[i]=='B':
       S[i]=4
for i in range(N): 
 #すべての(i,j)について(i,j,2*j-i)が1番目の条件を満たし、かつ2番目の条件を満たさないかを判定する
   for j in range(i+1,N):
     k=2*j-i
     if k>N : 
       continue  #考えなくて良いものはスキップ
     if S[i]+S[j]+S[k]==7 : 
         ans-=1   #1番目の条件を満たし、かつ2番目の条件を満たさないので、1を引く
print(ans)

Fixed submission:
N = int(input())
S = list(input())
ans = S.count('R')*S.count('G')*S.count('B') 
for i in range(N): 
   if S[i]=='R':
       S[i] =1
   elif S[i]=='G':
       S[i] =2
   elif S[i]=='B':
       S[i] =4
for i in range(N): 
   for j in range(i+1,N):
     k=2*j-i
     if k>=N : 
       continue  
     if S[i]+S[j]+S[k]==7 : 
         ans-=1 
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(input())
ans = S.count('R')*S.count('G')*S.count('B') 
 #1番目の条件を満たすものの総数は(Rの個数)*(Gの個数)*(Bの個数)
for i in range(N): #判定を簡単にするためR:=1,G:=2,B:=4と置き換える
   if S[i]=='R':
       S[i]=1
   elif S[i]=='G':
       S[i]
   elif S[i]=='B':
       S[i]=4
for i in range(N): 
 #すべての(i,j)について(i,j,2*j-i)が1番目の条件を満たし、かつ2番目の条件を満たさないかを判定する
   for j in range(i+1,N):
     k=2*j-i
     if k>N : 
       continue  #考えなくて良いものはスキップ
     if S[i]+S[j]+S[k]==7 : 
         ans-=1   #1番目の条件を満たし、かつ2番目の条件を満たさないので、1を引く
print(ans)

Fixed submission:
N = int(input())
S = list(input())
ans = S.count('R')*S.count('G')*S.count('B') 
for i in range(N): 
   if S[i]=='R':
       S[i] =1
   elif S[i]=='G':
       S[i] =2
   elif S[i]=='B':
       S[i] =4
for i in range(N): 
   for j in range(i+1,N):
     k=2*j-i
     if k>=N : 
       continue  
     if S[i]+S[j]+S[k]==7 : 
         ans-=1 
print(ans)