import std;

void main() {
    readln;
    auto S = readln.split[0].to!string;
    auto N = S.length;
    
    size_t[][char] rgb;
    rgb['R'] = [], rgb['G'] = [], rgb['B'] = [];
    foreach (n, c; S) {
        rgb[c] ~= n;
    }
    
    size_t ans;
    
    ans += rgb['R'].length * rgb['G'].length * rgb['B'].length;
    // j - i = k - j
    foreach (i; 0 .. N-2) {
        foreach (k; iota(i+2, N, 2)) {
            auto j = (k+i)/2;
            bool[char] set;
            set[S[i]] = true; set[S[j]] = true; set[S[k]] = true;
            if (set.keys.length == 3) ans--;
        }
    }
    
    writeln(ans);
}