Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n=int(input())
s=list(input())
sr=set()
sg=set()
sb=set()
for ii in range(n):
    if s[ii]=="R":
        sr.add(ii)
    if s[ii]=="G":
        sg.add(ii)
    if s[ii]=="B":
        sb.add(ii)
r=0
for ii in sr:
  for jj in sg:
    for kk in sb:
      if abs(ii-jj)!=abs(jj-kk) and abs(jj-kk)!=abs(kk-ii) and abs(kk-ii)!=abs(ii-jj):
        r+=1
print(r)

Fixed submission:
import numpy as np
n=int(input())
s=list(input())
sr=set()
sg=set()
sb=set()
for ii in range(n):
    if s[ii]=="R":
        sr.add(ii)
    if s[ii]=="G":
        sg.add(ii)
    if s[ii]=="B":
        sb.add(ii)
l=[len(sr),len(sg),len(sb)]
l.sort()

if l[0]==len(sr):
  s1=sr
  if l[1]==len(sg):
    s2=sg
    s3=sb
  else:
    s2=sb
    s3=sg
elif l[0]==len(sg):
  s1=sg
  if l[1]==len(sr):
    s2=sr
    s3=sb
  else:
    s2=sb
    s3=sr
else:
  s1=sb
  if l[1]==len(sr):
    s2=sr
    s3=sg
  else:
    s2=sg
    s3=sr
  
r=0
for ii in s1:
  for jj in s2:
    r+=len(s3)
    dt=abs(ii-jj)
    if ii+dt in s3:
      r-=1
    if ii-dt in s3:
      r-=1
    if jj+dt in s3:
      r-=1
    if jj-dt in s3:
      r-=1
    if (ii+jj)%2==0:
      if (ii+jj)//2 in s3:
        r-=1
      
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n=int(input())
s=list(input())
sr=[]
sg=[]
sb=[]
for ii in range(n):
    if s[ii]=="R":
        sr.append(ii)
    if s[ii]=="G":
        sg.append(ii)
    if s[ii]=="B":
        sb.append(ii)
sr.sort()
sg.sort()
sb.sort()
r=0
for ii in range(len(sr)):
  for jj in range(len(sg)):
    for kk in range(len(sb)):
      sl=set([abs(sr[ii]-sg[jj]),abs(sg[jj]-sb[kk]),abs(sb[kk]-sr[ii])])
      #print(sl)
      if len(sl)==3:
        r+=1
print(r)

Fixed submission:
import numpy as np
n=int(input())
s=list(input())
sr=set()
sg=set()
sb=set()
for ii in range(n):
    if s[ii]=="R":
        sr.add(ii)
    if s[ii]=="G":
        sg.add(ii)
    if s[ii]=="B":
        sb.add(ii)
l=[len(sr),len(sg),len(sb)]
l.sort()

if l[0]==len(sr):
  s1=sr
  if l[1]==len(sg):
    s2=sg
    s3=sb
  else:
    s2=sb
    s3=sg
elif l[0]==len(sg):
  s1=sg
  if l[1]==len(sr):
    s2=sr
    s3=sb
  else:
    s2=sb
    s3=sr
else:
  s1=sb
  if l[1]==len(sr):
    s2=sr
    s3=sg
  else:
    s2=sg
    s3=sr
  
r=0
for ii in s1:
  for jj in s2:
    r+=len(s3)
    dt=abs(ii-jj)
    if ii+dt in s3:
      r-=1
    if ii-dt in s3:
      r-=1
    if jj+dt in s3:
      r-=1
    if jj-dt in s3:
      r-=1
    if (ii+jj)%2==0:
      if (ii+jj)//2 in s3:
        r-=1
      
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=list(input())
import numpy as np
r=0
for ii in range(n-2):
  for jj in np.arange(ii+1,n-1):
    if s[ii]!=s[jj]:
      for kk in range(jj+1,n):
        if ii-jj!=jj-kk:
          if s[jj]!=s[kk] and s[ii]!=s[kk]:
            r+=1
print(r)

Fixed submission:
import numpy as np
n=int(input())
s=list(input())
sr=set()
sg=set()
sb=set()
for ii in range(n):
    if s[ii]=="R":
        sr.add(ii)
    if s[ii]=="G":
        sg.add(ii)
    if s[ii]=="B":
        sb.add(ii)
l=[len(sr),len(sg),len(sb)]
l.sort()

if l[0]==len(sr):
  s1=sr
  if l[1]==len(sg):
    s2=sg
    s3=sb
  else:
    s2=sb
    s3=sg
elif l[0]==len(sg):
  s1=sg
  if l[1]==len(sr):
    s2=sr
    s3=sb
  else:
    s2=sb
    s3=sr
else:
  s1=sb
  if l[1]==len(sr):
    s2=sr
    s3=sg
  else:
    s2=sg
    s3=sr
  
r=0
for ii in s1:
  for jj in s2:
    r+=len(s3)
    dt=abs(ii-jj)
    if ii+dt in s3:
      r-=1
    if ii-dt in s3:
      r-=1
    if jj+dt in s3:
      r-=1
    if jj-dt in s3:
      r-=1
    if (ii+jj)%2==0:
      if (ii+jj)//2 in s3:
        r-=1
      
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n=int(input())
s=list(input())
sr=[0]*n
sg=[0]*n
sb=[0]*n
for ii in range(n):
    if s[ii]=="R":
        sr[ii]=1
    if s[ii]=="G":
        sg[ii]=1
    if s[ii]=="B":
        sb[ii]=1

r=0
"""
print(sr)
print(sg)
print(sb)
"""
gb=[0]*n
bg=[0]*n
rb=[0]*n
br=[0]*n
rg=[0]*n
gr=[0]*n
for jj in np.arange(1,n-1):
    if sg[jj]>0:
        gb[jj]=sum(sb[jj+1:n])
        gr[jj]=sum(sr[jj+1:n])
    if sb[jj]>0:
        bg[jj]=sum(sg[jj+1:n])
        br[jj]=sum(sr[jj+1:n])
    if sr[jj]>0:
        rb[jj]=sum(sb[jj+1:n])
        rg[jj]=sum(sg[jj+1:n])

for ii in np.arange(1,n-1):
  for jj in np.arange(ii+1,n):
    if s[ii-1]!=s[jj-1] and jj<n:
        kk=2*jj-ii-1
        if (s[ii-1]=="R" and s[jj-1]=="G") or (s[jj-1]=="R" and s[ii-1]=="G"):
            if s[ii-1]=="R":
                r+=gb[jj-1]
            if s[ii-1]=="G":
                r+=rb[jj-1]
            if kk<n:
                r-=sb[kk]
        if (s[ii-1]=="R" and s[jj-1]=="B") or (s[jj-1]=="R" and s[ii-1]=="B"):
            if s[ii-1]=="R":
                r+=bg[jj-1]
            if s[ii-1]=="B":
                r+=rg[jj-1]
            if kk<n:
                r-=sg[kk]
        if (s[ii-1]=="B" and s[jj-1]=="G") or (s[jj-1]=="B" and s[ii-1]=="G"):
            if s[ii-1]=="B":
                r+=gr[jj-1]
            if s[ii-1]=="G":
                r+=br[jj-1]
            if kk<n:
                r-=sr[kk]
        """
      for kk in np.arange(jj+1,n+1):
        #print(ii,jj,kk)
        if jj-ii!=kk-jj:
          if s[jj-1]!=s[kk-1] and s[ii-1]!=s[kk-1]:
            r+=1
        """
print(r)
    

Fixed submission:
import numpy as np
n=int(input())
s=list(input())
sr=set()
sg=set()
sb=set()
for ii in range(n):
    if s[ii]=="R":
        sr.add(ii)
    if s[ii]=="G":
        sg.add(ii)
    if s[ii]=="B":
        sb.add(ii)
l=[len(sr),len(sg),len(sb)]
l.sort()

if l[0]==len(sr):
  s1=sr
  if l[1]==len(sg):
    s2=sg
    s3=sb
  else:
    s2=sb
    s3=sg
elif l[0]==len(sg):
  s1=sg
  if l[1]==len(sr):
    s2=sr
    s3=sb
  else:
    s2=sb
    s3=sr
else:
  s1=sb
  if l[1]==len(sr):
    s2=sr
    s3=sg
  else:
    s2=sg
    s3=sr
  
r=0
for ii in s1:
  for jj in s2:
    r+=len(s3)
    dt=abs(ii-jj)
    if ii+dt in s3:
      r-=1
    if ii-dt in s3:
      r-=1
    if jj+dt in s3:
      r-=1
    if jj-dt in s3:
      r-=1
    if (ii+jj)%2==0:
      if (ii+jj)//2 in s3:
        r-=1
      
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n=int(input())
s=list(input())
sr=[0]*n
sg=[0]*n
sb=[0]*n
for ii in range(n):
    if s[ii]=="R":
        sr[ii]=1
    if s[ii]=="G":
        sg[ii]=1
    if s[ii]=="B":
        sb[ii]=1

r=0
"""
print(sr)
print(sg)
print(sb)
"""
for ii in np.arange(1,n+1):
  for jj in np.arange(ii+1,n+1):
    if s[ii-1]!=s[jj-1] and jj<n:
        kk=2*jj-ii-1
        if (s[ii-1]=="R" and s[jj-1]=="G") or (s[jj-1]=="R" and s[ii-1]=="G"):
            r+=sum(sb[jj+1-1:n])
            if kk<n:
                r-=sb[kk]
        if (s[ii-1]=="R" and s[jj-1]=="B") or (s[jj-1]=="R" and s[ii-1]=="B"):
            r+=sum(sg[jj+1-1:n])
            if kk<n:
                r-=sg[kk]
        if (s[ii-1]=="B" and s[jj-1]=="G") or (s[jj-1]=="B" and s[ii-1]=="G"):
            r+=sum(sr[jj+1-1:n])
            if kk<n:
                r-=sr[kk]
        """
      for kk in np.arange(jj+1,n+1):
        #print(ii,jj,kk)
        if jj-ii!=kk-jj:
          if s[jj-1]!=s[kk-1] and s[ii-1]!=s[kk-1]:
            r+=1
        """
print(r)
    

Fixed submission:
import numpy as np
n=int(input())
s=list(input())
sr=set()
sg=set()
sb=set()
for ii in range(n):
    if s[ii]=="R":
        sr.add(ii)
    if s[ii]=="G":
        sg.add(ii)
    if s[ii]=="B":
        sb.add(ii)
l=[len(sr),len(sg),len(sb)]
l.sort()

if l[0]==len(sr):
  s1=sr
  if l[1]==len(sg):
    s2=sg
    s3=sb
  else:
    s2=sb
    s3=sg
elif l[0]==len(sg):
  s1=sg
  if l[1]==len(sr):
    s2=sr
    s3=sb
  else:
    s2=sb
    s3=sr
else:
  s1=sb
  if l[1]==len(sr):
    s2=sr
    s3=sg
  else:
    s2=sg
    s3=sr
  
r=0
for ii in s1:
  for jj in s2:
    r+=len(s3)
    dt=abs(ii-jj)
    if ii+dt in s3:
      r-=1
    if ii-dt in s3:
      r-=1
    if jj+dt in s3:
      r-=1
    if jj-dt in s3:
      r-=1
    if (ii+jj)%2==0:
      if (ii+jj)//2 in s3:
        r-=1
      
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n=int(input())
s=list(input())
r=0
for ii in np.arange(1,n+1):
  for jj in np.arange(ii+1,n+1):
    for kk in np.arange(jj+1,n+1):
      #print(ii,jj,kk)
      if jj-ii!=kk-jj:
        if s[ii-1]!=s[jj-1] and s[jj-1]!=s[kk-1] and s[ii-1]!=s[kk-1]:
          r+=1
print(r)
    

Fixed submission:
import numpy as np
n=int(input())
s=list(input())
sr=set()
sg=set()
sb=set()
for ii in range(n):
    if s[ii]=="R":
        sr.add(ii)
    if s[ii]=="G":
        sg.add(ii)
    if s[ii]=="B":
        sb.add(ii)
l=[len(sr),len(sg),len(sb)]
l.sort()

if l[0]==len(sr):
  s1=sr
  if l[1]==len(sg):
    s2=sg
    s3=sb
  else:
    s2=sb
    s3=sg
elif l[0]==len(sg):
  s1=sg
  if l[1]==len(sr):
    s2=sr
    s3=sb
  else:
    s2=sb
    s3=sr
else:
  s1=sb
  if l[1]==len(sr):
    s2=sr
    s3=sg
  else:
    s2=sg
    s3=sr
  
r=0
for ii in s1:
  for jj in s2:
    r+=len(s3)
    dt=abs(ii-jj)
    if ii+dt in s3:
      r-=1
    if ii-dt in s3:
      r-=1
    if jj+dt in s3:
      r-=1
    if jj-dt in s3:
      r-=1
    if (ii+jj)%2==0:
      if (ii+jj)//2 in s3:
        r-=1
      
print(r)