#include <stdio.h>
int main(){
  long int N,i,j,k,count,num;
  char S[4000];
  scanf("%ld",&N);
  scanf("%s",S);
  count=N*(N-1)*(N-2)/6;
  for(i=0;i<N-2;i++){
    for(j=i+1;j<N-1;j++){
      if(S[i]==S[j]){
        num=N-j-1;
        count=count-num;
        continue;
      }
      for(k=j+1;k<N;k++){
        if(j-i==k-j){
          count--;
          continue;
        }
        if(S[j]==S[k] || S[k]==S[i]) count--;
      }
    }
  }
  printf("%ld",count);
  return 0;
}