import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y", long, "cost");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto s = sread(), c = "RGB";
    long color = 3, count;
    auto pair = new long[][](n + 1, color);
    foreach(i; iota(n))
    {
        foreach (j; iota(color))
        {
            pair[i + 1][j] = pair[i][j] + (s[i] == c[j]);
        }
    }

    foreach (i; iota(n - 2))
    {
        foreach (j; iota(i + 1, n - 1))
        {
            if(s[i] == s[j])
                continue;


            auto tmp = color.iota.sum() - c.countUntil(s[i]) - c.countUntil(s[j]);
            count += pair[n][tmp] - pair[j + 1][tmp];
            if(j + (j - i) < n && c[tmp] == s[j + (j - i)])
                count--;
        }
    }
    count.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}
