Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import sys
import math

sys.setrecursionlimit(10 ** 6)

input_line = input()
inputs = input_line.split(' ')
N, = [int(s) for s in inputs]

input_line = input()
s = list(input_line)
sl = len(s)

cand = []
for i in range(sl):
    for j in range(i+2,sl):
        if s[i]!=s[j]:
            cand.append((i,j))

ans = 0
for c in cand:
    st = c[0]
    en = c[1]
    for i in range(st+1,en):
        if i-st!=en-i and s[st]!=s[i] and s[i]!=s[en]:
            ans += 1

print(ans)



Fixed submission:
# -*- coding: utf-8 -*-

import sys
import math

sys.setrecursionlimit(10 ** 6)

input_line = input()
inputs = input_line.split(' ')
N, = [int(s) for s in inputs]

input_line = input()
s = list(input_line)
sl = len(s)

r = 0
g = 0
b = 0
for ss in s:
    if ss=='R':
        r += 1
    elif ss=='G':
        g += 1
    else:
        b += 1
ans = r*g*b

num = 0

for i in range(sl):
    for j in range(i+1, sl):
        k = j + (j - i)
        if k<sl:
            if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
                num += 1

ans -= num

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import sys
import math

sys.setrecursionlimit(10 ** 6)

input_line = input()
inputs = input_line.split(' ')
N, = [int(s) for s in inputs]

input_line = input()
s = list(input_line)
sl = len(s)

cand = []
for i in range(sl):
    for j in range(i+2,sl):
        if s[i]!=s[j]:
            cand.append((i,j))

ans = 0
for c in cand:
    st = c[0]
    en = c[1]
    for i in range(st+1,en):
        if i-st!=en-i and s[st]!=s[i] and s[i]!=s[en]:
            ans += 1

print(ans)



Fixed submission:
# -*- coding: utf-8 -*-

import sys
import math

sys.setrecursionlimit(10 ** 6)

input_line = input()
inputs = input_line.split(' ')
N, = [int(s) for s in inputs]

input_line = input()
s = list(input_line)
sl = len(s)

r = 0
g = 0
b = 0
for ss in s:
    if ss=='R':
        r += 1
    elif ss=='G':
        g += 1
    else:
        b += 1
ans = r*g*b

num = 0

for i in range(sl):
    for j in range(i+1, sl):
        k = j + (j - i)
        if k<sl:
            if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
                num += 1

ans -= num

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import sys
import math

sys.setrecursionlimit(10 ** 6)

input_line = input()
inputs = input_line.split(' ')
N, = [int(s) for s in inputs]

input_line = input()
s = list(input_line)
sl = len(s)

two = {}
for i in range(sl):
    for j in range(i+1,sl):
        if s[i]!=s[j]:
            if s[i]+s[j] in two:
                two[s[i]+s[j]].append((i,j))
            else:
                two[s[i]+s[j]] = [(i, j)]


ans = 0
for k1, v1 in two.items():
    for k2, v2 in two.items():
        if k1[1]==k2[0] and k1[0]!=k2[1]:
            for t1 in v1:
                for t2 in v2:
                    if t1[1]==t2[0] and t1[1]-t1[0]!=t2[1]-t2[0]:
                        ans += 1
print(ans)



Fixed submission:
# -*- coding: utf-8 -*-

import sys
import math

sys.setrecursionlimit(10 ** 6)

input_line = input()
inputs = input_line.split(' ')
N, = [int(s) for s in inputs]

input_line = input()
s = list(input_line)
sl = len(s)

r = 0
g = 0
b = 0
for ss in s:
    if ss=='R':
        r += 1
    elif ss=='G':
        g += 1
    else:
        b += 1
ans = r*g*b

num = 0

for i in range(sl):
    for j in range(i+1, sl):
        k = j + (j - i)
        if k<sl:
            if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
                num += 1

ans -= num

print(ans)