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

int main()
{
	int i,j,k;
	int count=0,N=0;
	char S[4000];

	scanf("%d", &N);
	scanf("%s", S);


	for(i=0;i<N-3;i++){
		for(j=i+1;j<N-1;j++){
			for(k=j+1;k<N;k++){

				if(S[i] != S[j] && S[i] != S[k] && S[j] != S[k] &&j-i != k-j){
					count++;
				}

			}
		}
	}

	printf("%d", count);


	return 0;
}
