### BUGGY CODE ###

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'))))))
    for i,r in enumerate(R):
       if r:
           for j,g in enumerate(G[i+1:]):
               if g:
                   for k,b in enumerate(B[i+j+2:]):
                       if b and j != k:
                           cnt += 1
           for j,g in enumerate(B[i+1:]):
               if g:
                   for k,b in enumerate(G[i+j+2:]):
                       if b and j !=k:
                           cnt += 1
    for i,r in enumerate(G):
       if r:
           for j,g in enumerate(R[i+1:]):
               if g:
                   for k,b in enumerate(B[i+j+2:]):
                       if b and j !=k:
                           cnt += 1
           for j,b in enumerate(B[i+1:]):
               if b:
                   for k,g in enumerate(R[i+j+2:]):
                       if g and j !=k:
                           cnt += 1
    for i,r in enumerate(B):
       if r:
           for j,g in enumerate(R[i+1:]):
               if g:
                   for k,b in enumerate(G[i+j+2:]):
                       if b and j !=k:
                           cnt += 1
           for j,b in enumerate(G[i+1:]):
               if b:
                   for k,g in enumerate(R[i+j+2:]):
                       if g and j !=k:
                           cnt += 1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    out_ctrl(cnt)

### FIXED CODE ###

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)