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

int main(){
  int N;
  cin >> N ;
  
  string s;
  cin >> s;
  
  int count = 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((s.at(i) != s.at(j))&&(s.at(i) != s.at(k))&&(s.at(j) != s.at(k))){
              if(j-i != k-j) count++;
        }
      }
    }
  }
         
  cout << count << endl;
}
        
  