#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    ll  ans = 0;
    for(int i = 0; i <= n-3; ++i){
        for(int j = i+1; j <= n-2; ++j){
            for(int k = j+1; k <= n-1; ++k) {
                if(j-i == k-j) continue;
                if(s[i]==s[j] || s[i]==s[k] || s[j]==s[k]) continue;
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}