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

int main()
{
    int N;
    scanf("%d", &N);
    char S[N];
    scanf("%s", S);
    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++;
        }
    }
    long sum = R * G * B;
    for (int r = 0; r < R; r++)
    {
        for (int g = 0; g < G; g++)
        {
            if (Rind[r] < Gind[g])
            {
                if ((Rind[r] + Gind[g]) % 2 == 0 && S[(Rind[r] + Gind[g]) / 2] == 'B')
                {
                    sum--;
                }
                if (2 * Gind[g] - Rind[r] < N && S[2 * Gind[g] - Rind[r]] == 'B')
                {
                    sum--;
                }
                if (2 * Rind[r] - Gind[g] >= 0 && S[2 * Rind[r] - Gind[g]] == 'B')
                {
                    sum--;
                }
            }
            else
            {
                if ((Rind[r] + Gind[g]) % 2 == 0 && S[(Rind[r] + Gind[g]) / 2] == 'B')
                {
                    sum--;
                }
                if (2 * Rind[r] - Gind[g] < N && S[2 * Rind[r] - Gind[g]] == 'B')
                {
                    sum--;
                }
                if (2 * Gind[g] - Rind[r] >= 0 && S[2 * Gind[g] - Rind[r]] == 'B')
                {
                    sum--;
                }
            }
        }
    }
    printf("%ld\n", sum);
}
