Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())

r_num = S.count("R")
g_num = S.count("G")
b_num = S.count("B")

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

print(r_num * g_num * b_num - count)

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

r_num = S.count("R")
g_num = S.count("G")
b_num = S.count("B")

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

print(r_num * g_num * b_num - count)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations, product

N = int(input())
S = list(input())

indices_R = [i for i in range(N) if S[i] == "R"]
indices_G = [i for i in range(N) if S[i] == "G"]
indices_B = [i for i in range(N) if S[i] == "B"]

count = 0
for ijk in product(indices_R, indices_G, indices_B):
    i, j, k = sorted(ijk)
    if j - i != k - j:
        count += 1

print(count)

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

r_num = S.count("R")
g_num = S.count("G")
b_num = S.count("B")

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

print(r_num * g_num * b_num - count)

Buggy python submission (verdict: Time Limit Exceeded):

from itertools import permutations, product

N = int(input())
S = list(input())

R_indices = [i for i in range(N) if S[i] == "R"]
G_indices = [i for i in range(N) if S[i] == "G"]
B_indices = [i for i in range(N) if S[i] == "B"]

count = 0
for indices_1, indices_2, indices_3 in permutations([R_indices, G_indices, B_indices]):
    j_idx_prev = -1
    for i in indices_1:
        j_idx = len(indices_2)
        ng = j_idx_prev
        while j_idx - ng > 1:
            m = (j_idx + ng) // 2
            if i < indices_2[m]:
                j_idx = m
            else:
                ng = m

        j_idx_prev = j_idx - 1
        k_idx_prev = -1
        for j in indices_2[j_idx:]:
            k_idx = len(indices_3)
            ng = k_idx_prev
            while k_idx - ng > 1:
                m = (k_idx + ng) // 2
                if j < indices_3[m]:
                    k_idx = m
                else:
                    ng = m

            k_idx_prev = k_idx - 1
            for k in indices_3[k_idx:]:
                if j - i != k - j:
                    count += 1

print(count)


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

r_num = S.count("R")
g_num = S.count("G")
b_num = S.count("B")

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

print(r_num * g_num * b_num - count)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations, product

N = int(input())
S = list(input())

R_indices = [i for i in range(N) if S[i] == "R"]
G_indices = [i for i in range(N) if S[i] == "G"]
B_indices = [i for i in range(N) if S[i] == "B"]

count = 0
for indices_1, indices_2, indices_3 in permutations([R_indices, G_indices, B_indices]):
    j_idx_prev = -1
    for i in indices_1:
        j_idx = len(indices_2)
        ng = j_idx_prev
        while j_idx - ng > 1:
            m = (j_idx + ng) // 2
            if i < indices_2[m]:
                j_idx = m
            else:
                ng = m

        j_idx_prev = j_idx - 1
        k_idx_prev = -1
        for j in indices_2[j_idx:]:
            k_idx = len(indices_3)
            ng = k_idx_prev
            while k_idx - ng > 1:
                m = (k_idx + ng) // 2
                if j < indices_3[m]:
                    k_idx = m
                else:
                    ng = m

            k_idx_prev = k_idx - 1
            for k in indices_3[k_idx:]:
                if j - i != k - j:
                    count += 1

print(count)

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

r_num = S.count("R")
g_num = S.count("G")
b_num = S.count("B")

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

print(r_num * g_num * b_num - count)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations, product

N = int(input())
S = list(input())

R_indices = [i for i in range(N) if S[i] == "R"]
G_indices = [i for i in range(N) if S[i] == "G"]
B_indices = [i for i in range(N) if S[i] == "B"]

count = 0
for indices_1, indices_2, indices_3 in permutations([R_indices, G_indices, B_indices]):
    for i in indices_1:
        j_idx = len(indices_2)
        ng = -1
        while j_idx - ng > 1:
            m = (j_idx + ng) // 2
            if i < indices_2[m]:
                j_idx = m
            else:
                ng = m
        for j in indices_2[j_idx:]:
            k_idx = len(indices_3)
            ng = -1
            while k_idx - ng > 1:
                m = (k_idx + ng) // 2
                if j < indices_3[m]:
                    k_idx = m
                else:
                    ng = m
            for k in indices_3[k_idx:]:
                if j - i != k - j:
                    count += 1

print(count)

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

r_num = S.count("R")
g_num = S.count("G")
b_num = S.count("B")

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

print(r_num * g_num * b_num - count)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations, product

N = int(input())
S = list(input())

R_indices = [i for i in range(N) if S[i] == "R"]
G_indices = [i for i in range(N) if S[i] == "G"]
B_indices = [i for i in range(N) if S[i] == "B"]

count = 0
for indices_tuple in permutations([R_indices, G_indices, B_indices]):
    for i, j, k in product(*indices_tuple):
        if i < j < k and j - i != k - j:
            count += 1

print(count)

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

r_num = S.count("R")
g_num = S.count("G")
b_num = S.count("B")

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

print(r_num * g_num * b_num - count)