# include <stdio.h>
# include <string.h>
# include <stdlib.h>
int  main(){
	int i,j,k,ans=0,n,a;
	char * s;
	scanf ("%d",&n);
	s=(char*)malloc(n*sizeof(char));
	scanf ("%s",s);
	int *red,*green,*blue,s_r=0,s_g=0,s_b=0;
	red=(int*)malloc(n*sizeof(int));
	blue=(int*)malloc(n*sizeof(int));
	green=(int*)malloc(n*sizeof(int));
	for(i=0;i<n;i++){
		if(s[i]=='R') s_r+=1;
		if(s[i]=='G') s_g+=1;
		if(s[i]=='B') s_b+=1;
		red[i]=s_r;
		blue[i]=s_b;
		green[i]=s_g;
	}
	for(i=0;i<n;i++){
		for(k=i+2;k<n;k++){
			if(s[i]!=s[k]){
				if((s[i]=='R' && s[k]=='B')|| (s[i]=='B' && s[k]=='R')){
					ans+=green[k-1]-green[i];
				}
				if((s[i]=='R' && s[k]=='G')|| (s[i]=='G' && s[k]=='R')){
					ans+=blue[k-1]-blue[i];
				}
				if((s[i]=='G' && s[k]=='B')|| (s[i]=='B' && s[k]=='G')){
					ans+=red[k-1]-red[i];
				}
				if((i+k)%2==0){
					a=(i+k)/2;
					if(s[a]!=s[i] && s[a]!=s[k]) ans-=1;
				}
			}
		}
	}
	printf ("%d\n",ans);
	return 0;
}