Buggy python submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')

sum = r*g*b

for i in range(N):
    for j in range(i+1, N):
        k = 2 * j - i
        if not S[i] == S[j] and not S[j] == S[k] and not S[k] == S[i]:
            sum -= 1
print(sum)

Fixed submission:
from collections import Counter

N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')

sum = r*g*b

for i in range(N):
    for j in range(i+1, N):
        k = 2 * j - i
        if k > N - 1:
            break
        if not S[i] == S[j] and not S[j] == S[k] and not S[k] == S[i]:
            sum -= 1
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')

sum = r*g*b

for i in range(N):
    for j in range(i+1, N):
        A = ['R','G','B']
        if S[i] == S[j]:
            continue
        
        A.remove(S[i])
        A.remove(S[j])
            
        # S[k]
        k = 2 * j - i
        if k < len(S):
            if S[k] == A[0]:
                sum -= 1
print(sum)

Fixed submission:
from collections import Counter

N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')

sum = r*g*b

for i in range(N):
    for j in range(i+1, N):
        k = 2 * j - i
        if k > N - 1:
            break
        if not S[i] == S[j] and not S[j] == S[k] and not S[k] == S[i]:
            sum -= 1
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
S = input()

sum = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] == S[j]:
            continue

        RGB = ['R','G','B']
        RGB.remove(S[j])
        RGB.remove(S[i])
        c = Counter(S[(j+1):])
        sum += c[RGB[0]]

        # S[k]
        k = 2 * j - i
        if k < len(S):
            if S[k] == RGB[0]:
                sum -= 1
print(sum)

Fixed submission:
from collections import Counter

N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')

sum = r*g*b

for i in range(N):
    for j in range(i+1, N):
        k = 2 * j - i
        if k > N - 1:
            break
        if not S[i] == S[j] and not S[j] == S[k] and not S[k] == S[i]:
            sum -= 1
print(sum)

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

sum = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] == S[j]:
            continue

        RGB = ['R','G','B']
        RGB.remove(S[j])
        RGB.remove(S[i])
        sum += S[(j+1):].count(RGB[0])

        # S[k]
        k = 2 * j - i
        if k < len(S):
            if S[k] == RGB[0]:
                sum -= 1
print(sum)

Fixed submission:
from collections import Counter

N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')

sum = r*g*b

for i in range(N):
    for j in range(i+1, N):
        k = 2 * j - i
        if k > N - 1:
            break
        if not S[i] == S[j] and not S[j] == S[k] and not S[k] == S[i]:
            sum -= 1
print(sum)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

sum = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] == S[j]:
            continue

        RGB = ['R','G','B']
            RGB.remove(S[j])
            RGB.remove(S[i])
            sum += S[(j+1):].count(RGB[0])

            # S[k]
            k = 2 * j - i
            if k < len(S):
                if S[k] == RGB[0]:
                    sum -= 1
print(sum)

Fixed submission:
from collections import Counter

N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')

sum = r*g*b

for i in range(N):
    for j in range(i+1, N):
        k = 2 * j - i
        if k > N - 1:
            break
        if not S[i] == S[j] and not S[j] == S[k] and not S[k] == S[i]:
            sum -= 1
print(sum)

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

sum = 0
for i in range(N):
    for j in range(i+1, N):
        RGB = ['R','G','B']
        if not S[i] == S[j]:
            RGB.remove(S[i])
            RGB.remove(S[j])
            sum += S[(j+1):].count(RGB[0])

            # S[k]
            k = 2 * j - i
            if k < len(S):
                if S[k] == RGB[0]:
                    sum -= 1
print(sum)

Fixed submission:
from collections import Counter

N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')

sum = r*g*b

for i in range(N):
    for j in range(i+1, N):
        k = 2 * j - i
        if k > N - 1:
            break
        if not S[i] == S[j] and not S[j] == S[k] and not S[k] == S[i]:
            sum -= 1
print(sum)