#include <stdio.h>
#include <inttypes.h>

int N;
char S[4096];

int id(char c) {
	switch (c) {
		case 'R': return 0;
		case 'G': return 1;
		case 'B': return 2;
	}
	return 3;
}

int rui[4][4096];

int main(void) {
	int i, j;
	uint64_t kotae = 0;
	if (scanf("%d", &N) != 1) return 1;
	if (scanf("%4095s", S) != 1) return 1;
	for (i = 0; i < N; i++) {
		rui[id(S[i])][i]++;
	}
	for (i = 0; i < 3; i++) {
		for (j = 1; j <= N; j++) rui[i][j] += rui[i][j - 1];
	}

	for (i = 0; i < N; i++) {
		for (j = i + 1; j < N; j++) {
			if (S[i] != S[j]) {
				int target = 3 - id(S[i]) - id(S[j]);
				int delta = rui[target][N] - rui[target][j];
				if (j + (j - i) < N && id(S[j + (j - i)]) == target) delta--;
				kotae += delta;
			}
		}
	}

	printf("%" PRIu64 "\n", kotae);
	return 0;
}
