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

int main()
{
  long long int N,M;
  long long int i,j,k;
  long long int A,B;
  long long int ans=0;
  scanf("%lld",&N);
  char buff[N+2];
  scanf("%s",buff);
  
  ans = 0;
  for(i=0;i<N;i++){
    for(j=i+1;j<N;j++){
      if( buff[i] != buff[j] ){
        for(k=j+1;k<N;k++){
          if( buff[i] != buff[k] && buff[j] != buff[k] && (j-i) != (k-j) ){
            ans++;
          }
        }
      }
    }
  }

  printf("%lld\n",ans);
  return 0; 
}