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)
  elif s[i]=='G':
    g.append(i)
  else:
    b.append(i)
ans=len(r)*len(g)*len(b)
for i in g:
  for j in b:
    a=i+j
    if a%2==0 and (a//2 in r):
      ans-=1
for i in r:
  for j in b:
    a=i+j
    if a%2==0 and (a//2 in g):
      ans-=1
for i in g:
  for j in r:
    a=i+j
    if a%2==0 and (a//2 in b):
      ans-=1
print(ans)

Fixed submission:
import bisect
n=int(input())
s=input()
r=[]
g=[]
b=[]
for i in range(n):
  if s[i]=='R':
    r.append(i)
  elif s[i]=='G':
    g.append(i)
  else:
    b.append(i)
ans=len(r)*len(g)*len(b)
r.append(n*4)
g.append(n*4)
b.append(n*4)
for i in g:
  for j in b:
    a=i+j
    if a%2==0 and r[bisect.bisect_left(r, a//2)]==a//2:
      ans-=1
for i in r:
  for j in b:
    a=i+j
    if a%2==0 and g[bisect.bisect_left(g, a//2)]==a//2:
      ans-=1
for i in g:
  for j in r:
    a=i+j
    if a%2==0 and b[bisect.bisect_left(b, a//2)]==a//2:
      ans-=1
print(ans+3)

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
r=[]
g=[]
b=[]
for i in range(n):
  if s[i]=='R':
    r.append(i)
  elif s[i]=='G':
    g.append(i)
  else:
    b.append(i)
ans=len(r)*len(g)*len(b)
for i in g:
  for j in b:
    i+j=a
    if a%2==0 and (a//2 in r):
      ans-=1
for i in r:
  for j in b:
    i+j=a
    if a%2==0 and (a//2 in g):
      ans-=1
for i in g:
  for j in r:
    i+j=a
    if a%2==0 and (a//2 in b):
      ans-=1
print(ans)


Fixed submission:
import bisect
n=int(input())
s=input()
r=[]
g=[]
b=[]
for i in range(n):
  if s[i]=='R':
    r.append(i)
  elif s[i]=='G':
    g.append(i)
  else:
    b.append(i)
ans=len(r)*len(g)*len(b)
r.append(n*4)
g.append(n*4)
b.append(n*4)
for i in g:
  for j in b:
    a=i+j
    if a%2==0 and r[bisect.bisect_left(r, a//2)]==a//2:
      ans-=1
for i in r:
  for j in b:
    a=i+j
    if a%2==0 and g[bisect.bisect_left(g, a//2)]==a//2:
      ans-=1
for i in g:
  for j in r:
    a=i+j
    if a%2==0 and b[bisect.bisect_left(b, a//2)]==a//2:
      ans-=1
print(ans+3)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
r=[]
r2=[]
g=[]
g2=[]
b=[]
b2=[]
for i in range(n):
  if s[i]=='R':
    r.append(i)
    r2.append(i*2)
  elif s[i]=='G':
    g.append(i)
    g2.append(i*2)
  else:
    b.append(i)
    b2.append(i*2)
ans=len(r)*len(g)*len(b)
for i in g:
  for j in b:
    if i+j in r2:
      ans-=1
for i in r:
  for j in b:
    if i+j in g2:
      ans-=1
for i in g:
  for j in r:
    if i+j in b2:
      ans-=1
print(ans)


Fixed submission:
import bisect
n=int(input())
s=input()
r=[]
g=[]
b=[]
for i in range(n):
  if s[i]=='R':
    r.append(i)
  elif s[i]=='G':
    g.append(i)
  else:
    b.append(i)
ans=len(r)*len(g)*len(b)
r.append(n*4)
g.append(n*4)
b.append(n*4)
for i in g:
  for j in b:
    a=i+j
    if a%2==0 and r[bisect.bisect_left(r, a//2)]==a//2:
      ans-=1
for i in r:
  for j in b:
    a=i+j
    if a%2==0 and g[bisect.bisect_left(g, a//2)]==a//2:
      ans-=1
for i in g:
  for j in r:
    a=i+j
    if a%2==0 and b[bisect.bisect_left(b, a//2)]==a//2:
      ans-=1
print(ans+3)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
r=[]
r2=[]
g=[]
g2=[]
b=[]
b2=[]
for i in range(n):
  if s[i]=='R':
    r.append(i)
    r2.append(i*2)
  elif s[i]=='G':
    g.append(i)
    g2.append(i*2)
  else:
    b.append(i)
    b2.append(i*2)
ans=len(r)*len(g)*len(b)
for i in g:
  for j in b:
    if i+j in r2:
      ans-=1
for i in r:
  for j in b:
    if i+j in g2:
      ans-=1
for i in g:
  for j in r:
    if i+j in b2:
      ans-=1
print(ans)

Fixed submission:
import bisect
n=int(input())
s=input()
r=[]
g=[]
b=[]
for i in range(n):
  if s[i]=='R':
    r.append(i)
  elif s[i]=='G':
    g.append(i)
  else:
    b.append(i)
ans=len(r)*len(g)*len(b)
r.append(n*4)
g.append(n*4)
b.append(n*4)
for i in g:
  for j in b:
    a=i+j
    if a%2==0 and r[bisect.bisect_left(r, a//2)]==a//2:
      ans-=1
for i in r:
  for j in b:
    a=i+j
    if a%2==0 and g[bisect.bisect_left(g, a//2)]==a//2:
      ans-=1
for i in g:
  for j in r:
    a=i+j
    if a%2==0 and b[bisect.bisect_left(b, a//2)]==a//2:
      ans-=1
print(ans+3)