#include <stdio.h>
#include <stdlib.h>
int posR[4004],posG[4004],posB[4004];

int main(){

	int  i,j,k;
	int N,nr=0,ng=0,nb=0;
	long long sum=0;
	int index_s=0,index_end=0;
	char s[4004];
	scanf("%d",&N);
	scanf("%s",s);
	char c;
	for(i=0;i<N;i++){
		
		//printf("%c\n",c);
		if(s[i]=='R'){
			nr++;
			posR[i+1]=nr;
		}
		else if(s[i]=='G'){
			ng++;
			posG[i+1]=ng;
		}
		else if(s[i]=='B'){
			nb++;
			posB[i+1]=nb;
		}
	}
	
	
	for(i=1;i<=N-2;i++){
		if(posR[i]!=0){
		for(j=i+1;j<=N-1;j++){
			
			if(posG[j]!=0){
				index_s=0,index_end=0;
			for(k=j+1;k<=N;k++){
				
				if(posB[k]!=0){
					if(index_s==0){
						index_s=k;index_end=k;
					}
					else index_end=k; 
				}
			}
				int tmp,tmp2;
				tmp = (posB[index_end]-posB[index_s])+1;
				if(posB[j+(j-i)]>0)tmp--;
				sum += tmp;
				//printf("%d,%d,%d|%d\n",i,j,posB[index_end],posB[index_s]);
			}
			
		}
		}
	}
	
	printf("%lld\n",sum);
}