#include <stdio.h>
#include <string.h>
#include <math.h>


int main(void) {
	int n;
	char s[4000];
	scanf("%d", &n);
	scanf("%s", s);

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

		}
	}
	printf("%d", count);

	return 0;
}