Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
from collections import deque
C =[deque([]),deque([]),deque([])]
for i in range(N):
    if S[i] == 'R':
        C[0].append(i)
    elif S[i] == 'G':
        C[1].append(i)
    else:
        C[2].append(i)

count = 0
l = len(C[2])
for i in C[0]:
    for j in C[1]:
        count += l
        if max(i,j) + abs(j-i) in C[2]:
            count -= 1
        if min(i,j) - abs(j-i) in C[2]:
            count -= 1
        if (i + j)%2 == 0 and (i + j)//2 in C[2]:
            count -= 1


print(count)


Fixed submission:
N = int(input())
S = input()
from collections import deque
C =[deque([]),deque([]),deque([])]
for i in range(N):
    if S[i] == 'R':
        C[0].append(i)
    elif S[i] == 'G':
        C[1].append(i)
    else:
        C[2].append(i)

count = len(C[0])*len(C[1])*len(C[2])

for i in C[0]:
    for j in C[1]:
        if max(i,j) + abs(j-i)<N and S[max(i,j) + abs(j-i)] == "B":
            count -= 1
        if min(i,j) - abs(j-i)>=0 and S[min(i,j) - abs(j-i)] == "B":
            count -= 1
        if (i + j)%2 == 0 and S[(i + j)//2] == "B":
            count -= 1


print(count)

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

C =[[],[],[]]
for i in range(N):
    if S[i] == 'R':
        C[0].append(i)
    elif S[i] == 'G':
        C[1].append(i)
    else:
        C[2].append(i)

count = 0
for i in C[0]:
    for j in C[1]:
        count += len(C[2])
        if max(i,j) + abs(j-i) in C[2]:
            count -= 1
        if min(i,j) - abs(j-i) in C[2]:
            count -= 1
        if (i + j)%2 == 0 and (i + j)//2 in C[2]:
            count -= 1
        

print(count)


Fixed submission:
N = int(input())
S = input()
from collections import deque
C =[deque([]),deque([]),deque([])]
for i in range(N):
    if S[i] == 'R':
        C[0].append(i)
    elif S[i] == 'G':
        C[1].append(i)
    else:
        C[2].append(i)

count = len(C[0])*len(C[1])*len(C[2])

for i in C[0]:
    for j in C[1]:
        if max(i,j) + abs(j-i)<N and S[max(i,j) + abs(j-i)] == "B":
            count -= 1
        if min(i,j) - abs(j-i)>=0 and S[min(i,j) - abs(j-i)] == "B":
            count -= 1
        if (i + j)%2 == 0 and S[(i + j)//2] == "B":
            count -= 1


print(count)

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

C =[[],[],[]]
for i in range(N):
    if S[i] == 'R':
        C[0].append(i)
    elif S[i] == 'G':
        C[1].append(i)
    else:
        C[2].append(i)

count = 0
for i in C[0]:
    for j in C[1]:
        for k in C[2]:
            ls = [i,j,k]
            ls.sort()
            if ls[1]-ls[0] != ls[2]-ls[1]:
                count += 1

print(count)



Fixed submission:
N = int(input())
S = input()
from collections import deque
C =[deque([]),deque([]),deque([])]
for i in range(N):
    if S[i] == 'R':
        C[0].append(i)
    elif S[i] == 'G':
        C[1].append(i)
    else:
        C[2].append(i)

count = len(C[0])*len(C[1])*len(C[2])

for i in C[0]:
    for j in C[1]:
        if max(i,j) + abs(j-i)<N and S[max(i,j) + abs(j-i)] == "B":
            count -= 1
        if min(i,j) - abs(j-i)>=0 and S[min(i,j) - abs(j-i)] == "B":
            count -= 1
        if (i + j)%2 == 0 and S[(i + j)//2] == "B":
            count -= 1


print(count)