#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i)++)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)
#define min3(a,b,c) (a)<(b)?(min(a,c)):(min(b,c))
#define max3(a,b,c) (a)>(b)?(max(a,c)):(max(b,c))
#define abs(a) (a)>0?(a):-(a)
#define llong long long

int main(){
	int N; scanf("%d",&N);
	llong cnt=0;
	char S[N]; scanf("%s",S);
	int R[N],G[N],B[N];
	int r=0,g=0,b=0;
	rep(i,1,N+1){
		char s=S[i-1];
		if( s=='R' ){
			R[r]=i; r++;
		}else if( s=='G' ){
			G[g]=i; g++;
		}else{
			B[b]=i; b++;
		}
	}
	rep(i,r,N) R[i]=-1;
	rep(i,g,N) G[i]=-1;
	rep(i,b,N) B[i]=-1;
	r=0; g=0; b=0;
	while( R[r]!=-1 ){
		int RR=R[r];
		g=0;
		while( G[g]!=-1 ){
			int GG=G[g];
			b=0;
			while( B[b]!=-1 ){
				int BB=B[b];
				int min=min3(RR,GG,BB),max=max3(RR,GG,BB);
				if( min<RR && RR<max && (max-RR)!=(RR-min) ){
					cnt++;
				}else if(min<GG && GG<max && (max-GG)!=(GG-min) ){
					cnt++;
				}else if(min<BB && BB<max && (max-BB)!=(BB-min) ){
					cnt++;
				}
				b++;
			}
			g++;
		}
		r++;
	}
	printf("%lld",cnt);
	return 0;
}
