#include <iostream>
using namespace std;


int main(){
  int N;
  string S;
  cin >> N >> S;
  long long int ans = 0;
  for(int ii=0; ii<N; ii++){
    for(int jj=ii+1; jj<N; jj++){
      for(int kk=jj+1; kk<N; kk++){
        if(S[ii]==S[jj] || S[ii]==S[kk] || S[jj]==S[kk]) continue;
        if(jj-ii==kk-jj) continue;
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
