#include<stdio.h>

int main(void)
{
	unsigned long int a, b, c, N;
	int sum = 0;
	char mozi[4001];
	
	scanf("%ld", &N);
	scanf("%s", &mozi);
	
	for (a = 1; a <= (N - 3); a++) {
		for (b = (a + 1); b <= (N - 1); b++) {
			if (mozi[a - 1] != mozi[b - 1]) {
				for (c = (b + 1); c <= N; c++) {
					if ((mozi[a - 1] != mozi[c - 1]) && (mozi[b - 1] != mozi[c - 1])) {
						if ((b - a) != (c - b)) {
							sum++;
						}
					}
				}
			}
		}
	}

	printf("%ld", sum);

	return 0;
}