Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

n = int(stdin.readline().rstrip())
data = list(stdin.readline().rstrip().split()[0])

r_list = []
g_list = []
b_list = []


for i in range(n):
    if data[i] == "R":
        r_list.append(i)
    elif data[i] == "G":
        g_list.append(i)
    else:
        b_list.append(i)

count = len(r_list) * len(g_list) * len(b_list)

for r in r_list:
    for g in g_list:
        for b in b_list:
            if abs(r-g) == abs(g-b) or abs(r-b) == abs(g-b) or abs(r-b) == abs(r-g):
                count -= 1

print(count)

Fixed submission:
N = int(input())
S = input()

R_cnt, G_cnt, B_cnt = 0, 0, 0

for i in range(len(S)):
    if S[i] == "R":
        R_cnt += 1
    elif S[i] == "G":
        G_cnt += 1
    else:
        B_cnt += 1

All = R_cnt * G_cnt * B_cnt

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

print(All)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

n = int(stdin.readline().rstrip())
data = list(stdin.readline().rstrip().split()[0])

count = 0

c_list = [["R", "G", "B"], ["R", "B", "G"], ["G", "R", "B"], ["G", "B", "R"], ["B", "R", "G"], ["B", "G", "R"]]

for temp_list in c_list:
    for i in range(n):
        if data[i] != temp_list[0]:
            continue
        else:
            for j in range(i+1, n):
                if data[j] != temp_list[1]:
                    continue
                else:
                    for k in range(j+1, n):
                        if data[k] == temp_list[2]:
                            if (k - j) != (j - i):
                                count += 1
                                
print(count)

Fixed submission:
N = int(input())
S = input()

R_cnt, G_cnt, B_cnt = 0, 0, 0

for i in range(len(S)):
    if S[i] == "R":
        R_cnt += 1
    elif S[i] == "G":
        G_cnt += 1
    else:
        B_cnt += 1

All = R_cnt * G_cnt * B_cnt

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

print(All)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

n = int(stdin.readline().rstrip())
data = list(stdin.readline().rstrip().split()[0])

count = 0

for i in range(n):
    s_1 = data[i]
    for j in range(i+1, n):
        if s_1 != data[j]:
            s_2 = data[j]
            for k in range(j+1, n):
                s_3 = data[k]
                if s_1 != s_3 and s_2 != s_3:
                    if (k - j) != (j - i):
                        count += 1

print(count)

Fixed submission:
N = int(input())
S = input()

R_cnt, G_cnt, B_cnt = 0, 0, 0

for i in range(len(S)):
    if S[i] == "R":
        R_cnt += 1
    elif S[i] == "G":
        G_cnt += 1
    else:
        B_cnt += 1

All = R_cnt * G_cnt * B_cnt

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

print(All)