#include <stdio.h>
#include <stdlib.h>

void swap(int *nx, int *ny)
{
    int temp = *nx;
    *nx = *ny;
    *ny = temp;
}

/*--- *n1≦*n2≦*n3となるように並べ替える ---*/
void sort3(int *n1, int *n2, int *n3)
{
    if (*n1 > *n2) swap(n1, n2);
    if (*n2 > *n3) swap(n2, n3);
    if (*n1 > *n2) swap(n1, n2);
}

int main() {
	int N;
	char *S;
	long long int sum_of_R = 0;
	long long int sum_of_G = 0;
	long long int sum_of_B = 0;
	int *array_of_R;
	int *array_of_G;
	int *array_of_B;
	int i, j, k; int count_R = 0; int count_G = 0;
	int count_B = 0;
	int a, b, c;
	int sum = 0;
	int sum_cont = 0;

	scanf("%d", &N);
	S = (char*)malloc(N * sizeof(char));
	scanf("%s", S);

	for(i = 0; i < N; i++) {
		if(S[i] == 'R') {
			sum_of_R++;
		} else if(S[i] == 'G') {
			sum_of_G++;
		} else if(S[i] == 'B') {
			sum_of_B++;
		}
	}

	for(i = 1; i * 2 < N; i++) {
		//for(j = 0; j < N - i * 2; j++) {
		for(j = 0; j + 2 * i < N; j++) {
			//printf("%d, %d, %d\n", j, j + i, j + 2 * i);
			if(S[j] == S[j + i]
				|| S[j + i] == S[j + 2 * i]
				|| S[j] == S[j + 2 * i]) {
				continue;
			}
			sum++;
		}
	}

	//printf("%d\n", sum_of_R * sum_of_G * sum_of_B);
	printf("%lld\n", sum_of_R * sum_of_G * sum_of_B - sum);
	return 0;
}

