import std;

// 累積和による解法
long calc(string s) {
    int n = cast(int)s.length;

    auto acc = new int[][](3, n);
    foreach (i; 0..n) {
        acc[0][i] = (s[i] == 'R') + (i > 0 ? acc[0][i-1] : 0);
        acc[1][i] = (s[i] == 'G') + (i > 0 ? acc[1][i-1] : 0);
        acc[2][i] = (s[i] == 'B') + (i > 0 ? acc[2][i-1] : 0);
    }

    // "RGB" の使っていない文字
    int get(char a, char b) {
        foreach (i, c; "RGB") {
            if (c != a && c != b) return cast(int)i;
        }
        assert(false);
    }

    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;

            int p = get(s[i], s[j]);
            ans += acc[p][$-1] - acc[p][j-1];
            int k = 2*j - i;
            if (k < n && s[k] == "RGB"[p]) ans--;
        }
    }
    return ans;
}

// 全体から j-i == k-j が一致するものを引く
long calc2(string s) {
    int n = cast(int)s.length;

    long r = 0, g = 0, b = 0;
    foreach (c; s) {
        if (c == 'R') r++;
        if (c == 'G') g++;
        if (c == 'B') b++;
    }
    int x = 0;
    foreach (i; 0..n) {
        foreach (j; i+1..n) {
            if (s[i] == s[j]) continue;
            int k = 2*j - i;
            if (k >= n || s[i] == s[k] || s[j] == s[k]) continue;
            x++; // j-i == k-j and i, j, k の文字が全て異なる
        }
    }
    return r * g * b - x;
}

void main() {
    readint;
    string s = read!string;
    writeln(calc2(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;
