#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;
	int sum_of_R = 0;
	int sum_of_G = 0;
	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);

	array_of_R = (int*)malloc(N * sizeof(int));
	array_of_G = (int*)malloc(N * sizeof(int));
	array_of_B = (int*)malloc(N * sizeof(int));

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

	for(i = 0; i < sum_of_R; i++) {
		for(j = 0; j < sum_of_G; j++) {
			for(k = 0; k < sum_of_B; k++) {
				a = array_of_R[i];
				b = array_of_G[j];
				c = array_of_B[k];
				sort3(&a, &b, &c);
//				printf("%d, %d, %d\n", a, b, c);

				if(b - a == c - b) {
//					sum_cont++;
					continue;
				}

				sum++;
			}
		}
	}

	printf("%d\n", sum);
//	printf("%d\n", sum_cont);
	return 0;
}

