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

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

int main(void){
	int n;
	char s[4010];
	scanf("%d",&n);
	scanf("%s",s);
	long long count=0;
	int i, j, k;
	for(i=0;i<n-2;i++){
		for(j=i+1;j<n-1;j++){
			if(s[i] != s[j]){
				for(k=j+1;k<n;k++){
					if(s[k] != s[i] && s[k] != s[j] && i+k != 2*j){
						count++;
					}
				}
			}
		}
	}
	printf("%lld\n",count);
    return 0; 
}
