#include<stdio.h>

int main(void){

  int N,i,j,k,count=0;
  scanf("%d",&N);
  char s[N];
  scanf("%s",s);

  for(i=1;i<=N;i++){
    for(j=2;j<=N;j++){
      for(k=4;k<=N;k++){
        if(i<=j&&j<=k&&k<=N){
          if(s[i-1]!=s[j-1] && s[i-1]!=s[k-1] && s[j-1]!=s[k-1]){
            if(j-i != k-j){
              count++;
          }
        }
      }
    }
  }
}
printf("%d",count);


  return 0;
}