# Original solution
import sys
import fractions

def in_ctrl():
    _input = [_.rstrip() for _ in sys.stdin.readlines()]
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    N = int(_input[0])
    S = _input[1]
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    return N,S


def out_ctrl(s):
    print(s)


if __name__ == "__main__":
    N,S = in_ctrl()
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 0
    R = list(map(bool,list(map(int,list(S.replace('R','1').replace('G','0').replace('B','0'))))))
    G = list(map(bool,list(map(int,list(S.replace('R','0').replace('G','1').replace('B','0'))))))
    B = list(map(bool,list(map(int,list(S.replace('R','0').replace('G','0').replace('B','1'))))))
    R_cum, G_cum, B_cum = {}, {}, {}
    for i,r in enumerate(R):
        if r:
            for j,g in enumerate(G[i+1:]):
                if g:
                    if i+j+2 not in B_cum:
                        B_cum[i+j+2] = sum(B[i+j+2:])
                    if i+2*j+2 < N:
                        cnt += B_cum[i+j+2] - B[i+2*j+2]
                    else:
                        cnt += B_cum[i+j+2]
            for j,g in enumerate(B[i+1:]):
                if g:
                    if i+j+2 not in G_cum:
                        G_cum[i+j+2] = sum(G[i+j+2:])
                    if i+2*j+2 < N:
                        cnt += G_cum[i+j+2] - G[i+2*j+2]
                    else:
                        cnt += G_cum[i+j+2]
    for i,r in enumerate(G):
        if r:
            for j,g in enumerate(R[i+1:]):
                if g:
                    if i+j+2 not in B_cum:
                        B_cum[i+j+2] = sum(B[i+j+2:])
                    if i+2*j+2 < N:
                        cnt += B_cum[i+j+2] - B[i+2*j+2]
                    else:
                        cnt += B_cum[i+j+2]
            for j,b in enumerate(B[i+1:]):
                if b:
                    if i+j+2 not in R_cum:
                        R_cum[i+j+2] = sum(R[i+j+2:])
                    if i+2*j+2 < N:
                        cnt += R_cum[i+j+2] - R[i+2*j+2]
                    else:
                        cnt += R_cum[i+j+2]
    for i,r in enumerate(B):
        if r:
            for j,g in enumerate(R[i+1:]):
                if g:
                    if i+j+2 not in G_cum:
                        G_cum[i+j+2] = sum(G[i+j+2:])
                    if i+2*j+2 < N:
                        cnt += G_cum[i+j+2] - G[i+2*j+2]
                    else:
                        cnt += G_cum[i+j+2]
            for j,b in enumerate(G[i+1:]):
                if b:
                    if i+j+2 not in R_cum:
                        R_cum[i+j+2] = sum(R[i+j+2:])
                    if i+2*j+2 < N:
                        cnt += R_cum[i+j+2] - R[i+2*j+2]
                    else:
                        cnt += R_cum[i+j+2]
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    out_ctrl(cnt)

# Optimized solution
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    S =     _in[1]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = S.count('R')*S.count('G')*S.count('B')
    for i in range(N):
        for j in range(i+1,N):
            k = 2*j-i
            if k<N:
                if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                    cnt -= 1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)