#include <stdio.h>

int main(void)
{
	int i,x,y,N,r[4000],g[4000],b[4000],rc=0,gc=0,bc=0,rp[4000],gp[4000],bp[4000];
	char S[4000];
	long long total=0;
	scanf("%d",&N);
	scanf("%s",S);
	for(i=0;i<N;i++){
		if(S[i]=='R'){
			rp[rc]=i;
			rc++;
		}else if(S[i]=='G'){
			gp[gc]=i;
			gc++;
		}else{
			bp[bc]=i;
			bc++;
		}
		r[i]=rc;
		g[i]=gc;
		b[i]=bc;
	}
	for(x=0;x<rc;x++){
		for(y=0;y<gc;y++){
			if(rp[x]<gp[y]){
				if(S[gp[y]*2-rp[x]]=='B')total+=bc-b[gp[y]]-1;
				else total+=bc-b[gp[y]];
			}
		}
	}
	for(x=0;x<gc;x++){
		for(y=0;y<bc;y++){
			if(gp[x]<bp[y]){
				if(S[bp[y]*2-gp[x]]=='R')total+=rc-r[bp[y]]-1;
				else total+=rc-r[bp[y]];
			}
		}
	}
	for(x=0;x<bc;x++){
		for(y=0;y<rc;y++){
			if(bp[x]<rp[y]){
				if(S[rp[y]*2-bp[x]]=='G')total+=gc-g[rp[y]]-1;
				else total+=gc-g[rp[y]];
			}
		}
	}
	for(x=0;x<rc;x++){
		for(y=0;y<bc;y++){
			if(rp[x]<bp[y]){
				if(S[bp[y]*2-rp[x]]=='G')total+=gc-g[bp[y]]-1;
				else total+=gc-g[bp[y]];
			}
		}
	}
	for(x=0;x<gc;x++){
		for(y=0;y<rc;y++){
			if(gp[x]<rp[y]){
				if(S[rp[y]*2-gp[x]]=='B')total+=bc-b[rp[y]]-1;
				else total+=bc-b[rp[y]];
			}
		}
	}
	for(x=0;x<bc;x++){
		for(y=0;y<gc;y++){
			if(bp[x]<gp[y]){
				if(S[gp[y]*2-bp[x]]=='R')total+=rc-r[gp[y]]-1;
				else total+=rc-r[gp[y]];
			}
		}
	}
	printf("%lld",total);
	return 0;
}