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

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

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

		int j = *a;
		int *kp = b;
		while (*kp != -1) {
			int k = *kp++;
			if (j - i != k - j)
				count++;
		}
		a++;
	}

	return count;
}

int main() {
	char buf[4096];
	int count = 0;

	if (!fgets(buf, sizeof buf, stdin))
		goto done;
	int n = atoi(buf);

	if (!fgets(buf, sizeof buf, stdin))
		goto done;
	buf[n] = '\0';

	int rpos[4001], gpos[4001], bpos[4001];
	int rc = 0, gc = 0, bc = 0;
	for (int i = 0; i < n; i++) {
		if (buf[i] == 'R')
			rpos[rc++] = i;
		else if (buf[i] == 'G')
			gpos[gc++] = i;
		else if (buf[i] == 'B')
			bpos[bc++] = i;
	}

	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 - 3; i++) {
		if (*rp == i) {
			count += doCount(i, gp, bp);
			rp++;
		} else if (*gp == i) {
			count += doCount(i, rp, bp);
			gp++;
		} else {
			count += doCount(i, rp, gp);
			bp++;
		}
		if (*rp == -1 || *gp == -1 || *bp == -1)
			break;
	}

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