#include <stdio.h>
#include <stdlib.h>
int main(void){
  int n;
  char s;
  int i,j,k;
  int total=0;
  scanf("%d",&n);
  s=(char)calloc(n,sizeof(char));
  scanf("%s",&s);
  for(i=1;i<=n;i++){
    for(j=i;j<=n;j++){
      for(j=j;j<=n;j++){
        if(s[i]!=s[j] && s[i]!=s[k] && s[j]!=s[k] && j-i!=k-j)total++;
      }
    }
  }
  printf("%d",total);
  free(s);
  return 0;
}
