#include <stdio.h>
char s[4001];
long long ans, n, r, g, b;
int main() {
	scanf("%lld", &n);
	scanf(" %s", s);
	for (long long i = 0; i < n; i++) {
		if (s[i] == 'R')r++;
		if (s[i] == 'G')g++;
		if (s[i] == 'B')b++;
	}
	ans = r * g * b;
	for (long long i = 0; i < n; i++) {
		for (long long j = 1; i + j * 2 < n; j++) {
			if (s[i] != s[i + j] && s[i] != s[i + j * 2] && s[i + j] != s[i + j * 2])ans--;
		}
	}
	printf("%lld\n", ans);
}