#include<stdio.h>
#include<stdlib.h>
#include <string.h>

int main(void){

    int N;

scanf("%d", &N);

char S[N];

scanf("%s", &S);

int count=0;

int i, j, m;

for(i=0; i<N-2; i++){
    for(j=i+1; j<N-1; j++){
if(S[i] != S[j]){
     for(m=j+1; m<N; m++){
if(S[j] != S[m] && S[m] != S[i]){
    if(j-i != m-j){
        count +=1;
    }
}
        }

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