Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
r = []
g = []
b = [0]*4000
for i,j in enumerate(s):
  if j == 'R':
    r.append(i)
  if j == 'G':
    g.append(i)
  if j == 'B':
    b[i] += 1
cnt = len(r)*len(g)*sum(b)
for i in r:
  for j in g:
    if b[2*j-i] == 1 :
      cnt -= 1
    if b[2*i-j] == 1 :
      cnt -= 1
    if (i+j)%2 == 0 and b[(i+j)//2] == 1:
      cnt -= 1
print(cnt)

Fixed submission:
N=int(input())
S=input()
r=S.count('R')
b=S.count('B')
g=S.count('G')
ans=r*b*g
for i in range(N):
    for s in range(N):
        j=i+s
        k=j+s
        if k>=N:
            break
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
r = []
g = []
b = []
for i,j in enumerate(s):
  if j == 'R':
    r.append(i)
  if j == 'G':
    g.append(i)
  if j == 'B':
    b.append(i)
cnt = 0
for i in r:
  for j in g:
    cnt += len(b)
    if 2*j-i in b:
      cnt -= 1
    if 2*i-j in b:
      cnt -= 1
    if (i+j)%2 == 0 and (i+j)//2 in b:
      cnt -= 1
print(cnt)
  


Fixed submission:
N=int(input())
S=input()
r=S.count('R')
b=S.count('B')
g=S.count('G')
ans=r*b*g
for i in range(N):
    for s in range(N):
        j=i+s
        k=j+s
        if k>=N:
            break
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans-=1
print(ans)

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)
  if s[i] == 'G':
    g.append(i)
  if s[i] == 'B':
    b.append(i)
cnt = len(r)*len(g)*len(b)
for i in r:
  for j in g:
    a = abs(i-j)
    B = max(i,j)+a
    c = min(i,j)-a
    if (i+j)%2==0:
      d = (i+j)//2
    else:
      d=-1
    if B in b:
      cnt-=1
    if c in b:
      cnt-=1
    if d in b:
      cnt-=1
print(cnt)

Fixed submission:
N=int(input())
S=input()
r=S.count('R')
b=S.count('B')
g=S.count('G')
ans=r*b*g
for i in range(N):
    for s in range(N):
        j=i+s
        k=j+s
        if k>=N:
            break
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
cnt =0
r = []
g = []
b = []
for i in range(n):
  if s[i] == 'R':
    r.append(i)
  if s[i] == 'G':
    g.append(i)
  if s[i] == 'B':
    b.append(i)
for i in range(len(r)):
  for j in range(len(g)):
    for k in range(len(b)):
      a = sorted([r[i],g[j],b[k]])
      if a[2]-a[1] != a[1]-a[0]:
        cnt += 1
print(cnt)

Fixed submission:
N=int(input())
S=input()
r=S.count('R')
b=S.count('B')
g=S.count('G')
ans=r*b*g
for i in range(N):
    for s in range(N):
        j=i+s
        k=j+s
        if k>=N:
            break
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans-=1
print(ans)

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

Fixed submission:
N=int(input())
S=input()
r=S.count('R')
b=S.count('B')
g=S.count('G')
ans=r*b*g
for i in range(N):
    for s in range(N):
        j=i+s
        k=j+s
        if k>=N:
            break
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans-=1
print(ans)