#include<stdio.h>
/*int calc(int x,int y,int z){
int xyz[3];
  xyz[0]=x;
  xyz[1]=y;
  xyz[2]=z;
 int max=x;
 int min=x;
  int maxind=0;
  int minind=0;
  for(int i=1;i<=2;i++){
    if(xyz[i]>max){
      max=xyz[i];
      maxind=i;
    }
    if(xyz[i]<min){
      min=xyz[i];
      minind=i;
    }
  }
  printf("%d %d\n",maxind,minind);
    int m=3-maxind-minind;
    return (xyz[maxind]-xyz[m])-(xyz[m]-xyz[minind]);
  }*/
    int calc(int x,int y,int z){
if(x>=y&&y>=z)return x-2*y+z;
if(x>=z&&z>=y)return x-2*z+y;
if(y>=x&&x>=z)return y-2*x+z;
if(y>=z&&z>=x)return y-2*z+x;
if(z>=x&&x>=y)return z-2*x+y;
if(z>=y&&y>=x)return z-2*y+x;
    }

int main(void){
  int n;
  scanf("%d",&n);
  char s[n];
  scanf("%s",&s);
  int r[n],g[n],b[n];
  for(int i=0;i<n;i++){
	r[i]=0;
    g[i]=0;
    b[i]=0;
  }
  int rc=0,gc=0,bc=0;
  for(int i=0;i<n;i++){
	if(s[i]=='R')r[rc++]=i;
    if(s[i]=='G')g[gc++]=i;
    if(s[i]=='B')b[bc++]=i;
  }
  if(rc==0||gc==0||bc==0)return 0;
  long long ans=0;
for(int i=0;i<rc;i++){
  //int max=r[i];
  //int min=r[i];
for(int j=0;j<gc;j++){
  //if(g[j]>max)max=g[j];
  //if(g[j]<min)min=g[j];
  for(int k=0;k<bc;k++){
    //if(b[k]>max)max=b[k];
    //if(b[k]<min)min=b[k];
    //int mid=r[i]+g[j]+b[k]-max-min;
    //printf("%d %d %d\n",r[i],g[j],b[k]);
    if(calc(r[i],g[j],b[k])!=0){
      ans++;
      //printf("clear\n");
      //printf("%d\n",calc(r[i],g[j],b[k]));
    }
    //if(max-mid!=mid-min)ans++;
  }
}
}
  printf("%lld",ans);
  return 0;
}