import std;

char get(char a, char b) {
    foreach (c; "RGB") {
        if (c != a && c != b) return c;
    }
    assert(false);
}

long calc(string s) {
    int n = cast(int)s.length;

    auto r = new int[n];
    auto g = new int[n];
    auto b = new int[n];
    if (s[0] == 'R') r[0] = 1;
    if (s[0] == 'G') g[0] = 1;
    if (s[0] == 'B') b[0] = 1;
    foreach (i; 1..n) {
        r[i] = r[i-1] + (s[i] == 'R');
        g[i] = g[i-1] + (s[i] == 'G');
        b[i] = b[i-1] + (s[i] == 'B');
    }

    long ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            if (s[i] == s[j]) continue;

            char c = get(s[i], s[j]);
            // writeln("i ", i, " j ", j, " ", c);
            int step = j - i;
            if (c == 'R') {
                ans += r[$-1] - r[j-1];
                if (j + step < n && s[j + step] == 'R') ans--;
            }
            if (c == 'G') {
                ans += g[$-1] - g[j-1];
                if (j + step < n && s[j + step] == 'G') ans--;
            }
            if (c == 'B') {
                ans += b[$-1] - b[j-1];
                if (j + step < n && s[j + step] == 'B') ans--;
            }
        }
    }
    return ans;

}

void main() {
    readint;
    string s = read!string;
    writeln(calc(s));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
