#include <stdio.h>
#include <stdlib.h>
int main(void){
  int n,i,j,k,ans;
  char *s;

  scanf("%d",&n);
  s = (char *)malloc(sizeof(char) * n);
  if(s == NULL) exit(0);

  scanf("%s",s);
  for(i=0;i<n-3;i++){
    for(j=i+1;j<n-1;j++){
      if(s[i] != s[j]){
        for(k=j+1;k<n;k++){
          if(s[i]!=s[k] && s[j]!=s[k] && j-i!=k-j){
            ans++;
          }
        }
      }
    }
  }

  printf("%d\n",ans);
  free(s);
  return 0;
}
