import std;

void main()
{
    const N = readln().chomp().to!uint();
    const S = readln().chomp();

    auto temp = S.fold!("a + (b == 'R')", "a + (b == 'G')", "a + (b == 'B')")(tuple(0, 0, 0));
    size_t ans = temp[0] * temp[1] * temp[2];

    foreach (uint i; 0 .. N)
    foreach (uint j; i + 1 .. N)
    {
        if (S[i] == S[j]) continue;
        const k = 2 * j - i;
        if (k >= N) continue;
        if (S[j] == S[k] || S[i] == S[k]) continue;
        --ans;
    }

    writeln(ans);
}
