#include <stdio.h>
#include <string.h>

#define MAX 5000

typedef unsigned long long int ULLI;

void change(char*, char,char);
int work(int, int, int);

int main()
{
	int n;
	ULLI count = 0;
	char s[MAX], *rp, *gp, *bp;

	scanf("%d", &n);
	scanf("%s", s);


	while ((rp=strchr(s, 'R')) != NULL) {
		while ((gp=strchr(s, 'G')) != NULL) {
			while ((bp = strchr(s, 'B')) != NULL) {
				s[bp - s] = '0';
				count += work(rp - s, gp - s, bp-s);
			}
			s[gp - s] = '1';
			change(s,'0','B');
		}
		change(s, '1','G');
		s[rp - s] = '2';
	}

	printf("%llu\n", count);

	return 0;
}

void change(char* s, char c,char h)
{
	char* p;

	while ((p = strchr(s, c)) != 0)
		s[p - s] = h;

}

int work(int i,int j,int k)
{
	int a, b, temp, r=0;
	int data[4];

	data[0] = i;
	data[1] = j;
	data[2] = k;

	for (a = 0; a < 3; a++) {
		for (b =a+1; b < 3; b++) {
			if (data[a] > data[b]) {
				temp = data[a];
				data[a] = data[b];
				data[b] = temp;
			}
		}
	}

	i = data[0];
	j = data[1];
	k = data[2];

	if ((j - i) != (k - j))
		r = 1;

	return r;
}