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

Rindex = set(i for i in range(N) if S[i] == 'R')
Gindex = set(i for i in range(N) if S[i] == 'G')
Bindex = set(i for i in range(N) if S[i] == 'B')

ans = 0

for i in Rindex:
    for j in Gindex:
        for k in Bindex:
            if abs(i - j) == abs(j - k) or abs(j - k) == abs(k - i) or abs(k - i) == abs(i - j):continue
            ans += 1

print(ans)

Fixed submission:
from collections import Counter

N = int(input())
S = input()
cnt = Counter(S)

ans = cnt['R']*cnt['G']*cnt['B']
#まずansに要請１を満たす(i, j, k)の組の数を入れておき，ここから，要請２を満たさないものを除いていく。

for i in range(N-2):
    for j in range(i+1, N-1):
        k = j + (j - i)
        #kは　j - i = k - j を満たす。ただし，（i, j, k）が要請１を満たしているとは限らない。
        if k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1

print(ans)

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

Rindex = set(i for i in range(N) if S[i] == 'R')
Gindex = set(i for i in range(N) if S[i] == 'G')
Bindex = set(i for i in range(N) if S[i] == 'B')

def findijk(l1, l2, l3):
    ret = 0
    for i in l1:
        for j in l2:
            if i > j:continue
            for k in l3:
                if j > k or j - i == k - j:continue
                ret += 1
    return ret

ans = 0

ans += findijk(Rindex, Gindex, Bindex)
ans += findijk(Bindex, Rindex, Gindex)
ans += findijk(Gindex, Bindex, Rindex)
ans += findijk(Rindex, Bindex, Gindex)
ans += findijk(Gindex, Rindex, Bindex)
ans += findijk(Bindex, Gindex, Rindex)

print(ans)

Fixed submission:
from collections import Counter

N = int(input())
S = input()
cnt = Counter(S)

ans = cnt['R']*cnt['G']*cnt['B']
#まずansに要請１を満たす(i, j, k)の組の数を入れておき，ここから，要請２を満たさないものを除いていく。

for i in range(N-2):
    for j in range(i+1, N-1):
        k = j + (j - i)
        #kは　j - i = k - j を満たす。ただし，（i, j, k）が要請１を満たしているとは限らない。
        if k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1

print(ans)

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

Rindex = set(i for i in range(N) if S[i] == 'R')
Gindex = set(i for i in range(N) if S[i] == 'G')
Bindex = set(i for i in range(N) if S[i] == 'B')

def findijk(l1, l2, l3):
    ret = 0
    for i in l1:
        for j in l2:
            if i > j:continue
            for k in l3:
                if j > k or j - i == k - j:continue
                ret += 1
    return ret

ans = 0

ans += findijk(Rindex, Gindex, Bindex)
ans += findijk(Bindex, Rindex, Gindex)
ans += findijk(Gindex, Bindex, Rindex)
ans += findijk(Rindex, Bindex, Gindex)
ans += findijk(Gindex, Rindex, Bindex)
ans += findijk(Bindex, Gindex, Rindex)

print(ans)

Fixed submission:
from collections import Counter

N = int(input())
S = input()
cnt = Counter(S)

ans = cnt['R']*cnt['G']*cnt['B']
#まずansに要請１を満たす(i, j, k)の組の数を入れておき，ここから，要請２を満たさないものを除いていく。

for i in range(N-2):
    for j in range(i+1, N-1):
        k = j + (j - i)
        #kは　j - i = k - j を満たす。ただし，（i, j, k）が要請１を満たしているとは限らない。
        if k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1

print(ans)

Buggy python submission (verdict: Runtime Error):
l = [input() for _ in range(2)]
S = l[1]
N = int(l[0])
count = 0

indexR = []
indexG = []
indexB = []

i = 0
j = 0
k = 0

for a in range(N):
    character = S[a:a+1]

    if character == 'R':
        indexR.append(a+1)
    elif character == 'G':
        indexG.append(a+1)
    elif character == 'B':
        indexB.append(a+1)

for r in indexR:
    for g in indexG:
        for b in indexB:
            mean = (max[r, g, b] + min[r, g, b])/2
            if mean != r and mean != g and mean != b:
                count = count + 1
print(count)

Fixed submission:
from collections import Counter

N = int(input())
S = input()
cnt = Counter(S)

ans = cnt['R']*cnt['G']*cnt['B']
#まずansに要請１を満たす(i, j, k)の組の数を入れておき，ここから，要請２を満たさないものを除いていく。

for i in range(N-2):
    for j in range(i+1, N-1):
        k = j + (j - i)
        #kは　j - i = k - j を満たす。ただし，（i, j, k）が要請１を満たしているとは限らない。
        if k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1

print(ans)

Buggy python submission (verdict: Runtime Error):
l = [input() for _ in range(2)]
S = l[1]
N = int(l[0])
count = 0

indexR = []
indexG = []
indexB = []

i = 0
j = 0
k = 0

for a in range(N):
    character = S[a:a+1]

    if character == 'R':
        indexR.append(a+1)
    elif character == 'G':
        indexG.append(a+1)
    elif character == 'B':
        indexB.append(a+1)

for r in indexR:
    for g in indexG:
        for b in indexB:
            mean = (max[r, g, b] + min[r, g, b]/2)
            if mean != r and mean != g and mean != b:
                count = count + 1
print(count)

Fixed submission:
from collections import Counter

N = int(input())
S = input()
cnt = Counter(S)

ans = cnt['R']*cnt['G']*cnt['B']
#まずansに要請１を満たす(i, j, k)の組の数を入れておき，ここから，要請２を満たさないものを除いていく。

for i in range(N-2):
    for j in range(i+1, N-1):
        k = j + (j - i)
        #kは　j - i = k - j を満たす。ただし，（i, j, k）が要請１を満たしているとは限らない。
        if k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
l = [input() for _ in range(2)]
n = l[0]
S = l[1]
N = int(n)
count = 0

indexR = []
indexG = []
indexB = []

i = 0
j = 0
k = 0

for a in range(N):
    character = str(S)[a:a+1]

    if character == 'R':
        indexR.append(a+1)
    elif character == 'G':
        indexG.append(a+1)
    elif character == 'B':
        indexB.append(a+1)

for r in indexR:
    for g in indexG:
        for b in indexB:
            if abs(r-g) != abs(g-b) and abs(g-r) != abs(r-b) and abs(g-b) != abs(r-b):
                count = count + 1

print(count)

Fixed submission:
from collections import Counter

N = int(input())
S = input()
cnt = Counter(S)

ans = cnt['R']*cnt['G']*cnt['B']
#まずansに要請１を満たす(i, j, k)の組の数を入れておき，ここから，要請２を満たさないものを除いていく。

for i in range(N-2):
    for j in range(i+1, N-1):
        k = j + (j - i)
        #kは　j - i = k - j を満たす。ただし，（i, j, k）が要請１を満たしているとは限らない。
        if k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1

print(ans)