N = int(eval(input()))

S = eval(input())



r = 0

g = 0

b = 0

cnt_S = []

for i, s in enumerate(S):

    if s == 'R':

        r += 1

    elif s == 'G':

        g += 1

    else:

        b += 1

    cnt_S.append([r, g, b])



ans = 0

for i in range(N-2):

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

        if S[i] == 'R':

            if S[j] == 'G':

                ans += cnt_S[-1][2] - cnt_S[j][2]

                if 2 * j - i < N and S[j + j - i] == 'B':

                    ans -= 1

            if S[j] == 'B':

                ans += cnt_S[-1][1] - cnt_S[j][1]

                if 2 * j - i < N and S[j + j - i] == 'G':

                    ans -= 1

        elif S[i] == 'G':

            if S[j] == 'R':

                ans += cnt_S[-1][2] - cnt_S[j][2]

                if 2 * j - i < N and S[j + j - i] == 'B':

                    ans -= 1

            if S[j] == 'B':

                ans += cnt_S[-1][0] - cnt_S[j][0]

                if 2 * j - i < N and S[j + j - i] == 'R':

                    ans -= 1

        else:

            if S[j] == 'R':

                ans += cnt_S[-1][1] - cnt_S[j][1]

                if 2 * j - i < N and S[j + j - i] == 'G':

                    ans -= 1

            if S[j] == 'G':

                ans += cnt_S[-1][0] - cnt_S[j][0]

                if 2 * j - i < N and S[j + j - i] == 'R':

                    ans -= 1

print(ans)







N = int(eval(input()))

S = eval(input())



r = 0

g = 0

b = 0

for i, s in enumerate(S):

    if s == 'R':

        r += 1

    elif s == 'G':

        g += 1

    else:

        b += 1



ans = r * g * b

for i in range(N-2):

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

        if S[i] == 'R':

            if S[j] == 'G':

                if 2 * j - i < N and S[j + j - i] == 'B':

                    ans -= 1

            if S[j] == 'B':

                if 2 * j - i < N and S[j + j - i] == 'G':

                    ans -= 1

        elif S[i] == 'G':

            if S[j] == 'R':

                if 2 * j - i < N and S[j + j - i] == 'B':

                    ans -= 1

            if S[j] == 'B':

                if 2 * j - i < N and S[j + j - i] == 'R':

                    ans -= 1

        else:

            if S[j] == 'R':

                if 2 * j - i < N and S[j + j - i] == 'G':

                    ans -= 1

            if S[j] == 'G':

                if 2 * j - i < N and S[j + j - i] == 'R':

                    ans -= 1

print(ans)







N = int(eval(input()))
S = eval(input())
r = 0
g = 0
b = 0
cnt_S = []
for i, s in enumerate(S):
    if s == "R":
        r += 1
    elif s == "G":
        g += 1
    else:
        b += 1
    cnt_S.append([r, g, b])
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if S[i] == "R":
            if S[j] == "G":
                ans += cnt_S[-1][2] - cnt_S[j][2]
                if 2 * j - i < N and S[j + j - i] == "B":
                    ans -= 1
            if S[j] == "B":
                ans += cnt_S[-1][1] - cnt_S[j][1]
                if 2 * j - i < N and S[j + j - i] == "G":
                    ans -= 1
        elif S[i] == "G":
            if S[j] == "R":
                ans += cnt_S[-1][2] - cnt_S[j][2]
                if 2 * j - i < N and S[j + j - i] == "B":
                    ans -= 1
            if S[j] == "B":
                ans += cnt_S[-1][0] - cnt_S[j][0]
                if 2 * j - i < N and S[j + j - i] == "R":
                    ans -= 1
        else:
            if S[j] == "R":
                ans += cnt_S[-1][1] - cnt_S[j][1]
                if 2 * j - i < N and S[j + j - i] == "G":
                    ans -= 1
            if S[j] == "G":
                ans += cnt_S[-1][0] - cnt_S[j][0]
                if 2 * j - i < N and S[j + j - i] == "R":
                    ans -= 1
print(ans)

N = int(eval(input()))
S = eval(input())
r = 0
g = 0
b = 0
for i, s in enumerate(S):
    if s == "R":
        r += 1
    elif s == "G":
        g += 1
    else:
        b += 1
ans = r * g * b
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if S[i] == "R":
            if S[j] == "G":
                if 2 * j - i < N and S[j + j - i] == "B":
                    ans -= 1
            if S[j] == "B":
                if 2 * j - i < N and S[j + j - i] == "G":
                    ans -= 1
        elif S[i] == "G":
            if S[j] == "R":
                if 2 * j - i < N and S[j + j - i] == "B":
                    ans -= 1
            if S[j] == "B":
                if 2 * j - i < N and S[j + j - i] == "R":
                    ans -= 1
        else:
            if S[j] == "R":
                if 2 * j - i < N and S[j + j - i] == "G":
                    ans -= 1
            if S[j] == "G":
                if 2 * j - i < N and S[j + j - i] == "R":
                    ans -= 1
print(ans)

-cnt_S = [] -    cnt_S.append([r, g, b]) -ans = 0 +ans = r * g * b -                ans += cnt_S[-1][2] - cnt_S[j][2] -                ans += cnt_S[-1][1] - cnt_S[j][1] -                ans += cnt_S[-1][2] - cnt_S[j][2] -                ans += cnt_S[-1][0] - cnt_S[j][0] -                ans += cnt_S[-1][1] - cnt_S[j][1] -                ans += cnt_S[-1][0] - cnt_S[j][0]