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

Klist = [N-1]
IJ = list()
for i in range(N-2):
    for j in range(i+1, N-1):
        if not S[i] == S[j]:
            IJ.append((i, j))
            Klist.append(j)
K = sorted(list(set(Klist)), reverse=True)
if 0 in K:
    K.remove(0)
if 1 in K:
    K.remove(1)
for ij in IJ:
    i, j = ij
    for k in K:
        if not j < k:
            break
        if S[j] == S[k]:
            continue
        if S[i] == S[k]:
            continue
        if j-i == k-j:
            continue
        ans += 1
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N):
    for j in range(i, N):
        k = 2*j - i
        if N > k and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans -= 1
print(ans)

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

Klist = [N-1]
IJ = list()
for i in range(N-2):
    for j in range(i+1, N-1):
        if not S[i] == S[j]:
            IJ.append((i, j))
            Klist.append(j)
K = sorted(list(set(Klist)), reverse=True)
for ij in IJ:
    i, j = ij
    for k in K:
        if not j < k:
            break
        if S[j] == S[k]:
            continue
        if S[i] == S[k]:
            continue
        if j-i == k-j:
            continue
        ans += 1
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N):
    for j in range(i, N):
        k = 2*j - i
        if N > k and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = 0
JK = list()
Ilist = [0]
for k in range(2, N):
    for j in range(1, k):
        if not S[j] == S[k]:
            JK.append((j, k))
            Ilist.append(j)

Iset = set(Ilist)
for jk in JK:
    j, k = jk
    for i in Iset:
        if not i < j:
            break
        if S[i] == S[j]:
            continue
        if S[i] == S[k]:
            continue
        if j-i == k-j:
            continue
        ans += 1
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N):
    for j in range(i, N):
        k = 2*j - i
        if N > k and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())
S = input()
ans = 0
JK = list()
for k in range(2, N):
    for j in range(1, k):
        if not S[j] == S[k]:
            JK.append((j, k))
for jk in JK:
    j, k = jk
    for i in range(j):
        if S[i] == S[j]:
            continue
        if S[i] == S[k]:
            continue
        if j-i == k-j:
            continue
        ans += 1
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N):
    for j in range(i, N):
        k = 2*j - i
        if N > k and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())
S = input()
ans = 0
for k in range(2, N):
    for j in range(1, k):
        if S[j] == S[k]:
            continue
        for i in range(j):
            if S[i] == S[j]:
                continue
            if S[i] == S[k]:
                continue
            if j-i == k-j:
                continue
            ans += 1
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N):
    for j in range(i, N):
        k = 2*j - i
        if N > k and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans -= 1
print(ans)