#include<stdio.h>
#include<stdlib.h>
void swap(int *x,int *y){
    int tmp=*x;
    *x=*y;
    *y=tmp;
}

int main(){
    int n;scanf("%d",&n);
    char s[n+1];scanf("%s",s);

    int r[4000]={},g[4000]={},b[4000]={};
    int r_i,g_i,b_i;r_i=g_i=b_i=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R')r[r_i++]=i;
        if(s[i]=='G')g[g_i++]=i;
        if(s[i]=='B')b[b_i++]=i;
    }
    int cnt=0;
    for(int i=1;i<n-1;i++){
        int dist=1;
        while(i-dist>=0&&i+dist<n){
            if(s[i-dist]!=s[i]&&s[i]!=s[i+dist]&&s[i-dist]!=s[i+dist])
                cnt++;
            dist++;
        }
    }
    long long ans=r_i*g_i*b_i;
    printf("%lld\n",ans-cnt);
}