#include <stdio.h>

long count(int x[], int nx, int y[], int ny, int z[], int nz) {
   int i,j,k,jj,kk;
   long a;

   a=jj=0;
   for (i=0;i<nx;i++) {
       for (j=jj;j<ny;j++)
          if (y[j]>x[i]) break;
       if (j==ny) continue;
       jj=j;kk=0;
       for (;j<ny;j++) {
          for (k=kk;k<nz;k++)
             if (z[k]>y[j]) break;
          if (k==nz) continue;
          kk=k;
          for (;k<nz;k++)
              if (y[j]-x[i]!=z[k]-y[j]) a++;
       }
   }
   return a;
}

int main(){
   int i,n,r[4000],g[4000],b[4000],rp,gp,bp;
   char s[4001];
   long sum;

   scanf("%d",&n);
   scanf("%s",s);
   rp=gp=bp=0;
   for (i=0;i<n;i++)
      if (s[i]=='R') r[rp++]=i;
      else if (s[i]=='G') g[gp++]=i;
      else b[bp++]=i;
   sum=count(r,rp,g,gp,b,bp);
   sum+=count(r,rp,b,bp,g,gp);
   sum+=count(g,gp,r,rp,b,bp);
   sum+=count(g,gp,b,bp,r,rp);
   sum+=count(b,bp,g,gp,r,rp);
   sum+=count(b,bp,r,rp,g,gp);
   printf("%ld\n",sum);
   return 0;
}
