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;
    }
    auto rgb_rbt = ['R' : redBlackTree(rgb['R']), 'G' : redBlackTree(rgb['G']), 'B' : redBlackTree(rgb['B'])];
    
    size_t ans;
    
    foreach (i; 0 .. N-1) {
        if (S[i] == 'R') {
            auto upb_G = rgb_rbt['G'].upperBound(i);
            auto upb_B = rgb_rbt['B'].upperBound(i);
            
            foreach (j; upb_G) {
                auto upb_B2 = rgb_rbt['B'].upperBound(j);
                if (upb_B2.canFind(2*j - i)) ans += upb_B2.array.length-1;
                else ans += upb_B2.array.length;
            }
            foreach (j; upb_B) {
                auto upb_G2 = rgb_rbt['G'].upperBound(j);
                if (upb_G2.canFind(2*j - i)) ans += upb_G2.array.length-1;
                else ans += upb_G2.array.length;
            }
        }
        
        if (S[i] == 'G') {
            auto upb_R = rgb_rbt['R'].upperBound(i);
            auto upb_B = rgb_rbt['B'].upperBound(i);
            
            foreach (j; upb_R) {
                auto upb_B2 = rgb_rbt['B'].upperBound(j);
                if (upb_B2.canFind(2*j - i)) ans += upb_B2.array.length-1;
                else ans += upb_B2.array.length;
            }
            foreach (j; upb_B) {
                auto upb_R2 = rgb_rbt['R'].upperBound(j);
                if (upb_R2.canFind(2*j - i)) ans += upb_R2.array.length-1;
                else ans += upb_R2.array.length;
            }
        }
        
        if (S[i] == 'B') {
            auto upb_R = rgb_rbt['R'].upperBound(i);
            auto upb_G = rgb_rbt['G'].upperBound(i);
            
            foreach (j; upb_R) {
                auto upb_G2 = rgb_rbt['G'].upperBound(j);
                if (upb_G2.canFind(2*j - i)) ans += upb_G2.array.length-1;
                else ans += upb_G2.array.length;
            }
            foreach (j; upb_G) {
                auto upb_R2 = rgb_rbt['R'].upperBound(j);
                if (upb_R2.canFind(2*j - i)) ans += upb_R2.array.length-1;
                else ans += upb_R2.array.length;
            }
        }
    }
    
    writeln(ans);
}