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

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

count = 0
for r in r_list:
    for g in g_list:
        if min(r, g) - abs(r - g) > 0:
            if s[min(r, g) - abs(r - g)] == "B":
                count += 1
        if max(r, g) + abs(r - g) < n:
            if s[max(r, g) + abs(r - g)] == "B":
                count += 1
        if (r + g) % 2 == 0:
            if s[(r + g) // 2] == "B":
                count += 1


print(len(r_list) * len(g_list) * (n - len(r_list) - len(g_list)) - count)

Fixed submission:
n = int(input())
s = input()

r_list = []
g_list = []
for _ in range(n):
    if s[_] == "R":
        r_list.append(_)
    elif s[_] == "G":
        g_list.append(_)

count = 0
for r in r_list:
    for g in g_list:
        if min(r, g) - abs(r - g) > 0:
            if s[min(r, g) - abs(r - g)] == "B":
                count += 1
        if max(r, g) + abs(r - g) < n:
            if s[max(r, g) + abs(r - g)] == "B":
                count += 1
        if (r + g) % 2 == 0:
            if s[(r + g) // 2] == "B":
                count += 1


print(len(r_list) * len(g_list) * (n - len(r_list) - len(g_list)) - count)

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

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

count = 0
for r in r_list:
    for g in g_list:
        if min(r, g) - abs(r - g) in b_list:
            count += 1
        if max(r, g) + abs(r - g) in b_list:
            count += 1
        if (r + g) % 2 == 0:
            if (r + g) // 2 in b_list:
                count += 1
                
print(len(r_list) * len(g_list) * len(b_list) - count)

Fixed submission:
n = int(input())
s = input()

r_list = []
g_list = []
for _ in range(n):
    if s[_] == "R":
        r_list.append(_)
    elif s[_] == "G":
        g_list.append(_)

count = 0
for r in r_list:
    for g in g_list:
        if min(r, g) - abs(r - g) > 0:
            if s[min(r, g) - abs(r - g)] == "B":
                count += 1
        if max(r, g) + abs(r - g) < n:
            if s[max(r, g) + abs(r - g)] == "B":
                count += 1
        if (r + g) % 2 == 0:
            if s[(r + g) // 2] == "B":
                count += 1


print(len(r_list) * len(g_list) * (n - len(r_list) - len(g_list)) - count)

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

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

count = 0
for r in r_list:
    for g in g_list:
        for b in b_list:
            List = sorted([r, g, b])
            if List[0] + List[2] != List[1] * 2:
                count += 1

print(count)

Fixed submission:
n = int(input())
s = input()

r_list = []
g_list = []
for _ in range(n):
    if s[_] == "R":
        r_list.append(_)
    elif s[_] == "G":
        g_list.append(_)

count = 0
for r in r_list:
    for g in g_list:
        if min(r, g) - abs(r - g) > 0:
            if s[min(r, g) - abs(r - g)] == "B":
                count += 1
        if max(r, g) + abs(r - g) < n:
            if s[max(r, g) + abs(r - g)] == "B":
                count += 1
        if (r + g) % 2 == 0:
            if s[(r + g) // 2] == "B":
                count += 1


print(len(r_list) * len(g_list) * (n - len(r_list) - len(g_list)) - count)

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

count = 0
for k in range(2, n):
    for j in range(1, k):
        for i in range(j):
            if k - j != j - i \
                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_list = []
g_list = []
for _ in range(n):
    if s[_] == "R":
        r_list.append(_)
    elif s[_] == "G":
        g_list.append(_)

count = 0
for r in r_list:
    for g in g_list:
        if min(r, g) - abs(r - g) > 0:
            if s[min(r, g) - abs(r - g)] == "B":
                count += 1
        if max(r, g) + abs(r - g) < n:
            if s[max(r, g) + abs(r - g)] == "B":
                count += 1
        if (r + g) % 2 == 0:
            if s[(r + g) // 2] == "B":
                count += 1


print(len(r_list) * len(g_list) * (n - len(r_list) - len(g_list)) - count)