#include <stdio.h>

int main(){
  int n;  scanf("%d", &n);
  char s[4001];  scanf("%s", s);

  int count = 0;
  for(int i=0; i<n-2; i++){
    for(int j=i+1; j<n-1; j++){
      if(s[i] == s[j])  continue;
      for(int k=j+1; k<n; k++){
	if(k-j == j-i || s[k]==s[j] || s[k]==s[i])  continue;
	count++;
      }
    }
  }

  printf("%d\n", count);
  return 0;
}
