#include<stdio.h>
 
int main(void){
 
    long long int N,i,j,R_num = 0,G_num = 0,B_num = 0,ans = 0;
  	char s1[1],s2[1],s3[1];
    char S[4001];
    scanf("%d",&N);
    scanf("%s",S);
    for(i = 0;i < N;i++){
        if(S[i] == 'R') R_num++;
        else if(S[i] == 'G') G_num++;
        else if(S[i] == 'B') B_num++;
    }
    ans = R_num * G_num * B_num;
    for(i = 0;i < N;i++){
        for(j = 0;j < N;j++){
            if(i+j*2 >= N) break;
          	s1=S[i];
          	s2=S[i+j];
          	s3=S[i+j*2];
            if(s1!=s2 && s2!=s3 && s1!=s3) ans--;
        }
    }
    printf("%lld\n",ans);
    return 0;
}