#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ll long long int

int main(){
  ll n;
  scanf("%lld",&n);
  char s[4001];
  scanf("%s",s);

  ll ans=0;

  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
	if(s[i]==s[j] || s[j]==s[k] || s[k]==s[i]){
	  continue;}
	if((j-i)==(k-j)) continue;
	//printf("%d %d %d\n",i,j,k);
	ans++;
      }}}

  printf("%lld\n",ans);
  
  return 0;
}
