import std.conv, std.stdio;
import std.algorithm, std.array, std.range, std.string;
void main()
{
    immutable n = readln.chomp.to!size_t, s = readln.chomp;
    auto count = ['R': long(0), 'G': 0, 'B': 0];
    foreach (l; s)
        count[l] += 1;
    auto answer = count['R'] * count['G'] * count['B'];
    foreach (i; 0..s.length)
        foreach (k; i+2..s.length)
        {
            if ((i ^ k) & 1) continue;
            immutable j = (i + k) >> 1;
            if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i])
                answer -= 1;
        }
    answer.writeln;
}
