#include <stdio.h>
 
int main(void){
  int n, i, j, k, sum=0;
  char s[4001];
  
  scanf("%d", &n);
  scanf("%s", &s);
  
  for(i = 0; i < n-2; 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[j])&&(s[j] != s[k])&&(s[k] != s[i])&&((j-i) != (k-j))){
          sum++;
        }
       } 
      }
    }
  }
  printf("%d", sum);
  
  return 0;
}