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

N = int(input())
s = input()
cnt = Counter(s)
R = cnt.get('R', 0)
G = cnt.get('G', 0)
B = cnt.get('B', 0)
ans = R * G * B
for i in range(N-1):
  for j in range(i+1, N):
    if s[i] != s[j] and 2*j-i < n and s[i] != s[2*j-i] and s[j] != s[2*j-i]:
      ans -= 1
print(ans)

Fixed submission:
from collections import Counter

N = int(input())
s = input()
cnt = Counter(s)
R = cnt.get('R', 0)
G = cnt.get('G', 0)
B = cnt.get('B', 0)
ans = R * G * B
for i in range(N-1):
  for j in range(i+1, N):
    if s[i] != s[j] and 2*j-i < N and s[i] != s[2*j-i] and s[j] != s[2*j-i]:
      ans -= 1
print(ans)

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

N = int(input())
s = input()
cnt = Counter(s)
R = cnt.get('R', 0)
G = cnt.get('G', 0)
B = cnt.get('B', 0)
ans = R * G * B
for i in range(N-1):
  for j in range(i+1, N):
    if s[i] != s[j] and 2*j-i < N and s[i] != s[2*j-i] and s[j] != s[2*j-i]:
      ans -= 1
print(ans)

Fixed submission:
from collections import Counter

N = int(input())
s = input()
cnt = Counter(s)
R = cnt.get('R', 0)
G = cnt.get('G', 0)
B = cnt.get('B', 0)
ans = R * G * B
for i in range(N-1):
  for j in range(i+1, N):
    if s[i] != s[j] and 2*j-i < N and s[i] != s[2*j-i] and s[j] != s[2*j-i]:
      ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    S = input()
    cnt = {'R': [], 'B': [], 'G': []}
    indices_set = {'R': set(cnt['R']), 'G': set(cnt['G']), 'B': set(cnt['B'])}
    for i, c in enumerate(S):
        cnt[c].append(i)
    from itertools import permutations
    import bisect
    ans = 0
    for (ci, cj, ck) in permutations(['R', 'B', 'G']):
        for i in cnt[ci]:
            for ind_j in range(bisect.bisect_left(cnt[cj], i), len(cnt[cj])):
                j = cnt[cj][ind_j]
                ans += len(cnt[ck]) - bisect.bisect_left(cnt[ck], j)
                if j + (j - i) in cnt[ck]:
                    ans -= 1
    print(ans)
resolve()

Fixed submission:
from collections import Counter

N = int(input())
s = input()
cnt = Counter(s)
R = cnt.get('R', 0)
G = cnt.get('G', 0)
B = cnt.get('B', 0)
ans = R * G * B
for i in range(N-1):
  for j in range(i+1, N):
    if s[i] != s[j] and 2*j-i < N and s[i] != s[2*j-i] and s[j] != s[2*j-i]:
      ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    S = input()
    cnt = {'R': [], 'B': [], 'G': []}
    for i, c in enumerate(S):
        cnt[c].append(i)
    from itertools import permutations
    ans = 0
    for (ci, cj, ck) in permutations(['R', 'B', 'G']):
        for i in cnt[ci]:
            for j in cnt[cj]:
                if j < i:
                    continue
                for k in cnt[ck]:
                    if k < j or ((j - i) == (k - j)):
                        continue
                    ans += 1
    print(ans)
resolve()

Fixed submission:
from collections import Counter

N = int(input())
s = input()
cnt = Counter(s)
R = cnt.get('R', 0)
G = cnt.get('G', 0)
B = cnt.get('B', 0)
ans = R * G * B
for i in range(N-1):
  for j in range(i+1, N):
    if s[i] != s[j] and 2*j-i < N and s[i] != s[2*j-i] and s[j] != s[2*j-i]:
      ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    S = input()
    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            if S[i] == S[j]:
                continue
            for k in range(j+1, N):
                if (j - i) == (k  - j):
                    continue
                if S[i] != S[k] and S[j] != S[k]:
                    ans += 1
    print(ans)
resolve()

Fixed submission:
from collections import Counter

N = int(input())
s = input()
cnt = Counter(s)
R = cnt.get('R', 0)
G = cnt.get('G', 0)
B = cnt.get('B', 0)
ans = R * G * B
for i in range(N-1):
  for j in range(i+1, N):
    if s[i] != s[j] and 2*j-i < N and s[i] != s[2*j-i] and s[j] != s[2*j-i]:
      ans -= 1
print(ans)