#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};

int gcm(int a, int b) { return b ? gcm(b, a % b) : a;}

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    rep(i,n) {
        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[k] || s[j] == s[k]) continue;
                ans++;
            }
        }
    }
    cout << ans << endl;
}
