#include <stdio.h>

int main()
{
    int n;
    char s[4001];
    int rgb_buc[3][4001] = {0},rgb[] = {'R','G','B'};
    scanf("%d %s",&n,s);

    int i,j,k;
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < 3; j++)
        {
            if(rgb[j] == s[i]){rgb_buc[j][i + 1] = 1;break;}
        }
    }

    for (i = 0; i < n; i++)
    {
        for (j = 0; j < 3; j++)
        {
            rgb_buc[j][i + 1] += rgb_buc[j][i];
        }
    }

    long long ans = 0,buf = 0;
    char ii,jj;
    for (i = 0; i < n; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            if(s[i] == s[j])continue;
            for (k = 0; k < 3; k++)
            {
                if(rgb[k] == (int)'R' + 'G' + 'B' - s[i] - s[j])break;
            }
            
            buf = rgb_buc[k][n] - rgb_buc[k][j + 1];
            if(buf != 0 && (int)s[2 * j - i] == (int)'R' + 'G' + 'B' - s[i] - s[j])buf--;
            
            ans += buf;
        }
    }
    printf("%lld",ans);
}

//'R' + 'G' + 'B'