#include<stdio.h>

int main (void){
    int N;
    char S[4000];
    char c;
    int count=0;
    int i,j,k;

    scanf("%d",&N);
    scanf("%c",&c);
    for(i=0;i<N;i++){
        scanf("%c",&S[i]);
    }

    for(k=0;k<N;k++){
        for(j=0;j<k;j++){
            for(i=0;i<j;i++){
                if(2*(j+1)==i+k+2){
                    continue;
                }else if(S[i]!=S[j]&&S[i]!=S[k]&&S[j]!=S[k]){
                    count++;
                }

            }
        }
    }

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