#include <stdio.h>
#include <stdlib.h>
void sort_num(int*);
void change_num(int*, int, int);

int main(){
    int N;
    scanf("%d", &N);
    char RGB[N+1];
    scanf("%s", RGB);
    int red=0, green=0, blue=0;
    for(int i =0; i < N; i++){
        switch(RGB[i]){
            case 'R':
                red++;
                break;
            case 'G':
                green++;
                break;
            case 'B':
                blue++;
                break;
        }
    }

    int RED[red], GREEN[green], BLUE[blue];
    int r_f = 0, g_f = 0, b_f =0;
    for(int i =0; i < N; i++){
        switch(RGB[i]){
            case 'R':
                RED[r_f] = i;
                r_f++;
                break;
            case 'G':
                GREEN[g_f] = i;
                g_f++;
                break;
            case 'B':
                BLUE[b_f] = i;
                b_f++;
                break;
        }
    }

int num = 0;
int num_list[3], num_change[3];
    for(int a = 0; a < red; a++){
        num_list[0] = RED[a];
        for(int b = 0; b < green; b++){
            num_list[1] = GREEN[b];
            for(int c = 0; c < blue; c++){
                num_list[2] = BLUE[c];
                num_change[0] = num_list[0];
                num_change[1] = num_list[1];
                num_change[2] = num_list[2];
                sort_num(num_change);
                if ( (num_change[2] - num_change[1]) != (num_change[1] - num_change[0]) )
                    num++;
            }
        }
    }
    printf("%d", num);
    return 0;
}

void sort_num(int* num){
    int tmp;
    if (num[0] > num[1])
        change_num(num, 0, 1);
    if (num[1] > num[2])
        change_num(num, 1, 2);
    if (num[0] > num[1])
        change_num(num, 0, 1);
}
void change_num(int* num, int a, int b){
    int tmp;
    tmp = num[a];
    num[a] = num[b];
    num[b] = tmp;
}