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

int doCount(int i, int **a, int **b) {
	int *ap = *a;
	int *bp = *b;
	int count = 0;

	while (*ap < i) {
		if (*ap == -1)
			goto done;
		ap++;
	}

	while (*bp < i) {
		if (*bp == -1)
			goto done;
		bp++;
	}

	int *xp = ap;
	int *yp = bp;

	while (*xp != -1 && *yp != -1) {
		if (*xp  > *yp) {
			int *tmp = xp;
			xp = yp;
			yp = tmp;
		}

		int j = *xp;
		for (int y = 0; yp[y] != -1; y++) {
			int k = yp[y];
			if (j - i != k - j)
				count++;
		}
		xp++;
	}

done:
	*a = ap;
	*b = bp;
	return count;
}

int main() {
	char buf[4096];
	int n;

	fgets(buf, sizeof buf, stdin);
	n = atoi(buf);

	fgets(buf, sizeof buf, stdin);
	buf[n] = '\0';

	int count = 0;
	int rpos[4000], gpos[4000], bpos[4000];
	int rc = 0, gc = 0, bc = 0;
	for (int i = 0; i < n; i++) {
		switch (buf[i]) {
		case 'R':
			rpos[rc++] = i;
			break;
		case 'G':
			gpos[gc++] = i;
			break;
		case 'B':
			bpos[bc++] = i;
			break;
		}
	}

	if (rc == 0 || gc == 0 || bc == 0) {
		goto done;
	}

	rpos[rc] = gpos[gc] = bpos[bc] = -1;

	int *rp = rpos;
	int *gp = gpos;
	int *bp = bpos;

	for (int i = 0; i < n - 2; i++) {
		switch (buf[i]) {
		case 'R':
			count += doCount(i, &gp, &bp);
			rp++;
			break;
		case 'G':
			count += doCount(i, &rp, &bp);
			gp++;
			break;
		case 'B':
			count += doCount(i, &rp, &gp);
			bp++;
			break;
		}
		if (*rp == -1 || *gp == -1 || *bp == -1)
			break;
	}

done :
	printf("%d\n", count);
	return 0;
}
