#include <stdio.h>

int main(void) {

	int n, i, j, k, r = 0, g = 0, b = 0, ans = 0, frg = 0;
	char s[4001];

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



	for (i = 0; i < n; i++) {
		if (s[i] == 'R') r++;
		else if (s[i] == 'G') g++;
		else b++;
	}

	ans = r * g * b;

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

			
	printf("%d\n", ans);

	return 0;
}