#include <stdio.h>

int main(void){
	int n;
	long int ans=0;
	scanf("%d",&n);
	char s[n+1];
	scanf("%s",s);
	int countr=0;
	int countg=0;
	int countb=0;
	for(int i=0; i<n; i++){
		if(s[i]=='R'){
			countr++;
		}
		if(s[i]=='G'){
			countg++;
		}
		if(s[i]=='B'){
			countb++;
		}
	}
	ans=countr*countg*countb;
	int i=0;
	int j=1;
	int k=2;
	while(i<=n-3){
		if(s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k]){
			ans--;
		}
		j++;
		k+=2;
		if(k>n-1){
			i++;
			j=i+1;
			k=i+2;
		}
	}
	
	/*int i=0;
	int j=1;
	int k=2;
	for(i=0; i<j; i++){
		for(j=i+1; j<k; j++){
			for(k=j+1; k<n; k++){
				printf("%d %d %d\n",i,j,k);
				if(s[i]==s[j]){
					k=n-1;
				}
				if(s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k]&&j-i!=k-j){
					ans++;
				}
			}
		}
	}*/
	printf("%ld\n",ans);
	return 0;
}