import std;

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

    size_t ans = count(S, 'R') * count(S, 'G') * count(S, 'B');

    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);
}
