#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main(){
  ll n;
  cin >> n;
  string s;
  cin >> s;
  ll ans = 0;
  for(int i=1;i<=n-2;i++){
    for(int j=i+1;j<=n-1;j++){
      for(int k=j+1;k<=n;k++){
        if( j-i == k-j ) continue;
        if( s.at(i) != s.at(j) && s.at(i) != s.at(k) && s.at(j) != s.at(k) ){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}