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

int main(void){
  int N;
  //char *S;
  char S[5000];
  int count=0;
  
  if(scanf("%d",&N) != 1){
    printf("*****SCANF ERROR****\n");
    exit(1);
  }
  //S=(char*)malloc(sizeof(char )*N);

  if(scanf("%s",S) != 1){
    printf("*****SCANF ERROR S****\n");
    exit(1);
  }

  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      for(int k=j+1;k<N;k++){
	if((S[i] != S[j]) && (S[j] != S[k]) && (S[k] != S[i]) && (j-i != k-j)) count++;
      }
    }
  }
  printf("%d\n",count);  
  
  return 0;
}