#include <stdio.h>

int main() {
	int n, r = 0, g = 0, b = 0;
	long long int ans=0;
	char S[4010];
	scanf("%d", &n);
	scanf("%s", &S);
	

	//printf("%s", S);

	int N[4][4010] = {0};
	char dd[4] = { '0','R','G','B' };

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (S[j] == 'B')N[3][i]++;
			if (S[j] == 'R')N[1][i]++;
			if (S[j] == 'G')N[2][i]++;
		}
	}
	//for (int i = 0; i < n; i++) printf("%d %d %d\n", N[1][i], N[2][i], N[3][i]);

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (S[i] == S[j]) continue;
			int o = 0;
			if ((S[i] == 'R' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'R'))o = 3;
			if ((S[i] == 'B' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'B'))o = 1;
			if ((S[i] == 'R' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'R'))o = 2;
			ans += N[o][j];
			if (2 * j - i < n) {
				if (S[2 * j - i] == dd[o])ans--;
			}
		}
	}
	printf("%lld", ans);
	return 0;
}