#include <stdio.h>

int main(void) {
	int N;
	int A[4000];
	int B[4000];
	int C[4000];
	int nA = 0;
	int nB = 0;
	int nC = 0;
	long num = 0;

	
	scanf("%d\n", &N);
	for(int i = 0; i < N; i++) {
		char tmp;
	
		scanf("%c", &tmp);
		if(tmp == 'R') {
			A[nA] = i + 1;
			nA++;
		}
		else if(tmp == 'G') {
			B[nB] = i + 1;
			nB++;
		}
		else if(tmp == 'B') {
			C[nC] = i + 1;
			nC++;
		}
	}
	
	for(int i = 0; i < nA; i++) {
		for(int j = 0; j < nB; j++) {
			for(int k = 0; k < nC; k++) {
				int tmp;
				
				int x[3];
				x[0] = A[i];
				x[1] = B[j];
				x[2] = C[k];
				
				if(x[0] > x[1]) {
					tmp = x[0];
					x[0] = x[1];
					x[1] = tmp;
				}
				if(x[0] > x[2]) {
					tmp = x[0];
					x[0] = x[2];
					x[2] = tmp;
				}
				if(x[1] > x[2]) {
					tmp = x[1];
					x[1] = x[2];
					x[2] = tmp;
				}
				
				if( (x[1] - x[0]) == (x[2] - x[1]) ) continue;
				
				num++;
			}
		}
	}
	printf("%ld\n", num);
	
	return 0;
}
