#include<stdio.h>
int main(void){
  int N,i,j,k,A = 0;
  scanf("%d",&N);
  char S[N];
  scanf("%s",S);
  for(i = 0; i < N-2;i ++)
    for(j = i + 1;j < N-1;j++)
      for(k = j + 1;k < N;k++)
          if((S[i] != S[j]) && (S[i] != S[k]) && (S[j] != S[k]))
            if(j-i != k-j)
            A++;
  printf("%d",A);
}
