#include <stdio.h>


int main() {
	int n, i, j, k, Rc=0, Gc=0, Bc=0;
	char s[4000];
	int R[4000], G[4000], B[4000];
	long long ans=0;
	scanf("%d\n%s", &n, s);
	for (i = 0; i < n; i++) {
		if (s[i] == 'R') {
			R[Rc] = i;
			Rc++;
		}
		else if (s[i] == 'G') {
			G[Gc] = i;
			Gc++;
		}
		else {
			B[Bc] = i;
			Bc++;
		}
	}
	ans = (Rc) * (Gc) * (Bc);

	for (i = 1; i < n / 2; i++) {
		for (j = 0; j < n - 1 - i-i;j++) {
			if (s[j] != s[j + i] && s[j + i] != s[j + i + i] && s[j + i + i] != s[j]) {
				ans--;
			}
		}
	}

	printf("%lld", ans);





}