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

typedef long long ll;
typedef long double ld;

const int inf = 1e9;

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  ll t = 0;
  for(int i = 0; i < n ; ++i){
    for(int j = i + 1; j < n; ++j){
      for(int k = j + 1; k < n; ++k){
	//int y = n - i + 1;
	//int r = n - j + 1;
	//int p = n - k + 1;
	if(s[i] != s[j] && s[i] != s[k] && s[j] != s[k] && j - i != k - j)t++;
	//if(s[y] != s[r] && s[y] != s[p] && s[r] != s[p] && y - r != r - p)t++;
      }	   
    }
  }
  cout<<t<<endl;
  return 0;
}


