#include <stdio.h>

int check(char a, char b, char c) {
    if(a !=b && a != c && b != c) {
        return 1;
    }
    return 0;
}
int main(void) {
    int N;
    char S[4001];
    scanf("%d", &N);
    scanf("%s", S);

    int result = 0;
    int head, center, tail;
    for (head = 0; head < N - 3; head++) {
        for (tail = 3; tail < N; tail++) {
            for (center = head + 1; center < tail; center++) {
                if (center - head == tail - center) {
                    continue;
                }
                if (check(S[head], S[center], S[tail])) {
                    result++;
                }
            }
        }
    }

    printf("%d\n", result);
    return 0;
}