#include <stdio.h>

int main(void) {
	int n, r = 0, g = 0, b = 0; 
	unsigned long int num;
	int k;
	char s[4001];

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

	for (int i = 0; i < n; i++) {
		switch (s[i]) {
		case 'R':
			r++;
			break;
		case 'G':
			g++;
			break;
		case 'B':
			b++;
			break;
		}
	}

	num = r * b * g;

	for (int j = 0; j < n; j++) {
		for (int i = 0; i < j; i++) {
			k = j + (j - i);
			if (k < n && num > 0 && i != j) {
				if (s[i] == s[j])
					continue;
				if (s[j] == s[k])
					continue;
				if (s[k] == s[i])
					continue;

				num--;
			}
		}
	}

	printf("%d", num);

	return 0;
}

