#include <stdio.h>

int aa(char c){
	if(c=='R'){
    	return 0;
    }else if(c=='G'){
    	return 1;
    }
  	return 2;
}

int main(void){
	char str[4001];
  	int flg[3]={-1,-1,-1};
  	int n,i,j,k;
  	int count=0;
  	scanf("%d",&n);
  	scanf("%s",str);
  	for(i=0;i<n-2;i++){
      	flg[aa(str[i])]=1;
    	for(j=i+1;j<n-1;j++){
          	if(flg[aa(str[j])]==1){continue;}
          	flg[aa(str[j])]==1;
        	for(k=j+1;k<n;k++){
            	if(flg[aa(str[k])]==1||j-i==k-j){continue;}
              	count++;
            }
          	flg[aa(str[j])]==-1;
        }
      	flg[aa(str[i])]=-1;
    }
  	printf("%d\n",count);
}


