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

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

count = collections.Counter(S)

ans = count['R'] * count['G'] * count['B']

for i in range(N):
    for j in range(1, (N - 1) // 2 + 1):
        if i + 2 * j < N:
            if len({S[i], S[i + j], S[i + 2 * j]}) == 3:
                ans -= 1
    

print(ans)

Fixed submission:
import collections

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

count = collections.Counter(S)

ans = count['R'] * count['G'] * count['B']

for distance in range(1, (N - 1) // 2 + 1):
    for i in range(N):
        if i + 2 * distance >= N:
            break
        
        if len({S[i], S[i + distance], S[i + 2 * distance]}) == 3:
             ans -= 1
    

print(ans)

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

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

count = collections.Counter(S)

ans = count['R'] * count['G'] * count['B']

for i in range(N):
    for j in range(1, (N - 1) // 2 + 1):
        if i + 2 * j < N:
            if len({S[i], S[i + j], S[i + 2 * j]}) == 3:
                ans -= 1
    

print(ans)

Fixed submission:
import collections

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

count = collections.Counter(S)

ans = count['R'] * count['G'] * count['B']

for distance in range(1, (N - 1) // 2 + 1):
    for i in range(N):
        if i + 2 * distance >= N:
            break
        
        if len({S[i], S[i + distance], S[i + 2 * distance]}) == 3:
             ans -= 1
    

print(ans)

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

N = int(input())
S = input()
ans = 0

count = collections.Counter(S)

R_list = [count['R']]
G_list = [count['G']]
B_list = [count['B']]

for i in range(N):
    if S[i] == 'R':
        R_list.append(R_list[i] - 1)
        G_list.append(G_list[i])
        B_list.append(B_list[i])
    elif S[i] == 'G':
        R_list.append(R_list[i])
        G_list.append(G_list[i] - 1)
        B_list.append(B_list[i])
    else:
        R_list.append(R_list[i])
        G_list.append(G_list[i])
        B_list.append(B_list[i] - 1)

for i in range(N - 2):
    for j in range(i, N - 1):
        rest_str = {'R', 'G', 'B'} - {S[i], S[j]}
        
        if len(rest_str) != 1:
            continue
        
        if rest_str == {'B'}:
            ans += B_list[j + 1]
        elif rest_str == {'R'}:
            ans += R_list[j + 1]
        elif rest_str == {'G'}:
            ans += G_list[j + 1]
        
        if j + (j - i) <= N - 1:
            if {S[i], S[j], S[2 * j - i]} == {'R', 'B', 'G'}:
                ans -= 1
                
print(ans)

Fixed submission:
import collections

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

count = collections.Counter(S)

ans = count['R'] * count['G'] * count['B']

for distance in range(1, (N - 1) // 2 + 1):
    for i in range(N):
        if i + 2 * distance >= N:
            break
        
        if len({S[i], S[i + distance], S[i + 2 * distance]}) == 3:
             ans -= 1
    

print(ans)

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

N = int(input())
S = input()
ans = 0

count = collections.Counter(S)

R_list = [count['R']]
G_list = [count['G']]
B_list = [count['B']]

for i in range(N):
    if S[i] == 'R':
        R_list.append(R_list[i] - 1)
        G_list.append(G_list[i])
        B_list.append(B_list[i])
    elif S[i] == 'G':
        R_list.append(R_list[i])
        G_list.append(G_list[i] - 1)
        B_list.append(B_list[i])
    else:
        R_list.append(R_list[i])
        G_list.append(G_list[i])
        B_list.append(B_list[i] - 1)

for i in range(N - 2):
    for j in range(i, N - 1):
        if {S[i], S[j]} == {'R', 'G'}:
            ans += B_list[j + 1]
        elif {S[i], S[j]} == {'G', 'B'}:
            ans += R_list[j + 1]
        elif {S[i], S[j]} == {'B', 'R'}:
            ans += G_list[j + 1]
        
        if j + (j - i) <= N -1:
            if {S[i], S[j], S[2 * j - i]} == {'R', 'B', 'G'}:
                ans -= 1
print(ans)

Fixed submission:
import collections

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

count = collections.Counter(S)

ans = count['R'] * count['G'] * count['B']

for distance in range(1, (N - 1) // 2 + 1):
    for i in range(N):
        if i + 2 * distance >= N:
            break
        
        if len({S[i], S[i + distance], S[i + 2 * distance]}) == 3:
             ans -= 1
    

print(ans)

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

for i in range(N):
    for j in range(i, N):
        for k in range(j, N):
            if j - i == k - j:
                continue
            elif len(set([S[i], S[j], S[k]])) == 3:
                ans += 1

print(ans)

Fixed submission:
import collections

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

count = collections.Counter(S)

ans = count['R'] * count['G'] * count['B']

for distance in range(1, (N - 1) // 2 + 1):
    for i in range(N):
        if i + 2 * distance >= N:
            break
        
        if len({S[i], S[i + distance], S[i + 2 * distance]}) == 3:
             ans -= 1
    

print(ans)