
#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(j) != S.at(k) && S.at(k) != S.at(i) && j-i != k-j)
        count ++;
    }
   }
  }
  cout << count << endl;
  
}