#include<iostream>
#include<vector>
using namespace std;

int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;
  int c=0;

  for(int i=0;i<N-2;i++){
    for(int j=i+1;j<N-1;j++){
      if(S[i]!=S[j]){
        for(int k=j+1;k<N;k++){
          if(j-i!=k-j){
            if(S[i]!=S[k] && S[j]!=S[k]){
              c = c+1;
              //cout<<i<<" "<<j<<" "<<k<<" = "<<S[i]<<" "<<S[j]<<" "<<S[k]<<endl;
            }
          }
        }
      }
    }
  }
  cout<<c<<endl;

}