#include<stdio.h>

int main() {
	int n, p = 0;
	char s[4001];
	scanf("%d", &n);
	scanf("%s", &s);
	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 1; j < n-1; j++) {
			for (int k = j + 1; k < n; k++) {
				if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i] && j - i != k - j) {
					p = p + 1;
				}
			}
		}
	}
	printf("%d", p);
}