#include <stdio.h>
int main(void){
    int n;
    int i,j,k;
    int l;
    long ret = 0;
    char S[4001];
    int tmp;
    scanf("%d",&n);
    scanf("%s",S);
    for(i = 0 ; i < (n-2) ; i++){
        for(j = i+1 ; j < (n-1) ; j++){
            if(S[j] != S[i]){
                tmp = j-i;
                for(k = j+1 ; k < n ; k++){
                    if ((S[k] != S[j]) && (S[k] != S[i])) {
                        if ((tmp) != ( k-j )){
                            ret++;
                        }   
                    }
                }
            }
        }
    }
    printf("%lu\n",ret);
    return 0;
}
