#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(n) n.begin(),n.end()
#define yn(x) cout << (x ? "Yes":"No") << endl;

int main() {
  ll n;
  string s;
  cin >> n >> s;
  ll cnt = 0;
  rep(i,n){
    rep(j,n){
      rep(k,n){
        if(i<j && j<k){
          if(s[i]!=s[j]&&s[i]!=s[k]){
            if(j-i!=k-j) cnt++;
          }
        }
      }
    }
  }
  cout << cnt << endl;
}
