#include <stdio.h>
#define rep(i,r) for(int i=0;i<r;i++)

int main() {
	int N;
	scanf("%d", &N);
	char S[N];
	scanf("%s", &S);
	long R = 0, G = 0, B = 0;
	rep(i,N) {
		if (S[i] == 'R') R++;
		else if (S[i] == 'G') G++;
		else B++;
	}
	
	long count = R * G * B;
	for (int i = 0; i < N - 2; i++) {
		for (int j = 1; i + j * 2 < N; j++) {
			if (S[i] != S[i + j]
				&& S[i] != S[i + j * 2]
				&& S[i + j] != S[i + j * 2]) count--;
		}
	}
	
	printf("%ld", count);
	return 0;
}
