Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

cnt = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        nn = n-j
        if s[i] == s[j]:
            continue
        w = j - i
        if j+w < n and (s[j+w] != s[j] and s[j+w] != s[i]):
            cnt -= 1
        not_same = nn - (s[j:].count(s[i]) + s[j:].count(s[j]))
        cnt += not_same

print(cnt)


Fixed submission:
from collections import Counter

n = int(input())
s = input()
c = Counter(s)
cnt = c['R'] * c['G'] * c['B']

for i in range(n-2):
    for j in range(i+1, n-1):
        w = j - i
        if j+w >= n:
            continue
        if s[i] != s[j] and s[j+w] != s[j] and s[j+w] != s[i]:
            cnt -= 1

print(cnt)

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

n = int(input())
s = input()
c = Counter(s)
cnt = c['R'] * c['G'] * c['B']

for i in range(n-2):
    for j in range(i+1, n-1):
        if s[i] == s[j]:
            continue
        w = j - i
        if j+w >= n:
            continue
        if s[i] == s[j+w] or s[j+w] == s[j]:
            continue
        if s[i] != s[j+w] != s[j]:
            cnt -= 1

print(cnt)


Fixed submission:
from collections import Counter

n = int(input())
s = input()
c = Counter(s)
cnt = c['R'] * c['G'] * c['B']

for i in range(n-2):
    for j in range(i+1, n-1):
        w = j - i
        if j+w >= n:
            continue
        if s[i] != s[j] and s[j+w] != s[j] and s[j+w] != s[i]:
            cnt -= 1

print(cnt)

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

n = int(input())
s = input()
c = Counter(s)
cnt = c['R'] * c['G'] * c['B']

for i in range(n-2):
    for j in range(i+1, n-1):
        if s[i] == s[j]:
            continue
        w = j - i
        if j+w < n and (s[j+w] != s[j] and s[j+w] != s[i]):
            cnt -= 1

print(cnt)


Fixed submission:
from collections import Counter

n = int(input())
s = input()
c = Counter(s)
cnt = c['R'] * c['G'] * c['B']

for i in range(n-2):
    for j in range(i+1, n-1):
        w = j - i
        if j+w >= n:
            continue
        if s[i] != s[j] and s[j+w] != s[j] and s[j+w] != s[i]:
            cnt -= 1

print(cnt)

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

n = int(input())
s = input()

cnt = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        if s[i] == s[j]:
            continue
        c = Counter(s[j:])
        total = sum(c.values()) - 1
        cnt += total - c[s[i]] - c[s[j]]
        w = j - i
        if j+w < n and (s[j+w] != s[j] and s[j+w] != s[i]):
            cnt -= 1

print(cnt)


Fixed submission:
from collections import Counter

n = int(input())
s = input()
c = Counter(s)
cnt = c['R'] * c['G'] * c['B']

for i in range(n-2):
    for j in range(i+1, n-1):
        w = j - i
        if j+w >= n:
            continue
        if s[i] != s[j] and s[j+w] != s[j] and s[j+w] != s[i]:
            cnt -= 1

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

cnt = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        nn = n-j
        if s[i] == s[j]:
            continue
        w = j - i
        if j+w < n and (s[j+w] != s[j] and s[j+w] != s[i]):
            cnt -= 1
        not_same = nn - (s[j:].count(s[i]) + s[j:].count(s[j]))
        cnt += not_same

print(cnt)


Fixed submission:
from collections import Counter

n = int(input())
s = input()
c = Counter(s)
cnt = c['R'] * c['G'] * c['B']

for i in range(n-2):
    for j in range(i+1, n-1):
        w = j - i
        if j+w >= n:
            continue
        if s[i] != s[j] and s[j+w] != s[j] and s[j+w] != s[i]:
            cnt -= 1

print(cnt)