Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n=int(input())
s_=input()
s=Counter(s_)
rgb = s['R'] * s['G'] * s['B']
cnt=0
for i in range(len(s_)):
  for j in range(i+1,len(s_)):
    h=j-i+j
    if h<len(s_):
      if s_[i]!=s_[j] and s_[h]!=s_[j] and s_[i]!=s_[h]:
        cnt+=1

print(rgb-cnt)

Fixed submission:

n=int(input())
s_=input()
r, g, b = s_.count("R"), s_.count("G"), s_.count("B")
rgb = r * g * b
cnt=0
for i in range(len(s_)):
  for j in range(i+1,len(s_)):
    h=j-i+j
    if h<n:
      if s_[i]!=s_[j] and s_[h]!=s_[j] and s_[i]!=s_[h]:
        cnt+=1

print(rgb-cnt)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
s_=input()
s=Couter(s_)
rgb = s['R'] * s['G'] * s['B']
cnt=0
for i in range(len(s_)):
  for j in range(i+1,len(s_)):
    h=j-i+j
    if h<n:
      if s_[i]!=s_[j] and s_[h]!=s_[j] and s_[i]!=s_[h]:
        cnt+=1

print(rgb-cnt)
    

Fixed submission:

n=int(input())
s_=input()
r, g, b = s_.count("R"), s_.count("G"), s_.count("B")
rgb = r * g * b
cnt=0
for i in range(len(s_)):
  for j in range(i+1,len(s_)):
    h=j-i+j
    if h<n:
      if s_[i]!=s_[j] and s_[h]!=s_[j] and s_[i]!=s_[h]:
        cnt+=1

print(rgb-cnt)

Buggy python submission (verdict: Time Limit Exceeded):

n=int(input())
s_=input()
r, g, b = s_.count("R"), s_.count("G"), s_.count("B")
rgb = r * g * b
cnt=0
for i in range(len(s_)):
  for j in range(i+1,len(s_)):
    h=j-i+j
    if h<=len(s_)-1:
      if s_[i]!=s_[j] and s_[h]!=s_[j] and s_[i]!=s_[h]:
        cnt+=1

print(rgb-cnt)

Fixed submission:

n=int(input())
s_=input()
r, g, b = s_.count("R"), s_.count("G"), s_.count("B")
rgb = r * g * b
cnt=0
for i in range(len(s_)):
  for j in range(i+1,len(s_)):
    h=j-i+j
    if h<n:
      if s_[i]!=s_[j] and s_[h]!=s_[j] and s_[i]!=s_[h]:
        cnt+=1

print(rgb-cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()

rgb=['R','G','B']
cnt=0
for i in range(len(s)):
  if s[i]==rgb[0]:
    for j in range(i+1,len(s)):
      if s[j]==rgb[1]:
        for h in range(j+1,len(s)):
          if h-j!=j-i:
            if s[h]==rgb[2]:
              cnt+=1
        
      elif s[j]==rgb[2]:
        for h in range(j+1,len(s)):
          if h-j!=j-i:
            if s[h]==rgb[1]:
              cnt+=1
              
  elif s[i]==rgb[1]:
    for j in range(i+1,len(s)):
      if s[j]==rgb[0]:
        for h in range(j+1,len(s)):
          if h-j!=j-i:
            if s[h]==rgb[2]:
              cnt+=1
        
      elif s[j]==rgb[2]:
        for h in range(j+1,len(s)):
          if h-j!=j-i:
            if s[h]==rgb[0]:
              cnt+=1
              
  elif s[i]==rgb[2]:
    for j in range(i+1,len(s)):
      if s[j]==rgb[1]:
        for h in range(j+1,len(s)):
          if h-j!=j-i:
            if s[h]==rgb[0]:
              cnt+=1
        
      elif s[j]==rgb[0]:
        for h in range(j+1,len(s)):
          if h-j!=j-i:
            if s[h]==rgb[1]:
              cnt+=1
              
print(cnt)

Fixed submission:

n=int(input())
s_=input()
r, g, b = s_.count("R"), s_.count("G"), s_.count("B")
rgb = r * g * b
cnt=0
for i in range(len(s_)):
  for j in range(i+1,len(s_)):
    h=j-i+j
    if h<n:
      if s_[i]!=s_[j] and s_[h]!=s_[j] and s_[i]!=s_[h]:
        cnt+=1

print(rgb-cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()

rgb=['R','G','B']
cnt=0
for i in range(len(s)):
  if s[i]==rgb[0]:
    for j in range(i+1,len(s)):
      if s[j]==rgb[1]:
        for h in range(j+1,len(s)):
          if h-j!=j-i:
            if s[h]==rgb[2]:
              cnt+=1
        
      elif s[j]==rgb[2]:
        for h in range(j+1,len(s)):
          if h-j!=j-i:
            if s[h]==rgb[1]:
              cnt+=1
              
  elif s[i]==rgb[1]:
    for j in range(i+1,len(s)):
      if s[j]==rgb[0]:
        for h in range(j+1,len(s)):
          if h-j!=j-i:
            if s[h]==rgb[2]:
              cnt+=1
        
      elif s[j]==rgb[2]:
        for h in range(j+1,len(s)):
          if h-j!=j-i:
            if s[h]==rgb[0]:
              cnt+=1
              
  elif s[i]==rgb[2]:
    for j in range(i+1,len(s)):
      if s[j]==rgb[1]:
        for h in range(j+1,len(s)):
          if h-j!=j-i:
            if s[h]==rgb[0]:
              cnt+=1
        
      elif s[j]==rgb[0]:
        for h in range(j+1,len(s)):
          if h-j!=j-i:
            if s[h]==rgb[1]:
              cnt+=1
              
print(cnt)

Fixed submission:

n=int(input())
s_=input()
r, g, b = s_.count("R"), s_.count("G"), s_.count("B")
rgb = r * g * b
cnt=0
for i in range(len(s_)):
  for j in range(i+1,len(s_)):
    h=j-i+j
    if h<n:
      if s_[i]!=s_[j] and s_[h]!=s_[j] and s_[i]!=s_[h]:
        cnt+=1

print(rgb-cnt)