#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++) {
				if(s[j]!=s[i])
					for (k = j; k < N; k++) {
						if (s[k] != s[j] && s[k] != s[i]&&k-j!=j-i)
							count++;
					}
			}
	}
	printf("%ld", count);

	return 0;
}