#include<stdio.h>
int main(){
	int count =0;
	int n;	scanf("%d", &n);
	char s[4002];	scanf("%s", s);
	for(int i=0; i<n-2; i=i+1){
		for(int j=i+1; j<n-1; j=j+1){
			if(s[i] != s[j]){
				for(int k=j+1; k<n; k=k+1){
					if(s[k]!=s[i] && j-i!=k-j && s[k]!=s[j]){
						count=count+1;
					}
				}
			}
		}
	}
	printf("%d", count);
	return 0;
}