/**
 * Title:
 * Url:
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {

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

    return 0;
}