#include <bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(ll i =(l);(i)<(r);(i)++)
using namespace std;
//TLE
int main(){
    ll n,ans=0;
    cin>>n;
    string s;
    cin>>s;
    rep(i,0,n-2){
        rep(j,i+1,n-1){
            rep(k,j+1,n){
                if((s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k])&&j-i!=k-j)ans++;
            }
        }
    }
    cout<<ans<<endl;
}