Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np
import itertools
N = int(input())
S = (input())

r_index_lis, g_index_lis, b_index_lis = [], [], []
for i, s in enumerate(S):
    if s == 'R':
        r_index_lis.append(i)
    elif s == 'G':
        g_index_lis.append(i)
    else:
        b_index_lis.append(i)
count = 0

p = (itertools.product(r_index_lis, g_index_lis, b_index_lis))
for _p in p:
    _p = sorted(_p)
    if(_p[0] - _p[1] != _p[1] - _p[2]):
        count += 1
print(count)
# for r in r_index_lis:
#     for g in g_index_lis:
#         diff = r - g
#         if(b_index_lis)
#         count += len(b_index_lis)

# for b in b_index_lis:
#     rgb = sorted([r, g, b])
#     if (rgb[0] - rgb[1] != rgb[1] - rgb[2]):
#         count += 1


Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
import itertools
import time
N = int(input())
S = (input())
# start = time.time()
r_index_lis, g_index_lis, b_index_lis = [], [], []
for i, s in enumerate(S):
    if s == 'R':
        r_index_lis.append(i)
    elif s == 'G':
        g_index_lis.append(i)
    else:
        b_index_lis.append(i)
count = len(r_index_lis)*len(g_index_lis)*len(b_index_lis)
# print(time.time() - start)
# exit()

# for r in r_index_lis:
#     for g in g_index_lis:
#         diff = r - g
#         # count += len(b_index_lis)
#         if(min(r, g) - diff >= 0):
#             if S[min(r, g) - diff] == 'B':
#                 count -= 1
#         if(max(r, g) + diff < N):
#             if S[max(r, g) + diff] == 'B':
#                 count -= 1
#         if (r+g) % 2 == 0:
#             if S[int((r+g)/2)] == 'B':
#                 count -= 1

for i in range(N):
    for j in range(i+1, N):
        k = 2*j - i
        if k < N and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            count -= 1


print(count)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np
N = int(input())
S = (input())

r_index_lis, g_index_lis, b_index_lis = [], [], []
for i, s in enumerate(S):
    if s == 'R':
        r_index_lis.append(i)
    elif s == 'G':
        g_index_lis.append(i)
    else:
        b_index_lis.append(i)
count = 0
for r in r_index_lis:
    for g in g_index_lis:
        for b in b_index_lis:
            rgb = sorted([r, g, b])
            if (rgb[0] - rgb[1] != rgb[1] - rgb[2]):
                count += 1
print(count)


Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
import itertools
import time
N = int(input())
S = (input())
# start = time.time()
r_index_lis, g_index_lis, b_index_lis = [], [], []
for i, s in enumerate(S):
    if s == 'R':
        r_index_lis.append(i)
    elif s == 'G':
        g_index_lis.append(i)
    else:
        b_index_lis.append(i)
count = len(r_index_lis)*len(g_index_lis)*len(b_index_lis)
# print(time.time() - start)
# exit()

# for r in r_index_lis:
#     for g in g_index_lis:
#         diff = r - g
#         # count += len(b_index_lis)
#         if(min(r, g) - diff >= 0):
#             if S[min(r, g) - diff] == 'B':
#                 count -= 1
#         if(max(r, g) + diff < N):
#             if S[max(r, g) + diff] == 'B':
#                 count -= 1
#         if (r+g) % 2 == 0:
#             if S[int((r+g)/2)] == 'B':
#                 count -= 1

for i in range(N):
    for j in range(i+1, N):
        k = 2*j - i
        if k < N and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            count -= 1


print(count)