Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math 
n = int(input())
s = input()
a = np.zeros(n)
rgb = [[] for _ in range(3)]
rgb2 = np.zeros((3,n), int)
idx = {'R':0, 'G':1, 'B':2}
for i in range(n):
  rgb[idx[s[i]]].append(i)
  rgb2[idx[s[i]]][i] = 1
#

counts = 0
for i in rgb[0]:
  for j in rgb[1]:
    if(i+j >= 2*n-1):
      break
    if((i+j)%2 == 0 and rgb2[2][((i+j)//2)] == 1):
        counts += 1
for i in rgb[0]:
  for j in rgb[2]:
    if(i+j >= 2*n-1):
      break
    if((i+j)%2 == 0 and rgb2[1][(i+j)//2] == 1):
      counts += 1
for i in rgb[1]:
  for j in rgb[2]:
    if(i+j >= 2*n-1):
      break
    if((i+j)%2 == 0 and rgb2[0][(i+j)//2] == 1):
      counts += 1
print(len(rgb[0])*len(rgb[1])*len(rgb[2]) - counts)


Fixed submission:
import numpy as np
n = int(input())
s = input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

counts = 0
for i in range(n):
  for j in range(i+1, n):
    k = 2*j-i
    if(k >= n):
      break
    if(s[i] != s[j] and s[j]!=s[k] and s[k]!=s[i]):
      counts += 1
print(r*g*b - counts)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
s = input()
a = np.zeros(n)
rgb = [[] for _ in range(3)]
rgb2 = np.zeros((3,n), int)
idx = {'R':0, 'G':1, 'B':2}
for i in range(n):
  rgb[idx[s[i]]].append(i)
#

middles = [[] for _ in range(3)]
for i in rgb[0]:
  for j in rgb[1]:
    if(i+j >= 2*n-1):
      break
    if((i+j)%2 == 0):
      middles[idx['B']].append((i+j)//2)
for i in rgb[0]:
  for j in rgb[2]:
    if(i+j >= 2*n-1):
      break
    if((i+j)%2 == 0):
      middles[idx['G']].append((i+j)//2)
for i in rgb[1]:
  for j in rgb[2]:
    if(i+j >= 2*n-1):
      break
    if((i+j)%2 == 0):
      middles[idx['R']].append((i+j)//2)
#
counts = 0
for i in range(3):
  tmp,c = np.unique(middles[i], return_counts=True)
  for j,c in zip(tmp,c):
    if(j in rgb[i]):
      counts += c
print(len(rgb[0])*len(rgb[1])*len(rgb[2]) - counts)

Fixed submission:
import numpy as np
n = int(input())
s = input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

counts = 0
for i in range(n):
  for j in range(i+1, n):
    k = 2*j-i
    if(k >= n):
      break
    if(s[i] != s[j] and s[j]!=s[k] and s[k]!=s[i]):
      counts += 1
print(r*g*b - counts)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math 
n = int(input())
s = input()
a = np.zeros(n)
rgb = [[] for _ in range(3)]
rgb2 = np.zeros((3,n), int)
idx = {'R':0, 'G':1, 'B':2}
for i in range(n):
  rgb[idx[s[i]]].append(i)
  rgb2[idx[s[i]]][i] = 1
#

middles = [[] for _ in range(3)]
for i in rgb[0]:
  for j in rgb[1]:
    if(i+j >= 2*n-1):
      break
    if((i+j)%2 == 0):
      middles[idx['B']].append((i+j)//2)
for i in rgb[0]:
  for j in rgb[2]:
    if(i+j >= 2*n-1):
      break
    if((i+j)%2 == 0):
      middles[idx['G']].append((i+j)//2)
for i in rgb[1]:
  for j in rgb[2]:
    if(i+j >= 2*n-1):
      break
    if((i+j)%2 == 0):
      middles[idx['R']].append((i+j)//2)
#
counts = 0
for i in range(3):
  tmp,c = np.unique(middles[i], return_counts=True)
  for j,c in zip(tmp,c):
    if(j in rgb[i]):
      counts += c
print(len(rgb[0])*len(rgb[1])*len(rgb[2]) - counts)

Fixed submission:
import numpy as np
n = int(input())
s = input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

counts = 0
for i in range(n):
  for j in range(i+1, n):
    k = 2*j-i
    if(k >= n):
      break
    if(s[i] != s[j] and s[j]!=s[k] and s[k]!=s[i]):
      counts += 1
print(r*g*b - counts)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math 
n = int(input())
s = input()
a = np.zeros(n)
rgb = [[] for _ in range(3)]
rgb2 = np.zeros((3,n), int)
idx = {'R':0, 'G':1, 'B':2}
for i in range(n):
  rgb[idx[s[i]]].append(i)
  rgb2[idx[s[i]]][i] = 1
#

counts = 0
for i in rgb[0]:
  for j in rgb[1]:
    if(i+j >= 2*n-1):
      break
    if((i+j)%2 == 0 and rgb2[idx['B']][((i+j)//2)] == 1):
        counts += 1
for i in rgb[0]:
  for j in rgb[2]:
    if(i+j >= 2*n-1):
      break
    if((i+j)%2 == 0 and rgb2[idx['G']][(i+j)//2] == 1):
      counts += 1
for i in rgb[1]:
  for j in rgb[2]:
    if(i+j >= 2*n-1):
      break
    if((i+j)%2 == 0 and rgb2[idx['R']][(i+j)//2] == 1):
      counts += 1
print(len(rgb[0])*len(rgb[1])*len(rgb[2]) - counts)

Fixed submission:
import numpy as np
n = int(input())
s = input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

counts = 0
for i in range(n):
  for j in range(i+1, n):
    k = 2*j-i
    if(k >= n):
      break
    if(s[i] != s[j] and s[j]!=s[k] and s[k]!=s[i]):
      counts += 1
print(r*g*b - counts)