#include <bits/stdc++.h>
#define ll long long
using namespace std;

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