#include <stdio.h>

int main(){
	int n;
	if(scanf("%d", &n)==EOF){return 0;}
	char buf[n+1];
	if(scanf("%*c%s", buf)==EOF){return 0;}

	int count = 0;
	for(int i=0; i<n-2; i++){
		for(int j =i+1; j<n-1; j++){
			if(buf[i]==buf[j]){continue;}
			for(int k = j+1; k<n; k++){
				if(buf[i]==buf[k] || buf[j]==buf[k]){continue;}
				if(j-i == k-j){continue;}
				count ++;
			}
			
		}
	}
	printf("%d\n", count);
	return 0;

}