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

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)
    
mcount = 0
for i in range(int((n-1)/2)):
  k = i+1
  for j in range(k, n-k):
    if s[j] != s[j-k] and s[j] != s[j+k] and s[j-k] != s[j+k]:
      mcount += 1
  

for i in range(n):
  if i in r:
    for j in g:
      for k in b:
        if k < j:
          continue
        count += 1
    for j in b:
      for k in g:
        if k < j:
          continue
        count += 1      
  if i in g:
    for j in r:
      for k in b:
        if k < j:
          continue
        count += 1
    for j in b:
      for k in r:
        if k < j:
          continue
        count += 1
  if i in b:
    for j in g:
      for k in r:
        if k < j:
          continue
        count += 1
    for j in r:
      for k in g:
        if k < j:
          continue
        count += 1
  if i in r:
    r = r[1:]
  elif i in g:
    g = g[1:]
  else:
    b = b[1:]


print(count-mcount)

Fixed submission:
n = int(input())
s = input()
r = []
g = []
b = []

ans = s.count("R")*s.count("G")*s.count("B")

for i in range(n):
    for j in range(i+1,n):
        k = 2*j-i
        if k>=n:
          break
        ans -= s[k] != s[i] != s[j] != s[k]

print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
count = 0

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)
mcount = 0
for i in range((n-1)/2-1):
  for j in range(i+1, n-1-1-i):
    if s[j] != s[j-i-1] and s[j] != s[j+i+1] and s[j-i-1] != s[j+i+1]:
      mcount += 1
  

for i in range(n):
  if i in r:
    for j in g:
      for k in b:
        if k < j:
          continue
        count += 1
    for j in b:
      for k in g:
        if k < j:
          continue
        count += 1      
  if i in g:
    for j in r:
      for k in b:
        if k < j:
          continue
        count += 1
    for j in b:
      for k in r:
        if k < j:
          continue
        count += 1
  if i in b:
    for j in g:
      for k in r:
        if k < j:
          continue
        count += 1
    for j in r:
      for k in g:
        if k < j:
          continue
        count += 1
  if i in r:
    r = r[1:]
  elif i in g:
    g = g[1:]
  else:
    b = b[1:]

print(count-mcount)

Fixed submission:
n = int(input())
s = input()
r = []
g = []
b = []

ans = s.count("R")*s.count("G")*s.count("B")

for i in range(n):
    for j in range(i+1,n):
        k = 2*j-i
        if k>=n:
          break
        ans -= s[k] != s[i] != s[j] != s[k]

print(ans)

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

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)
    


for i in range(n):
  if i in r:
    for j in g:
      for k in b:
        if k < j:
          continue
        if 2*j != i+k:
          count += 1
    for j in b:
      for k in g:
        if k < j:
          continue
        if 2*j != i+k:
          count += 1      
  if i in g:
    for j in r:
      for k in b:
        if k < j:
          continue
        if 2*j != i+k:
          count += 1
    for j in b:
      for k in r:
        if k < j:
          continue
        if 2*j != i+k:
          count += 1
  if i in b:
    for j in g:
      for k in r:
        if k < j:
          continue
        if 2*j != i+k:
          count += 1
    for j in r:
      for k in g:
        if k < j:
          continue
        if 2*j != i+k:
          count += 1
  if i in r:
    r = r[1:]
  elif i in g:
    g = g[1:]
  else:
    b = b[1:]

print(count)

Fixed submission:
n = int(input())
s = input()
r = []
g = []
b = []

ans = s.count("R")*s.count("G")*s.count("B")

for i in range(n):
    for j in range(i+1,n):
        k = 2*j-i
        if k>=n:
          break
        ans -= s[k] != s[i] != s[j] != s[k]

print(ans)

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

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)
    


for i in range(n):
  if i in r:
    for j in g:
      if i > j:
        continue
      for k in b:
        if k < j:
          continue
        if 2*j != i+k:
          count += 1
    for j in b:
      if i > j:
        continue
      for k in g:
        if k < j:
          continue
        if 2*j != i+k:
          count += 1      
  if i in g:
    for j in r:
      if i > j:
        continue
      for k in b:
        if k < j:
          continue
        if 2*j != i+k:
          count += 1
    for j in b:
      if i > j:
        continue
      for k in r:
        if k < j:
          continue
        if 2*j != i+k:
          count += 1
  if i in b:
    for j in g:
      if i > j:
        continue
      for k in r:
        if k < j:
          continue
        if 2*j != i+k:
          count += 1
    for j in r:
      if i > j:
        continue
      for k in g:
        if k < j:
          continue
        if 2*j != i+k:
          count += 1

print(count)

Fixed submission:
n = int(input())
s = input()
r = []
g = []
b = []

ans = s.count("R")*s.count("G")*s.count("B")

for i in range(n):
    for j in range(i+1,n):
        k = 2*j-i
        if k>=n:
          break
        ans -= s[k] != s[i] != s[j] != s[k]

print(ans)

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

print(count)

Fixed submission:
n = int(input())
s = input()
r = []
g = []
b = []

ans = s.count("R")*s.count("G")*s.count("B")

for i in range(n):
    for j in range(i+1,n):
        k = 2*j-i
        if k>=n:
          break
        ans -= s[k] != s[i] != s[j] != s[k]

print(ans)

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

print(count)

Fixed submission:
n = int(input())
s = input()
r = []
g = []
b = []

ans = s.count("R")*s.count("G")*s.count("B")

for i in range(n):
    for j in range(i+1,n):
        k = 2*j-i
        if k>=n:
          break
        ans -= s[k] != s[i] != s[j] != s[k]

print(ans)