#include <stdio.h>

int main()
{
	int i, N;
	char S[4001];
	scanf("%d", &N);
	scanf("%s", S);
	
	long long R = 0, G = 0, B = 0, ans = 0;
	for (i = 0; i < N; i++) {
		if (S[i] == 'R') {
			ans += G * B;
			R++;
		} else if (S[i] == 'G') {
			ans += B * R;
			G++;
		} else {
			ans += R * G;
			B++;
		}
	}
	
	int j;
	for (i = 0; i < N; i++) {
		for (j = 1; j < (N - i + 1) / 2; j++) {
			if (S[i] != S[i+j] && S[i+j] != S[i+j*2] && S[i+j*2] != S[i]) ans--;
		}
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}