

N = int(eval(input()))

S = eval(input())



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

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

for i in range(N):

    ctr[i + 1][d[S[i]]] += 1

    for j in range(3):

        ctr[i + 1][j] += ctr[i][j]





ans = 0

for i in range(N - 1):

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

        if S[i] != S[j]:

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

            cnt = ctr[-1][d[c]] - ctr[j + 1][d[c]]



            k = 2 * (j + 1) - (i + 1) - 1

            if j < k < N and c == S[k]:

                cnt -= 1



            ans += max(0, cnt)



print(ans)



from collections import Counter



N = int(eval(input()))

S = eval(input())



ctr = Counter(S)

res = 0

for i in range(N - 1):

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

        k = 2 * j - i

        if k < N and (S[i] != S[j] and S[i] != S[k] and S[j] != S[k]):

            res += 1



print((ctr["R"] * ctr["G"] * ctr["B"] - res))

N = int(eval(input()))
S = eval(input())
d = {"R": 0, "G": 1, "B": 2}
ctr = [[0] * 3 for _ in range(N + 1)]
for i in range(N):
    ctr[i + 1][d[S[i]]] += 1
    for j in range(3):
        ctr[i + 1][j] += ctr[i][j]
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if S[i] != S[j]:
            c = (set("RGB") - set([S[i], S[j]])).pop()
            cnt = ctr[-1][d[c]] - ctr[j + 1][d[c]]
            k = 2 * (j + 1) - (i + 1) - 1
            if j < k < N and c == S[k]:
                cnt -= 1
            ans += max(0, cnt)
print(ans)

from collections import Counter

N = int(eval(input()))
S = eval(input())
ctr = Counter(S)
res = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        k = 2 * j - i
        if k < N and (S[i] != S[j] and S[i] != S[k] and S[j] != S[k]):
            res += 1
print((ctr["R"] * ctr["G"] * ctr["B"] - res))

+from collections import Counter + -d = {"R": 0, "G": 1, "B": 2} -ctr = [[0] * 3 for _ in range(N + 1)] -for i in range(N): -    ctr[i + 1][d[S[i]]] += 1 -    for j in range(3): -        ctr[i + 1][j] += ctr[i][j] -ans = 0 +ctr = Counter(S) +res = 0 -        if S[i] != S[j]: -            c = (set("RGB") - set([S[i], S[j]])).pop() -            cnt = ctr[-1][d[c]] - ctr[j + 1][d[c]] -            k = 2 * (j + 1) - (i + 1) - 1 -            if j < k < N and c == S[k]: -                cnt -= 1 -            ans += max(0, cnt) -print(ans) +        k = 2 * j - i +        if k < N and (S[i] != S[j] and S[i] != S[k] and S[j] != S[k]): +            res += 1 +print((ctr["R"] * ctr["G"] * ctr["B"] - res))