from bisect import bisect_right



N = int(eval(input()))

S = eval(input())



d = [[0] * N for _ in range(3)]

for i in range(3):

    for j in range(N):

        d[i][j] = int(S[j] == "RGB"[i])

        

cumsum = [[0] * (N + 1) for _ in range(3)]

for i in range(3):

    for j in range(N):

        cumsum[i][j + 1] = cumsum[i][j] + d[i][j]



cnt = [len(v) for v in d]

ans = 0

for i in range(1, N - 1):

    for j in range(i + 1, N):

        

        if S[i - 1] == S[j - 1]:

            continue



        # Find `k` string and index

        s = (set("RGB") - set([S[i - 1], S[j - 1]])).pop()

        idx = "RGB".find(s)

        ans += cumsum[idx][-1] - cumsum[idx][j]

        

        k = 2 * j - i

        if k <= N and d[idx][k - 1]:

            ans -= 1

        

print(ans)

N = int(eval(input()))

S = eval(input())



d = {"R": 0, "G": 0, "B": 0}

for i in range(N):

    d[S[i]] += 1

    

ans = d["R"] * d["G"] * d["B"]



cnt = 0

for i in range(1, N - 1):

    for j in range(i + 1, N):

        k = 2 * j - i

        if k > N or S[i - 1] == S[j - 1]:

            continue

            

        if S[i - 1] != S[k - 1] and S[j - 1] != S[k - 1]:

            cnt += 1

            

print((ans - cnt))



from bisect import bisect_right

N = int(eval(input()))
S = eval(input())
d = [[0] * N for _ in range(3)]
for i in range(3):
    for j in range(N):
        d[i][j] = int(S[j] == "RGB"[i])
cumsum = [[0] * (N + 1) for _ in range(3)]
for i in range(3):
    for j in range(N):
        cumsum[i][j + 1] = cumsum[i][j] + d[i][j]
cnt = [len(v) for v in d]
ans = 0
for i in range(1, N - 1):
    for j in range(i + 1, N):
        if S[i - 1] == S[j - 1]:
            continue
        # Find `k` string and index
        s = (set("RGB") - set([S[i - 1], S[j - 1]])).pop()
        idx = "RGB".find(s)
        ans += cumsum[idx][-1] - cumsum[idx][j]
        k = 2 * j - i
        if k <= N and d[idx][k - 1]:
            ans -= 1
print(ans)

N = int(eval(input()))
S = eval(input())
d = {"R": 0, "G": 0, "B": 0}
for i in range(N):
    d[S[i]] += 1
ans = d["R"] * d["G"] * d["B"]
cnt = 0
for i in range(1, N - 1):
    for j in range(i + 1, N):
        k = 2 * j - i
        if k > N or S[i - 1] == S[j - 1]:
            continue
        if S[i - 1] != S[k - 1] and S[j - 1] != S[k - 1]:
            cnt += 1
print((ans - cnt))

-from bisect import bisect_right - -d = [[0] * N for _ in range(3)] -for i in range(3): -    for j in range(N): -        d[i][j] = int(S[j] == "RGB"[i]) -cumsum = [[0] * (N + 1) for _ in range(3)] -for i in range(3): -    for j in range(N): -        cumsum[i][j + 1] = cumsum[i][j] + d[i][j] -cnt = [len(v) for v in d] -ans = 0 +d = {"R": 0, "G": 0, "B": 0} +for i in range(N): +    d[S[i]] += 1 +ans = d["R"] * d["G"] * d["B"] +cnt = 0 -        if S[i - 1] == S[j - 1]: +        k = 2 * j - i +        if k > N or S[i - 1] == S[j - 1]: -        # Find `k` string and index -        s = (set("RGB") - set([S[i - 1], S[j - 1]])).pop() -        idx = "RGB".find(s) -        ans += cumsum[idx][-1] - cumsum[idx][j] -        k = 2 * j - i -        if k <= N and d[idx][k - 1]: -            ans -= 1 -print(ans) +        if S[i - 1] != S[k - 1] and S[j - 1] != S[k - 1]: +            cnt += 1 +print((ans - cnt))