#include <bits/stdc++.h>

using namespace std;

int main() {
    int N, res = 0;
    string S;

    cin >> N;
    cin >> S;

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

            for (int k = j + 1; k < N; ++k) {
                if (k == 2 * j - i) {
                    continue;
                }
                if (S[i] == S[k] || S[j] == S[k]) {
                    continue;
                }

                res++;
            }
        }
    }

    cout << res;
    return 0;
}

