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

int main()
{
    int N, Ra[40005], Ga[40005], Ba[40005], i, j;
    long long int sum=0;
    char S[40005];
    scanf("%d", &N);
    scanf(" %s ", S);
    if(S[N-1]=='R')
    {
        Ra[N-1]=1;
        Ga[N-1]=0;
        Ba[N-1]=0;
    }
    else if(S[N-1]=='G')
    {
        Ra[N-1]=0;
        Ga[N-1]=1;
        Ba[N-1]=0;
    }
    else
    {
        Ra[N-1]=0;
        Ga[N-1]=0;
        Ba[N-1]=1;
    }
    for(i=N-2;i>=0;i=i-1)
    {
        if(S[i]=='R')
        {
            Ra[i]=Ra[i+1]+1;
            Ga[i]=Ga[i+1];
            Ba[i]=Ba[i+1];
        }
        else if(S[i]=='G')
        {
            Ra[i]=Ra[i+1];
            Ga[i]=Ga[i+1]+1;
            Ba[i]=Ba[i+1];
        }
        else
        {
            Ra[i]=Ra[i+1];
            Ga[i]=Ga[i+1];
            Ba[i]=Ba[i+1]+1;
        }
    }
    for(i=0;i<N;i=i+1)
    {
        for(j=i+1;j<N;j=j+1)
        {
            if(S[i]==S[j])
            {
                continue;
            }
            if((S[i]=='R' && S[j]=='G') || (S[i]=='G' && S[j]=='R'))
            {
                sum = sum + Ba[j];
                if(2*j-i<=N-1 && S[2*j-i]=='B')
                {
                    sum=sum-1;
                }
            }
            else if((S[i]=='R' && S[j]=='B') || (S[i]=='B' && S[j]=='R'))
            {
                sum = sum + Ga[j];
                if(2*j-i<=N-1 && S[2*j-i]=='G')
                {
                    sum=sum-1;
                }
            }
            else if((S[i]=='G' && S[j]=='B') || (S[i]=='B' && S[j]=='G'))
            {
                sum = sum + Ra[j];
                if(2*j-i<=N-1 && S[2*j-i]=='R')
                {
                    sum=sum-1;
                }
            }
        }
    }
    printf("%lld\n", sum);
}