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

res = s.count('R') * s.count('G') * s.count('B')

for i in range(n):
    for j in range(i+1, n-1):
        k = j + (j - i)
        if k < n:
            if len(set([s[i], s[j], s[k]])) == 3:
                res -= 1
        else:
            break

print(res)

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

res = s.count('R') * s.count('G') * s.count('B')

for i in range(n):
    for j in range(i+1, n-1):
        k = j + (j - i)
        if k < n:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                res -= 1
        else:
            break

print(res)

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

res = s.count('R') * s.count('G') * s.count('B')

for ni,i in enumerate(s[:-2]):
    lst3 = ['R','G','B']
    lst3.remove(i)
    for nj in range(ni+1,n):
        nk = nj + (nj - ni)
        if nk < n:
            if set(lst3) == set([s[nj],s[nk]]):
                res -= 1
        else:
            break

print(res)

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

res = s.count('R') * s.count('G') * s.count('B')

for i in range(n):
    for j in range(i+1, n-1):
        k = j + (j - i)
        if k < n:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                res -= 1
        else:
            break

print(res)

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

from collections import Counter

ct = Counter(s)
res = ct['R'] * ct['G'] * ct['B']

for ni,i in enumerate(s[:-2]):
    lst3 = ['R','G','B']
    lst3.remove(i)
    for nj in range(ni+1,n):
        nk = nj + (nj - ni)
        if nk < n:
            if set(lst3) == set([s[nj],s[nk]]):
                res -= 1
        else:
            break

print(res)

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

res = s.count('R') * s.count('G') * s.count('B')

for i in range(n):
    for j in range(i+1, n-1):
        k = j + (j - i)
        if k < n:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                res -= 1
        else:
            break

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
dic = {'R':0,'G':1,'B':2}

lst = []
t_last = (0,0,0)
for i in s[::-1]:
    if i=='R':
        t = (t_last[0]+1, t_last[1], t_last[2])
        lst.append(t)
        t_last = t
    elif i=='G':
        t = (t_last[0], t_last[1]+1, t_last[2])
        lst.append(t)
        t_last = t
    elif i=='B':
        t = (t_last[0], t_last[1], t_last[2]+1)
        lst.append(t)
        t_last = t
lst.reverse()

res = 0
for ni,i in enumerate(s[:-2]):
    lst3 = ['R','G','B']
    lst3.remove(i)
    res += lst[ni][dic[lst3[0]]] * lst[ni][dic[lst3[1]]]
    for nj in range(ni+1,n):
        nk = nj + (nj - ni)
        if nk < n:
            if set(lst3) == set([s[nj],s[nk]]):
                res -= 1
        else:
            break
print(res)

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

res = s.count('R') * s.count('G') * s.count('B')

for i in range(n):
    for j in range(i+1, n-1):
        k = j + (j - i)
        if k < n:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                res -= 1
        else:
            break

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
dic = {'R':0,'G':1,'B':2}

lst = []
t_last = (0,0,0)
for i in s[::-1]:
    if i=='R':
        t = (t_last[0]+1, t_last[1], t_last[2])
        lst.append(t)
        t_last = t
    elif i=='G':
        t = (t_last[0], t_last[1]+1, t_last[2])
        lst.append(t)
        t_last = t
    elif i=='B':
        t = (t_last[0], t_last[1], t_last[2]+1)
        lst.append(t)
        t_last = t
lst.reverse()

res = 0
for ni,i in enumerate(s[:-2]):
    lst3 = ['R','G','B']
    lst3.remove(i)
    for nnj,j in enumerate(s[ni+1:-1]):
        if i!=j:
            nj = nnj + ni + 1
            target = [x for x in lst3 if x != j][0]
            res += lst[nj][dic[target]]
            index = nj + (nj-ni)
            if index <= n-1 and s[index] == target:
                res -= 1
print(res)

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

res = s.count('R') * s.count('G') * s.count('B')

for i in range(n):
    for j in range(i+1, n-1):
        k = j + (j - i)
        if k < n:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                res -= 1
        else:
            break

print(res)