N = int(eval(input()))

S = list(eval(input()))

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

for i in range(N-2):

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

        k = j+(j-i)

        if len(set([S[i], S[j], S[k]])) == 3:

            ans-=1

print(ans)
def solve():

    N = int(eval(input()))

    S = list(eval(input()))

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

    for i in range(N-2):

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

            k = j+(j-i)

            if len(set([S[i], S[j], S[k]])) == 3:

                ans-=1

    return ans

print((solve()))
N = int(eval(input()))
S = list(eval(input()))
ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N - 2):
    for j in range(i + 1, N + (-(N - i - 1) // 2)):
        k = j + (j - i)
        if len(set([S[i], S[j], S[k]])) == 3:
            ans -= 1
print(ans)

def solve():
    N = int(eval(input()))
    S = list(eval(input()))
    ans = S.count("R") * S.count("G") * S.count("B")
    for i in range(N - 2):
        for j in range(i + 1, N + (-(N - i - 1) // 2)):
            k = j + (j - i)
            if len(set([S[i], S[j], S[k]])) == 3:
                ans -= 1
    return ans


print((solve()))

-N = int(eval(input())) -S = list(eval(input())) -ans = S.count("R") * S.count("G") * S.count("B") -for i in range(N - 2): -    for j in range(i + 1, N + (-(N - i - 1) // 2)): -        k = j + (j - i) -        if len(set([S[i], S[j], S[k]])) == 3: -            ans -= 1 -print(ans) +def solve(): +    N = int(eval(input())) +    S = list(eval(input())) +    ans = S.count("R") * S.count("G") * S.count("B") +    for i in range(N - 2): +        for j in range(i + 1, N + (-(N - i - 1) // 2)): +            k = j + (j - i) +            if len(set([S[i], S[j], S[k]])) == 3: +                ans -= 1 +    return ans + + +print((solve()))