#include <stdio.h>

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

   a=jj=kk=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;
       for (k=kk;k<nz;k++)
          if (z[k]>x[i]) break;
       if (k==nz) continue;
       kk=k;
       for (;j<ny && k<nz;)
          if (y[j]<z[k]) {
             for (l=k;l<nz;l++)
                if (y[j]-x[i]!=z[l]-y[j]) a++;
             j++;
          } else {
             for (l=j;l<ny;l++)
                if (z[k]-x[i]!=y[l]-z[k]) a++;
             k++;
          }
   }
   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(g,gp,r,rp,b,bp);
   sum+=count(b,bp,g,gp,r,rp);
   printf("%ld\n",sum);
   return 0;
}
