#include <stdio.h>

int main(void) {
	short int n, num = 0; 
	char s[4000];

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

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

	printf("%d", num);

	return 0;
}

