#include<stdio.h>
int main(void){
  int n,i,j,k,flag=0;
  scanf("%d",&n);
  char s[n];
  scanf("%s",&s);
  long ans=0;
  for(i=0;i<n-3;i++){
    for(j=i+1;j<n-2;j++){
      while(s[i]==s[j]){
  	j++;
		}
		k=j+1;
         while(k<n){//33
           if(flag){
             k++;
             flag=0;
           }
      while(k<n){//22
           if(s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k]){//11
             flag=1;
            // printf("%d %d %d\n",i,j,k);
          if(k-j!=j-i)ans++;
              break;
            }//11
            k++;
          }//22
         }//33
       
    }
  }
    
  printf("%ld",ans);
  return 0;
}