Buggy python submission (verdict: Runtime Error):
N=int(input())
K=input()
dic = {}
for t in ts:
    p=[]
    for ir, r in enumerate(K):
        if r == t:
            p.append(ir)
    dic[t] = p
ans1 = len(dic['R']) * len(dic['G']) * len(dic['B'])

ans2 = 0

for i in range(N):
    for j in range(i):
        if (i + 2*(j-i) < N):
            if  K[i] != K[j] and K[i] != K[i + 2*(j-i)] and K[i+2*(j-i)] != K[j]:
                ans2 +=1

print(ans1 - ans2)


Fixed submission:
N=int(input())
K=input()
dic = {}
ts = 'RGB'
for t in ts:
    p=[]
    for ir, r in enumerate(K):
        if r == t:
            p.append(ir)
    dic[t] = p
ans1 = len(dic['R']) * len(dic['G']) * len(dic['B'])

ans2 = 0

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

print(ans1 - ans2)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N=int(input())
K=list(input())

ans = 0
while len(K)>3:
    a = K.pop()
    for i, b in enumerate(K):
        if b != a:
            k = K[i+1:]
    
            for ii,c in enumerate(k):
                    if (c != b) and (c != a):
                        if (ii != (len(k)-1)/2):
                            ans +=1
                 
print(ans)


Fixed submission:
N=int(input())
K=input()
dic = {}
ts = 'RGB'
for t in ts:
    p=[]
    for ir, r in enumerate(K):
        if r == t:
            p.append(ir)
    dic[t] = p
ans1 = len(dic['R']) * len(dic['G']) * len(dic['B'])

ans2 = 0

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

print(ans1 - ans2)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N=int(input())
K=list(input())

ans = 0
while len(K)>3:
    a = K.pop()
    for i, b in enumerate(K):
        if b != a:
            k = K[i+1:]
    
            for ii,c in enumerate(k):
                    if (c != b) and (c != a) and (ii != (len(k)-1)/2):
                        ans +=1
                 
print(ans)


Fixed submission:
N=int(input())
K=input()
dic = {}
ts = 'RGB'
for t in ts:
    p=[]
    for ir, r in enumerate(K):
        if r == t:
            p.append(ir)
    dic[t] = p
ans1 = len(dic['R']) * len(dic['G']) * len(dic['B'])

ans2 = 0

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

print(ans1 - ans2)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N=int(input())
K=list(input())

ans = 0
while len(K)>3:
    a = K.pop()
    for i, b in enumerate(K):
        if b != a:
            k = K[i+1:]
    
            for ii,c in enumerate(k):
                    if (c != b) and (c != a) and (ii != (len(k)-1)/2):
                        ans +=1
                 
print(ans)


Fixed submission:
N=int(input())
K=input()
dic = {}
ts = 'RGB'
for t in ts:
    p=[]
    for ir, r in enumerate(K):
        if r == t:
            p.append(ir)
    dic[t] = p
ans1 = len(dic['R']) * len(dic['G']) * len(dic['B'])

ans2 = 0

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

print(ans1 - ans2)