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

int main () {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  int sum = 0;
   for (int i = 0; i < N; i++) {
     for (int j = i+1; j < N; j++) {
       for (int k = j+1; j < N; k++) {
         if ((S.at(i) != S.at(j)) && (S.at(i) != S.at(k)) && (S.at(k) != S.at(j)) &&
            (k-j != j-i))
           sum++;
       }
     }
   }
  cout << sum << endl;
  
}