#include<stdio.h>
int main()

{
    int n,i,j,k,x=0,y=0,z=0,t=0,p=0,q=0,r=0,small,big;

    scanf("%d",&n);
    char ch[n+1];
    scanf("%s",ch);
    int a[n],b[n],c[n];
    for(i=0; ch[i]; i++)
    {
        if     (ch[i]=='R'){a[p]=i+1;x++;p++;}
        else if(ch[i]=='B'){b[q]=i+1;y++;q++;}
        else if(ch[i]=='G'){c[r]=i+1;z++;r++;}

    }

    for(i=0; i<x; i++)
    {
        for(j=0; j<y; j++)
        {
            for(k=0; k<z; k++)
            {
                big=a[i];
                if(b[j]>a[i])big=b[j];
                if(c[k]>big)big=c[k];
                small=a[i];
                if(b[j]<a[i])small=b[j];
                if(c[k]<small)small=c[k];
                int mid;
                if(a[i]>small && a[i]<big)mid=a[i];
                if(b[j]>small && b[j]<big)mid=b[j];
                if(c[k]>small && c[k]<big)mid=c[k];
                if((big-mid)!=(mid-small)){t++;}
            }
        }
    }

    printf("%d\n",t);
    return 0;


}

