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

int main(void) {
    char buf[8];
    char *p;
    int N;
    int i,j,k,cnt = 0;

    p = fgets(buf, 8, stdin);
    N = atoi(buf);

    p = (char*)malloc(sizeof(int) * (N+2));
    (void)fgets(p, sizeof(int)*(N+2),stdin);

    for(i=0;i<N-2;i++) {
        for(j=i+1;j<N-1;j++){
            for(k=j+1;k<N;k++){
                if(j-i == k-j)continue;
                if((p[i] != p[j]) && (p[i] != p[k]) && (p[j] != p[k]))cnt++;
            }
        }
    }
    
    printf("%d\n", cnt);

    return 0;
}
