#include <stdio.h>

int main() {
    long long x = 0;

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

    for (int i = 2; i < N; i++) {
        for (int j = 1; j < i; j++) {
            if (S[i] != S[j]) {
                for (int k = 0; k < j; k++) {
                    if (S[j] != S[k] && S[k] != S[i] && j - i != k - j) {
                        x++;
                    }
                }
            }
        }
    }

    printf("%lld\n", x);
    return 0;
}