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

# 大きく求めて引く
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N-2):
    for k in range(i+2, N):
        if (i+k) % 2 == 0 and set([S[i], S[(i+k)//2], S[k]]) == set(["R", "G", "B"]):
            ans -= 1

print(ans)


Fixed submission:
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N-2):
    for d in range(1, (N-i-1)//2+1):
        if {S[i], S[i+d], S[i+2*d]} == {"R", "G", "B"}:
            ans -= 1

print(ans)

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

ans = S.count("R") * S.count("G") * S.count("B")

res = 0
for i in range(N-2):
    for d in range(1, (N-i)//2+1):
        if i+2*d < N and set([S[i], S[i+d], S[i+2*d]]) == {"R", "G", "B"}:
            ans -= 1
print(ans)


Fixed submission:
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N-2):
    for d in range(1, (N-i-1)//2+1):
        if {S[i], S[i+d], S[i+2*d]} == {"R", "G", "B"}:
            ans -= 1

print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")

res = 0
for i in range(N-2):
    for d in range(1, (N-i)//2+1):
        if set(S[i], S[i+d], S[i+2*d]) == {"R", "G", "B"}:
            res += 1
ans -= res
print(ans)


Fixed submission:
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N-2):
    for d in range(1, (N-i-1)//2+1):
        if {S[i], S[i+d], S[i+2*d]} == {"R", "G", "B"}:
            ans -= 1

print(ans)

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

ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        if len(set([S[i], S[j]])) == 2:
            sk = list({"R", "G", "B"} - set([S[i], S[j]]))[0]
            if 2*j - i < N and S[2*j - i] == sk:
                ans += S[j+1:].count(sk) - 1
            else:
                ans += S[j+1:].count(sk)

print(ans)


Fixed submission:
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N-2):
    for d in range(1, (N-i-1)//2+1):
        if {S[i], S[i+d], S[i+2*d]} == {"R", "G", "B"}:
            ans -= 1

print(ans)

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

ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        set_ij = set([S[i], S[j]])
        if len(set_ij) == 2:
            sk = ({"R", "G", "B"} - set_ij).pop()
            if 2*j - i < N and S[2*j - i] == sk:
                ans += S[j+1:].count(sk) - 1
            else:
                ans += S[j+1:].count(sk)

print(ans)


Fixed submission:
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N-2):
    for d in range(1, (N-i-1)//2+1):
        if {S[i], S[i+d], S[i+2*d]} == {"R", "G", "B"}:
            ans -= 1

print(ans)

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

N = int(input())
S = input()

ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        if len(set([S[i], S[j]])) == 2:
            sk = ({"R", "G", "B"} - set([S[i], S[j]])).pop()
            if 2*j - i < N and S[2*j - i] == sk:
                ans += Counter(S[j+1:])[sk] - 1
            else:
                ans += Counter(S[j+1:])[sk]

print(ans)


Fixed submission:
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N-2):
    for d in range(1, (N-i-1)//2+1):
        if {S[i], S[i+d], S[i+2*d]} == {"R", "G", "B"}:
            ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
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
        else:
            sk = ({"R", "G", "B"} - set([S[i], S[j]])).pop()
            if 2*j - i < N and S[2*j - i] == sk:
                ans += S[j+1:].count(sk) - 1
            else:
                ans += S[j+1:].count(sk)

print(ans)


Fixed submission:
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N-2):
    for d in range(1, (N-i-1)//2+1):
        if {S[i], S[i+d], S[i+2*d]} == {"R", "G", "B"}:
            ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, bisect_right

def runLength(string):
    """文字列strをランレングス圧縮して返す関数
    ex: "0000111101" => [(0,4), (1,4), (0,1), (1,1)]
    """
    res = []
    data, count = string[0], 1
    for i in range(1, len(string)):
        if string[i] == data:
            count += 1
        else:
            res.append((data, count, i))
            data, count = string[i], 1
    res.append((data, count, i))
    return res


N = int(input())
S = input()

rl = runLength(S)
keys = [rli[2] for rli in rl]
nrl = len(rl)

ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        if S[i] == S[j]:
            continue
        elif set([S[i], S[j]]) == {"R", "G"}:
            if 2*j - i < N and S[2*j - i] == "B":
                ans += max(sum([rl[x][1] for x in range(bisect_left(keys, j+1), nrl) if rl[x][0] == "B"]) - 1, 0)
            else:
                ans += sum([rl[x][1] for x in range(bisect_left(keys, j+1), nrl) if rl[x][0] == "B"])
        elif set([S[i], S[j]]) == {"B", "G"}:
            if 2*j - i < N and S[2*j - i] == "R":
                ans += max(sum([rl[x][1] for x in range(bisect_left(keys, j+1), nrl) if rl[x][0] == "R"]) - 1, 0)
            else:
                ans += sum([rl[x][1] for x in range(bisect_left(keys, j+1), nrl) if rl[x][0] == "R"])
        else:
            if 2*j - i < N and S[2*j - i] == "G":
                ans += max(sum([rl[x][1] for x in range(bisect_left(keys, j+1), nrl) if rl[x][0] == "G"]) - 1, 0)
            else:
                ans += sum([rl[x][1] for x in range(bisect_left(keys, j+1), nrl) if rl[x][0] == "G"])

print(ans)


Fixed submission:
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N-2):
    for d in range(1, (N-i-1)//2+1):
        if {S[i], S[i+d], S[i+2*d]} == {"R", "G", "B"}:
            ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
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
        elif set([S[i], S[j]]) == {"R", "G"}:
            if 2*j - i < N and S[2*j - i] == "B":
                ans += S[j+1:].count("B") - 1
            else:
                ans += S[j+1:].count("B")
        elif set([S[i], S[j]]) == {"B", "G"}:
            if 2*j - i < N and S[2*j - i] == "R":
                ans += S[j+1:].count("R") - 1
            else:
                ans += S[j+1:].count("R")
        else:
            if 2*j - i < N and S[2*j - i] == "G":
                ans += S[j+1:].count("G") - 1
            else:
                ans += S[j+1:].count("G")

print(ans)


Fixed submission:
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N-2):
    for d in range(1, (N-i-1)//2+1):
        if {S[i], S[i+d], S[i+2*d]} == {"R", "G", "B"}:
            ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
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
        elif set([S[i], S[j]]) == {"R", "G"}:
            ans += S[j+1:].count("B")
            if 2*j - i < N and S[2*j - i] == "B":
                ans -= 1
        elif set([S[i], S[j]]) == {"B", "G"}:
            ans += S[j+1:].count("R")
            if 2*j - i < N and S[2*j - i] == "R":
                ans -= 1
        elif set([S[i], S[j]]) == {"R", "B"}:
            ans += S[j+1:].count("G")
            if 2*j - i < N and S[2*j - i] == "G":
                ans -= 1

print(ans)


Fixed submission:
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N-2):
    for d in range(1, (N-i-1)//2+1):
        if {S[i], S[i+d], S[i+2*d]} == {"R", "G", "B"}:
            ans -= 1

print(ans)

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


ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        if S[j] == S[i]:
            continue
        for k in range(j+1, N):
            if S[k] not in [S[i], S[j]] and j-i != k-j:
                ans += 1

print(ans)

Fixed submission:
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N-2):
    for d in range(1, (N-i-1)//2+1):
        if {S[i], S[i+d], S[i+2*d]} == {"R", "G", "B"}:
            ans -= 1

print(ans)

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

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if set([S[i], S[j], S[k]]) == {"R", "G", "B"} and j-i != k-j:
                ans += 1

print(ans)


Fixed submission:
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N-2):
    for d in range(1, (N-i-1)//2+1):
        if {S[i], S[i+d], S[i+2*d]} == {"R", "G", "B"}:
            ans -= 1

print(ans)