Buggy python submission (verdict: Runtime Error):
n = int(input())
s = list(input())

ri = [i for i, x in enumerate(s) if x=='R']
gi = [i for i, x in enumerate(s) if x=='G']
bi = [i for i, x in enumerate(s) if x=='B']

ans = len(ri) * len(gi) * len(bi)

for i in range(n):
    for d in range(n):
        j=i+d
        k=i+2*d
        if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
            ans -= 1

print(ans)

Fixed submission:
n = int(input())
s = input()

ri = [i for i, x in enumerate(s) if x=='R']
gi = [i for i, x in enumerate(s) if x=='G']
bi = [i for i, x in enumerate(s) if x=='B']

ans = len(ri) * len(gi) * len(bi)

for i in range(n):
    for d in range(n):
        j=i+d
        k=i+2*d
        if k>=n:
            break
        if 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 = list(input())

r_i = [i for i, x in enumerate(s) if x=='R']
g_i = [i for i, x in enumerate(s) if x=='G']
b_i = [i for i, x in enumerate(s) if x=='B']

ans = 0

for i in range(len(r_i)):
    for j in range(len(g_i)):
        for k in range(len(b_i)):
            ijk = [r_i[i], g_i[j], b_i[k]]
            ijk.sort()
            if ijk[1] - ijk[0] != ijk[2] - ijk[1]:
                ans += 1
print(ans)

Fixed submission:
n = int(input())
s = input()

ri = [i for i, x in enumerate(s) if x=='R']
gi = [i for i, x in enumerate(s) if x=='G']
bi = [i for i, x in enumerate(s) if x=='B']

ans = len(ri) * len(gi) * len(bi)

for i in range(n):
    for d in range(n):
        j=i+d
        k=i+2*d
        if k>=n:
            break
        if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
            ans -= 1

print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = list(map(input().split()))

r_i = [i for i, x in enumerate(s) if x=='R']
g_i = [i for i, x in enumerate(s) if x=='G']
b_i = [i for i, x in enumerate(s) if x=='B']

ans = 0

for i in len(r_i):
    for j in len(g_i):
        for k in len(b_i):
            if r_i[i]!=g_i[j] and g_i[j]!=b_i[k] and b_i[k]!=r_i[i]:
                ans += 1

print(ans)

Fixed submission:
n = int(input())
s = input()

ri = [i for i, x in enumerate(s) if x=='R']
gi = [i for i, x in enumerate(s) if x=='G']
bi = [i for i, x in enumerate(s) if x=='B']

ans = len(ri) * len(gi) * len(bi)

for i in range(n):
    for d in range(n):
        j=i+d
        k=i+2*d
        if k>=n:
            break
        if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
            ans -= 1

print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = list(map(input().split()))

r_i = [i for i, x in enumerate(s) if x=='R']
g_i = [i for i, x in enumerate(s) if x=='G']
b_i = [i for i, x in enumerate(s) if x=='B']

ans = 0

for i in len(r_i):
    for j in len(g_i):
        for k in len(b_i):
            if r_i[i]!=g_i[j] and g_i[j]!=b_i[k] and b_i[k]!=r_i[i]:
                ans += 1

print(ans)

Fixed submission:
n = int(input())
s = input()

ri = [i for i, x in enumerate(s) if x=='R']
gi = [i for i, x in enumerate(s) if x=='G']
bi = [i for i, x in enumerate(s) if x=='B']

ans = len(ri) * len(gi) * len(bi)

for i in range(n):
    for d in range(n):
        j=i+d
        k=i+2*d
        if k>=n:
            break
        if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
            ans -= 1

print(ans)