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

int compare_int(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}

int main()
{
    int N;
    scanf("%d", &N);
    char S[N];
    scanf("%s", S);
    long sum = 0;
    int R = 0;
    int G = 0;
    int B = 0;
    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'R')
        {
            R++;
        }
        else if (S[i] == 'G')
        {
            G++;
        }
        else
        {
            B++;
        }
    }
    int Rind[R];
    int Gind[G];
    int Bind[B];
    int Rtmp = 0;
    int Gtmp = 0;
    int Btmp = 0;
    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'R')
        {
            Rind[Rtmp] = i;
            Rtmp++;
        }
        else if (S[i] == 'G')
        {
            Gind[Gtmp] = i;
            Gtmp++;
        }
        else
        {
            Bind[Btmp] = i;
            Btmp++;
        }
    }
    for (int r = 0; r < R; r++)
    {
        for (int g = 0; g < G; g++)
        {
            for (int b = 0; b < B; b++)
            {
                int tmp[] = {Rind[r], Gind[g], Bind[b]};
                qsort(tmp, 3, sizeof(int), compare_int);
                if (tmp[2] - tmp[1] != tmp[1] - tmp[0])
                {
                    sum++;
                }
            }
        }
    }
    printf("%ld\n", sum);
}
