import std;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto S = sread();
    auto sum = new long[][](3, N + 1);
    foreach (i; 0 .. N)
    {
        switch (S[i])
        {
        case 'R':
            sum[0][i + 1] = 1;
            break;
        case 'G':
            sum[1][i + 1] = 1;
            break;
        case 'B':
            sum[2][i + 1] = 1;
            break;
        default:
            assert(0);
        }
    }
    foreach (i; 0 .. 3)
        foreach (j; 0 .. N)
        {
            sum[i][j + 1] += sum[i][j];
        }
    long[] idx = [0, 1, 2];
    long ans;
    do
    {
        foreach (i; 0 .. N)
        {
            if (S[i] == "RGB"[idx[0]])
                foreach (j; i + 1 .. N)
                {
                    if (S[j] == "RGB"[idx[1]])
                    {
                        ans += sum[idx[2]][$ - 1] - sum[idx[2]][j + 1];
                        // writefln("%s %s %s", i, j, sum[$ - 1] - sum[j + 1]);
                        if (j + (j - i) < N && S[j + (j - i)] == "RGB"[idx[2]])
                        {
                            // writefln("%s %s %s", i, j, j + (j - i));
                            ans--;
                        }
                    }
                }
        }
    }
    while (nextPermutation(idx));
    writeln(ans);
}
