#include <sysexits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(){
    int N;
    scanf("%d", &N);

    int x;
    x = getchar();

    char* S = (char*)malloc(sizeof(char)*4000);
    if (S == NULL){printf("malloc error\n"); exit(1);}
    if (fgets(S, 4000, stdin) == NULL){perror("gets"); exit(1);}

    int* R = (int*)malloc(sizeof(int)*4000);
    int* G = (int*)malloc(sizeof(int)*4000);
    int* B = (int*)malloc(sizeof(int)*4000);

    int sum = 0;
    int nr = 0;
    int ng = 0;
    int nb = 0;

    for (int i = 0; i < N; i++){
        if (strncmp((S+i), "R", 1) == 0){
            *(R + nr) = i;
            nr++;
        }
        else if (strncmp((S+i), "G", 1) == 0){
            *(G + ng) = i;
            ng++;
        }
        else{
            *(B + nb) = i;
            nb++;
        }
    }

    for (int r = 0; r < nr; r++){
        for (int g = 0; g < ng; g++){
            for (int b = 0; b < nb; b++){
                if (abs(*(R+r) - *(G+g)) != abs(*(G+g) - *(B+b)) && abs(*(R+r) - *(G+g)) != abs(*(B+b) - *(R+r)) && abs(*(G+g) - *(B+b)) != abs(*(B+b) - *(R+r))){
                    sum++;
                }
            }
        }
    }

    printf("%d\n",sum);

    return 0;
}