Buggy python submission (verdict: Runtime Error):
n=int(input())
s=list(input())
a=s.count("R")
b=s.count("G")
c=s.count("B")
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    k=2*j-i
    if n>=k and (s[i]==s[j] or s[i]==s[k] or s[j]==s[k]): 
      ans=ans+1
print(abc-ans)

      

Fixed submission:
n=int(input())
s=list(input())
a=s.count("R")
b=s.count("G")
c=s.count("B")
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    k=2*j-i
    if n-1>=k and (s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]): 
      ans=ans+1
print(a*b*c-ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
k=[i for i in range(0,n)]
from itertools import combinations
c=list(combinations(k,3))
ans=0
for i in range(len(c)):
  p=c[i][0]
  q=c[i][1]
  r=c[i][2]
  if s[p]!=s[q] and s[q]!=s[r] and s[p]!=s[r] and q-p!=r-q:
    ans=ans+1
print(ans)  

Fixed submission:
n=int(input())
s=list(input())
a=s.count("R")
b=s.count("G")
c=s.count("B")
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    k=2*j-i
    if n-1>=k and (s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]): 
      ans=ans+1
print(a*b*c-ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
k=[i for i in range(1,n+1)]
from itertools import combinations
c=list(combinations(k,3))
ans=0
for i in range(len(c)):
  p=int(c[i][0])
  q=int(c[i][1])
  r=int(c[i][2])
  if s[p]!=s[q] and s[q]!=s[r] and s[p]!=s[r] and q-p!=r-q:
    ans=ans+1
print(ans)  

Fixed submission:
n=int(input())
s=list(input())
a=s.count("R")
b=s.count("G")
c=s.count("B")
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    k=2*j-i
    if n-1>=k and (s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]): 
      ans=ans+1
print(a*b*c-ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
k=[i for i in range(1,n+1)]
from itertools import combinations
c=list(combinations(k,3))
ans=0
for i in range(len(c)):
  p=c[i][0]
  q=c[i][1]
  r=c[i][2]
  if s[p]!=s[q] and s[q]!=s[r] and s[p]!=s[r] and q-p!=r-q:
    ans=ans+1
print(ans)  

Fixed submission:
n=int(input())
s=list(input())
a=s.count("R")
b=s.count("G")
c=s.count("B")
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    k=2*j-i
    if n-1>=k and (s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]): 
      ans=ans+1
print(a*b*c-ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
k=[i for i in range(1,n+1)]
from itertools import combinations
c=list(combinations(k,2))
ans=0
for i in range(len(c)):
  p=c[i][0]
  q=c[i][1]
  r=c[i][2]
  if s[p]!=s[q] and s[q]!=s[r] and s[p]!=s[r] and q-p!=r-q:
    ans=ans+1
print(ans)  

Fixed submission:
n=int(input())
s=list(input())
a=s.count("R")
b=s.count("G")
c=s.count("B")
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    k=2*j-i
    if n-1>=k and (s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]): 
      ans=ans+1
print(a*b*c-ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
ans=0
#a=min(s.count("R"),s.count("G"),s.count("B"))
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if s[j]!=s[i] and s[i]!=s[k] and s[j]!=s[k] and j-i!=k-j:
                ans = ans+1
print(ans)

Fixed submission:
n=int(input())
s=list(input())
a=s.count("R")
b=s.count("G")
c=s.count("B")
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    k=2*j-i
    if n-1>=k and (s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]): 
      ans=ans+1
print(a*b*c-ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=list(input())
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if s[j]!=s[i] and s[i]!=s[k] and s[j]!=s[k] and j-i!=k-j:
                ans = ans+1
print(ans)

Fixed submission:
n=int(input())
s=list(input())
a=s.count("R")
b=s.count("G")
c=s.count("B")
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    k=2*j-i
    if n-1>=k and (s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]): 
      ans=ans+1
print(a*b*c-ans)