#include <stdio.h>
int min(int x, int y) { return x < y ? x : y; }
int main() {
	int n, cnt = 0, Rcnt = 0, Gcnt = 0, Bcnt = 0;
	char s[4001];
	scanf("%d%s", &n, s);
	for (int i = 0; i < n; i++) {
		switch (s[i]) {
			case 'R':
				Rcnt++;
				break;
			case 'G':
				Gcnt++;
				break;
			case 'B':
				Bcnt++;
				break;
			default:
				break;
		}
	}
	cnt = Rcnt * Gcnt * Bcnt;
	for (int i = 1; i < n - 1; i++) {
		for (int j = 1; j <= min(i, n - i - 1); j++) {
			if (s[i - j] != s[i + j] && s[i - j] != s[i] && s[i + j] != s[i]) {
				cnt--;
			}
		}
	}
	printf("%d\n", cnt);
	return 0;
}