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

def judge(numlist):
    if numlist[2] + numlist[0] == 2 * numlist[1]:
        return False
    else:
        return True

N = int(input())
S = list(input())
R = []
G = []
B = []

for i in range(N):
    if S[i] == 'R':
        R.append(i)
    elif S[i] == 'G':
        G.append(i)
    else:
        B.append(i)

RG = product(R,G)
RGcombs = []
for i in RG:
    RGcombs.append(sorted(list(i)))

ans = 0
for comb in RGcombs:
    for k in B:
        if k < comb[0]:
            if judge([k]+list(comb)):
                ans += 1
        elif k > comb[1]:
            if judge(list(comb)+[k]):
                ans += 1
        else:
            c = list(comb)
            if judge([c[0],k,c[1]]):
                ans += 1

print(ans)

Fixed submission:
N = int(input())
S = list(input())
r = 0
g = 0
b = 0

for i in range(N):
    if S[i] == 'R':
        r += 1
    elif S[i] == 'G':
        g += 1
    else:
        b += 1

allcnt = r * g * b

sub = 0
for i in range(N):
    for j in range(i+1,N):
        if S[i] == S[j]:
            None
        else:
            k = 2*j-i
            if k >= N or S[i] == S[k] or S[j] == S[k]:
                None
            else:
                sub += 1

print(allcnt - sub)

Buggy python submission (verdict: Time Limit Exceeded):
def judge(numlist):
    if numlist[2] + numlist[0] == 2 * numlist[1]:
        return False
    else:
        return True

N = int(input())
S = list(input())
R = []
G = []
B = []

for i in range(N):
    if S[i] == 'R':
        R.append(i)
    elif S[i] == 'G':
        G.append(i)
    else:
        B.append(i)

RGcombs = []

for i in R:
    for j in G:
        if i < j:
            RGcombs.append([i,j])
        else:
            RGcombs.append([j,i])

ans = 0
for comb in RGcombs:
    for k in B:
        if k < comb[0]:
            if judge([k]+comb):
                ans += 1
        elif k > comb[1]:
            if judge(comb+[k]):
                ans += 1
        else:
            if judge([comb[0],k,comb[1]]):
                ans += 1

print(ans)

Fixed submission:
N = int(input())
S = list(input())
r = 0
g = 0
b = 0

for i in range(N):
    if S[i] == 'R':
        r += 1
    elif S[i] == 'G':
        g += 1
    else:
        b += 1

allcnt = r * g * b

sub = 0
for i in range(N):
    for j in range(i+1,N):
        if S[i] == S[j]:
            None
        else:
            k = 2*j-i
            if k >= N or S[i] == S[k] or S[j] == S[k]:
                None
            else:
                sub += 1

print(allcnt - sub)

Buggy python submission (verdict: Time Limit Exceeded):
def judge(numlist):
    if numlist[2] + numlist[0] == 2 * numlist[1]:
        return False
    else:
        return True

N = int(input())
S = list(input())
R = []
G = []
B = []

for i in range(N):
    if S[i] == 'R':
        R.append(i)
    elif S[i] == 'G':
        G.append(i)
    else:
        B.append(i)

RGcombs = []

for i in R:
    for j in G:
        if i < j:
            RGcombs.append([i,j])
        else:
            RGcombs.append([j,i])

RGBcombs = []

for comb in RGcombs:
    for k in B:
        if k < comb[0]:
            RGBcombs.append([k]+comb)
        elif k > comb[1]:
            RGBcombs.append(comb+[k])
        else:
            RGBcombs.append([comb[0],k,comb[1]])

ans = 0
for satcomb in RGBcombs:
    if judge(satcomb):
        ans += 1

print(ans)

Fixed submission:
N = int(input())
S = list(input())
r = 0
g = 0
b = 0

for i in range(N):
    if S[i] == 'R':
        r += 1
    elif S[i] == 'G':
        g += 1
    else:
        b += 1

allcnt = r * g * b

sub = 0
for i in range(N):
    for j in range(i+1,N):
        if S[i] == S[j]:
            None
        else:
            k = 2*j-i
            if k >= N or S[i] == S[k] or S[j] == S[k]:
                None
            else:
                sub += 1

print(allcnt - sub)