#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    string S;
    cin >> N >> S;
    ll sum = 0;
    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 (j - i == k - j) {
                    continue;
                }
                if (S[i] != S[j] && S[i] != S[k] && S[j] != S[k]) {
                    sum++;
                }
            }
        }
    }
    cout << sum << endl;
}