#include <stdio.h>

int main(void) {

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

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

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

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

	return 0;
}