#include <stdio.h>
#define max 4001

int main(void){
    int i, j, k = 3, N, sum = 0;
    char S[max];
    scanf("%d", &N);
    scanf("%s", S);
    

    while(k <= N){
        i = 1, j = 2;
        while(j < k){
            i = 1;
            while(i < j){
                if(S[i - 1] != S[j - 1] && S[i - 1] != S[k - 1] 
                && S[j - 1] != S[k - 1] && j - i != k - j) sum++;
                i++;
            }j++;
        }k++;
    }
    printf("%d\n", sum);

    return 0;
}