#include <stdio.h>

int main() {
	int n = 0;
	int a = scanf("%d", &n);
	char s[4000] = {0};
	int b = scanf("%s", s);
  	
  	int sum = 0;
	int i, j, k;
	for (i = 0; i <= n - 3; i++)
		for (j = i + 1; j <= n - 3 + 1; j++)
			for (k = j + 1; k <= n - 3 + 2; k++) {
				if (s[i] != s[j] && s[k] != s[j] && s[k] != s[i] && ((j - i) != (k - j))) {
						sum++;
				}
			}
	printf("%d\n", sum);
	return 0;
}