#include<stdio.h>

int main(void)
{
	int N, i, j, k;
	long int count = 0;
	char s[4001];

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

	for (i = 0; i < N; i++) {
		for (j = i; j < N; j++) {
			for (k = j; k < N; k++) {
				if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i] && k - j != j - i) {
					count++;
				}
			}
		}
	}
	printf("%ld", count);

	return 0;
}