#include <stdio.h>

void setArr(char *arr, char a, char b, char c) {
    arr[0] = a;
    arr[1] = b;
    arr[2] = c;
    arr[3] = '\0';
}

int checkArr(char *arr) {
    if (arr[0] != arr[1] && arr[0] != arr[2] && arr[1] != arr[2]) {
        return 1;
    }
    return 0;
}

int main(void) {
    int N;
    char S[4001];
    scanf("%d", &N);
    scanf("%s", S);

    int result = 0;
    int i, j, k;
    char check1[4];
    char check2[4];
    for (i = 0; i < N; i++) {
        for (j = 1; j < N - i - 1; j++) {
            for (k = 1; k < N; k++) {
                if (j == k) continue;
                if (i + j + k > N - 1) break;
                    setArr(check1, S[i], S[i + j], S[i + j + k]);
                    if (checkArr(check1)) {
                        result++;
                    }
                    setArr(check2, S[i], S[i + k], S[i + j + k]);
                    if (checkArr(check2)) {
                        result++;
                    }
            }
        }
    }
    printf("%d\n", result / 2);
    return 0;
}