#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>

int countR_l(int n,char s[])
{
  int count=0;
  int i;
  for(i=0;i<n;i++){
    if(s[i]=='R')
      count++;
  }
  return count;
}

int countG_l(int n,char s[])
{
  int count=0;
  int i;
  for(i=0;i<n;i++){
    if(s[i]=='G')
      count++;
  }
  return count;
}

int countB_l(int n,char s[])
{
  int count=0;
  int i;
  for(i=0;i<n;i++){
    if(s[i]=='B')
      count++;
  }
  return count;
}

int countR_r(int n,char s[],int m)
{
  int count=0;
  int i;
  for(i=n+1;i<m;i++){
    if(s[i]=='R')
      count++;
  }
  return count;
}

int countG_r(int n,char s[],int m)
{
  int count=0;
  int i;
  for(i=n+1;i<m;i++){
    if(s[i]=='G')
      count++;
  }
  return count;
}

int countB_r(int n,char s[],int m)
{
  int count=0;
  int i;
  for(i=n+1;i<m;i++){
    if(s[i]=='B')
      count++;
  }
  return count;
}

int countB_G(int n,char s[],int m)
{
  int count=0;
  int i=1;
  while(n-i!=-1 && n+i!=m){
      if((s[n-i]=='B'&&s[n+i]=='G')||(s[n-i]=='G'&&s[n+i]=='B'))
        count++;
      i++;
  }
  return count;
}

int countR_G(int n,char s[],int m)
{
  int count=0;
  int i=1;
  while(n-i!=-1 && n+i!=m){
      if((s[n-i]=='R'&&s[n+i]=='G')||(s[n-i]=='G'&&s[n+i]=='R'))
        count++;
      i++;
  }
  return count;
}

int countR_B(int n,char s[],int m)
{
  int count=0;
  int i=1;
  while(n-i!=-1 && n+i!=m){
      if((s[n-i]=='B'&&s[n+i]=='R')||(s[n-i]=='R'&&s[n+i]=='B'))
        count++;
      i++;
  }
  return count;
}

int main(void)
{
  int i,n;
  long int ans=0;
  char s[4001];
  scanf("%d%s",&n,s);

  if(n<=3){
    printf("0");
    return 0;
  }

  for(i=1;i<n-1;i++){
    if(s[i]=='R'){
      ans+=countB_l(i,s)*countG_r(i,s,n);
      ans+=countG_l(i,s)*countB_r(i,s,n);
      ans-=countB_G(i,s,n);
/*      printf("R ans%d=%d\n",i,ans);*/
    }
    if(s[i]=='G'){
      ans+=countB_l(i,s)*countR_r(i,s,n);
      ans+=countR_l(i,s)*countB_r(i,s,n);
/*      printf("countB_l=%d  countR_r=%d countR_l=%d  countB_r=%d\n",countB_l(i,s),countR_r(i,s,n),countR_l(i,s),countB_r(i,s,n));
*/      ans-=countR_B(i,s,n);
/*      printf("G ans%d=%d\n",i,ans);*/
    }
    if(s[i]=='B'){
      ans+=countR_l(i,s)*countG_r(i,s,n);
      ans+=countG_l(i,s)*countR_r(i,s,n);
      ans-=countR_G(i,s,n);
/*      printf("B ans%d=%d\n",i,ans);*/
    }
  }
  printf("%ld",ans);
  return 0;

}
