Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N = int(input())
I = input()

R = I.count('R')
G = I.count('G')
B = I.count('B')

sum = R * G * B

for i in range(N):
    for j in range(i+1,N):
        if I[i] != I[j]:
            k = j + j - i
            if k >= N:
                continue
            if I[i] != I[k] and I[j] != I[k]:
                sum -= 1

print(sum)

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
I = input()

R =0
G =0
B =0
for i in range(N):
    if (I[i] == 'R'):
        R+=1
    if (I[i] == 'G'):
        G+=1
    if (I[i] == 'B'):
        B+=1


sum = R * G * B

for i in range(N):
    for j in range(i+1,N):
        if I[i] != I[j]:
            k = j + j - i
            if k >= N:
                continue
            if I[i] != I[k] and I[j] != I[k]:
                sum -= 1

print(sum)

Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
I = input()

R = I.count('R')
G = I.count('G')
B = I.count('B')

sum = R * G * B

for i in range(N):
    for j in range(i+1,N):
        if I[i] != I[j]:
            k = j + j - i
            if k >= N:
                continue
            if I[i] != I[k] and I[j] != I[k]:
                sum -= 1

print(sum)

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
I = input()

R =0
G =0
B =0
for i in range(N):
    if (I[i] == 'R'):
        R+=1
    if (I[i] == 'G'):
        G+=1
    if (I[i] == 'B'):
        B+=1


sum = R * G * B

for i in range(N):
    for j in range(i+1,N):
        if I[i] != I[j]:
            k = j + j - i
            if k >= N:
                continue
            if I[i] != I[k] and I[j] != I[k]:
                sum -= 1

print(sum)

Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
I = input()

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

ans = len(R) * len(G) * len(B)

for a in R:
    for b in G:
        for c in B:
            abs1 = abs(a - b)
            abs2 = abs(b - c)
            abs3 = abs(c - a)
            
            if( abs1 == abs2 or abs2 == abs3 or abs3 == abs1 ):
                ans -= 1

print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
I = input()

R =0
G =0
B =0
for i in range(N):
    if (I[i] == 'R'):
        R+=1
    if (I[i] == 'G'):
        G+=1
    if (I[i] == 'B'):
        B+=1


sum = R * G * B

for i in range(N):
    for j in range(i+1,N):
        if I[i] != I[j]:
            k = j + j - i
            if k >= N:
                continue
            if I[i] != I[k] and I[j] != I[k]:
                sum -= 1

print(sum)

Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
I = input()

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

ans = 0

for a in R:
    for b in G:
        for c in B:
            n = sorted([a, b, c])
            if( (n[2] - n[1]) != (n[1] - n[0]) ):
                ans += 1

print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
I = input()

R =0
G =0
B =0
for i in range(N):
    if (I[i] == 'R'):
        R+=1
    if (I[i] == 'G'):
        G+=1
    if (I[i] == 'B'):
        B+=1


sum = R * G * B

for i in range(N):
    for j in range(i+1,N):
        if I[i] != I[j]:
            k = j + j - i
            if k >= N:
                continue
            if I[i] != I[k] and I[j] != I[k]:
                sum -= 1

print(sum)