#include<bits/stdc++.h>
using namespace std;

int ans = 0;
int n;
string x;

void solve(string form)
{
    int p[n], cnt = 0;
    memset(p, 0, sizeof p);
    char c = form[2];
    for (int i = n - 1; i >= 0; i--) {
        if (c == x[i]) p[i] = ++cnt;
    }
    int re = 0;
    for (int i = 1; i <= n - 1; i++) {
        for (int j = 0; j < n; j++) {
            if (!(j + i < n)) break;


            if (x[j] == form[0] && x[j + i] == form[1]) {
                bool ok = false;
                if (j + 2 * i < n && x[j + 2 * i] == form[2]) {
                    ok = true;
                }
                int nxt = -1;
                for (int k = j + i + 1; k < n; k++) {
                    if (x[k] == form[2]) {
                        nxt = k;
                        break;
                    }
                }
                if (nxt == -1) break;
                else {
                    re += p[nxt];
                    if (ok) re--;
                }
            }
        }
    }
    ans += re;
}

int main()
{
    cin >> n >> x;
    solve("RGB");
    solve("BGR");
    solve("BRG");
    solve("GBR");
    solve("GRB");
    solve("RBG");
    cout << ans << "\n";
}
