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

rli = []
gli = []
bli = []
for i in range(N):
    if S[i] == "R":
        rli.append(i+1)
    if S[i] == "G":
        gli.append(i+1)
    if S[i] == "B":
        bli.append(i+1)
ans = 0
mx = max(len(rli), len(gli), len(bli))

if mx == len(rli):
    for i in gli:
        for j in bli:
            sa = max(i,j)-min(i,j)
            scr = len(rli)
            if min(i,j)-sa in rli:
                scr -= 1
            if (i+j)/2 in rli:
                scr -= 1
            if max(i,j)+sa in rli:
                scr -= 1
            ans += scr
elif mx == len(gli):
    for i in rli:
        for j in bli:
            sa = max(i,j)-min(i,j)
            scr = len(gli)
            if min(i,j)-sa in gli:
                scr -= 1
            if (i+j)/2 in gli:
                scr -= 1
            if max(i,j)+sa in gli:
                scr -= 1
            ans += scr
else:
    for i in rli:
        for j in gli:
            sa = max(i,j)-min(i,j)
            scr = len(bli)
            if min(i,j)-sa in bli:
                scr -= 1
            if (i+j)/2 in bli:
                scr -= 1
            if max(i,j)+sa in bli:
                scr -= 1
            ans += scr

print(ans)

Fixed submission:
N = int(input())
S = list(input())
rli = []
gli = []
bli = []
for i in range(N):
    if S[i] == "R":
        rli.append(i+1)
    if S[i] == "G":
        gli.append(i+1)
    if S[i] == "B":
        bli.append(i+1)
ans = len(rli)*len(gli)*len(bli)
for i in range(N):
    for j in range(i+1, ((N-i)//2+(N-i)%2)+i):
        if S[i] != S[j] and S[j] != S[2*j-i] and S[2*j-i] != S[i]:
            ans -= 1
print(ans)

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

rli = []
gli = []
bli = []
for i in range(N):
    if S[i] == "R":
        rli.append(i+1)
    if S[i] == "G":
        gli.append(i+1)
    if S[i] == "B":
        bli.append(i+1)
ans = 0
mx = max(len(rli), len(gli), len(bli))

if mx == len(rli):
    for i in gli:
        for j in bli:
            sa = max(i,j)-min(i,j)
            scr = len(rli)
            if min(i,j)-sa in rli:
                scr -= 1
            if (i+j)/2 in rli:
                scr -= 1
            if max(i,j)+sa in rli:
                scr -= 1
            ans += scr
elif mx == len(gli):
    for i in rli:
        for j in bli:
            sa = max(i,j)-min(i,j)
            scr = len(gli)
            if min(i,j)-sa in gli:
                scr -= 1
            if (i+j)/2 in gli:
                scr -= 1
            if max(i,j)+sa in gli:
                scr -= 1
            ans += scr
else:
    for i in rli:
        for j in gli:
            sa = max(i,j)-min(i,j)
            scr = len(bli)
            if min(i,j)-sa in bli:
                scr -= 1
            if (i+j)/2 in bli:
                scr -= 1
            if max(i,j)+sa in bli:
                scr -= 1
            ans += scr

print(ans)

Fixed submission:
N = int(input())
S = list(input())
rli = []
gli = []
bli = []
for i in range(N):
    if S[i] == "R":
        rli.append(i+1)
    if S[i] == "G":
        gli.append(i+1)
    if S[i] == "B":
        bli.append(i+1)
ans = len(rli)*len(gli)*len(bli)
for i in range(N):
    for j in range(i+1, ((N-i)//2+(N-i)%2)+i):
        if S[i] != S[j] and S[j] != S[2*j-i] and S[2*j-i] != S[i]:
            ans -= 1
print(ans)

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

rli = []
gli = []
bli = []
for i in range(N):
    if S[i] == "R":
        rli.append(i+1)
    if S[i] == "G":
        gli.append(i+1)
    if S[i] == "B":
        bli.append(i+1)

ans = 0
for i in rli:
    for j in gli:
        sa = max(i,j)-min(i,j)
        scr = len(bli)
        if min(i,j)-sa in bli:
            scr -= 1
        if (i+j)/2 in bli:
            scr -= 1
        if max(i,j)+sa in bli:
            scr -= 1
        ans += scr

print(ans)

Fixed submission:
N = int(input())
S = list(input())
rli = []
gli = []
bli = []
for i in range(N):
    if S[i] == "R":
        rli.append(i+1)
    if S[i] == "G":
        gli.append(i+1)
    if S[i] == "B":
        bli.append(i+1)
ans = len(rli)*len(gli)*len(bli)
for i in range(N):
    for j in range(i+1, ((N-i)//2+(N-i)%2)+i):
        if S[i] != S[j] and S[j] != S[2*j-i] and S[2*j-i] != S[i]:
            ans -= 1
print(ans)