#include<stdio.h>
int main(){
  long long i,j,k,n,l,ans=0,b[3][10010]={};
  char s[10010],c[]={"RGB"};
  scanf("%lld %s",&n,s);
  for(i=0;i<n;i++){
    for(j=0;j<3;j++)b[j][i+1]=b[j][i];
    for(j=0;s[i]-c[j];j++);
    b[j][i+1]++;
  }
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      if(s[i]==s[j])continue;//printf("%d %d %d\n",i,j,i-(j-i));
      k=(int)'R'+'G'+'B'-s[i]-s[j];
      for(l=0;c[l]-k;l++);
      ans+=b[l][i];
      if(i-(j-i)>=0&&s[i-(j-i)]==c[l])ans--;
    }
  }
  printf("%lld\n",ans);
  return 0;
}
	
