#include<stdio.h>
#include<stdlib.h>
#define ll long long
int cmp(const void *a,const void *b){return *(int*)a-*(int*)b;}
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
int mid(int a,int b,int c){
    int d[3];
    d[0] = a;
    d[1] = b;
    d[2] = c;
    qsort(d,3,sizeof(int),cmp);
    return d[1];
}
int  main(){
    int n;
    scanf("%d",&n);
    char s[n + 1];
    scanf("%s",s);
    int r[n],g[n],b[n];
    int inr = 0, ing = 0, inb = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R'){
            r[inr] = i;
            inr ++;
        }
        else if(s[i] == 'G'){
            g[ing] = i;
            ing ++;
        }
        else{
            b[inb] = i;
            inb ++;
        }
    }
    ll ans = 0;
    for(int i = 0; i < inr; i++){
        for(int j = 0; j < ing; j++){
            for(int k = 0; k < inb; k++){
                int p = min(r[i],min(g[j],b[k]));
                int q = max(r[i],max(g[j],b[k]));
                int t = mid(r[i],g[j],b[k]);
                if(2 * t != p + q)
                    ans++;
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}