#include<stdio.h>

int main(void){

    int N;
    char string[4001];

    int count = 0;

    //入力部分
    scanf("%d",&N);
    for(int i=0;i<=N;i++){
        scanf("%c",&string[i]);
    }

    //計算部分
    for(int index1 = 1; index1 <= N; index1++){
        for(int index2 = index1+1; index2 <= N; index2++){
            if(string[index1]!=string[index2]){
                for(int index3 = index2+1; index3 <= N; index3++){
                    if((string[index2]!=string[index3])&&(string[index3]!=string[index1])){
                        if((index2-index1)!=(index3-index2))count++;
                    }
                }
            }
        }
    }


    //出力部分
    printf("%d\n",count);
}