n = int(eval(input()))

s = eval(input())



R = [0]

G = [0]

B = [0]



for i in range(n):

    R.append(R[-1])

    G.append(G[-1])

    B.append(B[-1])

    if s[i]=='R':

        R[-1]+=1

    elif s[i]=='G':

        G[-1]+=1

    else:

        B[-1]+=1



ans = 0



for j in range(1,n-1):

    if s[j]=='R':

        ans += G[j]*(B[n]-B[j+1])

        ans += B[j]*(G[n]-G[j+1])

        for i in range(j):

            if j+i+1<n:

                if s[j-i-1]=='B' and s[j+i+1]=='G':

                    ans-=1

                elif s[j-i-1]=='G' and s[j+i+1]=='B':

                    ans-=1

            else:

                break

    elif s[j]=='G':

        ans += R[j]*(B[n]-B[j+1])

        ans += B[j]*(R[n]-R[j+1])

        for i in range(j):

            if j+i+1<n:

                if s[j-i-1]=='R' and s[j+i+1]=='B':

                    ans-=1

                elif s[j-i-1]=='B' and s[j+i+1]=='R':

                    ans-=1

            else:

                break

    elif s[j]=='B':

        ans += G[j]*(R[n]-R[j+1])

        ans += R[j]*(G[n]-G[j+1])

        for i in range(j):

            if j+i+1<n:

                if s[j-i-1]=='R' and s[j+i+1]=='G':

                    ans-=1

                elif s[j-i-1]=='G' and s[j+i+1]=='R':

                    ans-=1

            else:

                break

print(ans)











n = int(eval(input()))

s = eval(input())



R = s.count('R')

G = s.count('G')

B = s.count('B')



ans = R*G*B



for i in range(n-2):

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

        k = j*2-i

        if k<n:

            if s[i]!=s[j]!=s[k]!=s[i]:

                ans -=1

print(ans)
n = int(eval(input()))
s = eval(input())
R = [0]
G = [0]
B = [0]
for i in range(n):
    R.append(R[-1])
    G.append(G[-1])
    B.append(B[-1])
    if s[i] == "R":
        R[-1] += 1
    elif s[i] == "G":
        G[-1] += 1
    else:
        B[-1] += 1
ans = 0
for j in range(1, n - 1):
    if s[j] == "R":
        ans += G[j] * (B[n] - B[j + 1])
        ans += B[j] * (G[n] - G[j + 1])
        for i in range(j):
            if j + i + 1 < n:
                if s[j - i - 1] == "B" and s[j + i + 1] == "G":
                    ans -= 1
                elif s[j - i - 1] == "G" and s[j + i + 1] == "B":
                    ans -= 1
            else:
                break
    elif s[j] == "G":
        ans += R[j] * (B[n] - B[j + 1])
        ans += B[j] * (R[n] - R[j + 1])
        for i in range(j):
            if j + i + 1 < n:
                if s[j - i - 1] == "R" and s[j + i + 1] == "B":
                    ans -= 1
                elif s[j - i - 1] == "B" and s[j + i + 1] == "R":
                    ans -= 1
            else:
                break
    elif s[j] == "B":
        ans += G[j] * (R[n] - R[j + 1])
        ans += R[j] * (G[n] - G[j + 1])
        for i in range(j):
            if j + i + 1 < n:
                if s[j - i - 1] == "R" and s[j + i + 1] == "G":
                    ans -= 1
                elif s[j - i - 1] == "G" and s[j + i + 1] == "R":
                    ans -= 1
            else:
                break
print(ans)

n = int(eval(input()))
s = eval(input())
R = s.count("R")
G = s.count("G")
B = s.count("B")
ans = R * G * B
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        k = j * 2 - i
        if k < n:
            if s[i] != s[j] != s[k] != s[i]:
                ans -= 1
print(ans)

-R = [0] -G = [0] -B = [0] -for i in range(n): -    R.append(R[-1]) -    G.append(G[-1]) -    B.append(B[-1]) -    if s[i] == "R": -        R[-1] += 1 -    elif s[i] == "G": -        G[-1] += 1 -    else: -        B[-1] += 1 -ans = 0 -for j in range(1, n - 1): -    if s[j] == "R": -        ans += G[j] * (B[n] - B[j + 1]) -        ans += B[j] * (G[n] - G[j + 1]) -        for i in range(j): -            if j + i + 1 < n: -                if s[j - i - 1] == "B" and s[j + i + 1] == "G": -                    ans -= 1 -                elif s[j - i - 1] == "G" and s[j + i + 1] == "B": -                    ans -= 1 -            else: -                break -    elif s[j] == "G": -        ans += R[j] * (B[n] - B[j + 1]) -        ans += B[j] * (R[n] - R[j + 1]) -        for i in range(j): -            if j + i + 1 < n: -                if s[j - i - 1] == "R" and s[j + i + 1] == "B": -                    ans -= 1 -                elif s[j - i - 1] == "B" and s[j + i + 1] == "R": -                    ans -= 1 -            else: -                break -    elif s[j] == "B": -        ans += G[j] * (R[n] - R[j + 1]) -        ans += R[j] * (G[n] - G[j + 1]) -        for i in range(j): -            if j + i + 1 < n: -                if s[j - i - 1] == "R" and s[j + i + 1] == "G": -                    ans -= 1 -                elif s[j - i - 1] == "G" and s[j + i + 1] == "R": -                    ans -= 1 -            else: -                break +R = s.count("R") +G = s.count("G") +B = s.count("B") +ans = R * G * B +for i in range(n - 2): +    for j in range(i + 1, n - 1): +        k = j * 2 - i +        if k < n: +            if s[i] != s[j] != s[k] != s[i]: +                ans -= 1