#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N;
    string S;
    cin >> N >> S;
    ll sum = 0;
    rep(i, N) {
        for (int j = i + 1; j < N; j++) {
            if (S.at(i) == S.at(j)) continue;
            for (int k = j + 1; k < N; k++) {
                if (j - i == k - j) continue;
                if (S.at(i) != S.at(k) && S.at(j) != S.at(k)) sum++;
            }
        }
    }
    cout << sum << endl;
}
