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

int cen(int num1,int num2,int num3){
    if(num1 >= num2 && num1 >= num3){
        if(num2 >= num3){
            return num2;
        }else{
            return num3;
        }
    }else if(num2 >= num1 && num2 >= num3){
        if(num1 >= num3){
            return num1;
        }else{
            return num3;
        }
    }else{
        if(num1 >= num2){
            return num1;
        }else{
            return num2;
        }
    }
}

int main(){
    int n;
    char s[4000];
    int r[4000];
    int g[4000];
    int b[4000]; 
    long long int sum = 0;
    scanf("%d",&n);
    scanf("%s",s);
    int rnum = -1;
    int gnum = -1;
    int bnum = -1;
    for(int i = 0;i < n;i++){
        if(s[i] == 'R'){
            rnum++;
            r[rnum] = i;
            continue;
        }else if(s[i] == 'G'){
            gnum++;
            g[gnum] = i;
            continue;
        }else{
            bnum++;
            b[bnum] = i;
            continue;
        }
    }
    for(int i = rnum;i >= 0;i--){
        for(int j = gnum;j >= 0;j--){
            for(int k = bnum;k >= 0;k--){
                if((cen(r[i],g[j],b[k]) == r[i] && 2*r[i] != g[j] + b[k]) || (cen(r[i],g[j],b[k]) == g[j] && 2*g[j] != r[i] + b[k]) || (cen(r[i],g[j],b[k]) == b[k] && 2*b[k] != g[j] + r[i])){
                    sum++;
                }
            }
        }
    }
    printf("%lld",sum);
    return 0;
}
