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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<lint> R(N + 1, 0), G(N + 1, 0), B(N + 1, 0);
    map<char, vector<lint>> mp;
    mp['R'] = vector<lint>(N + 1, 0);
    mp['G'] = vector<lint>(N + 1, 0);
    mp['B'] = vector<lint>(N + 1, 0);
    for (int i = N; 0 < i; i--) {
        // mp[S[i - 1]][i - 1] = mp[S[i - 1]][i] + 1;
        mp['R'][i - 1] = mp['R'][i];
        mp['G'][i - 1] = mp['G'][i];
        mp['B'][i - 1] = mp['B'][i];
        mp[S[i - 1]][i - 1]++;
    }
    // d(S);
    // dump(mp['R']);
    // dump(mp['G']);
    // dump(mp['B']);
    lint ans = 0;
    set<char> se{'R', 'G', 'B'};
    for (int i = 0; i <= N - 3; i++) {
        for (int j = i + 1; j <= N - 2; j++) {
            char c1 = S[i], c2 = S[j];
            int r = j - i;
            // dd(i, j);
            set<char> cp = se;
            if (cp.count(c1) == 1) { cp.erase(c1); }
            if (cp.count(c2) == 1) { cp.erase(c2); }
            if (cp.size() != 1) { continue; }
            char c3 = *cp.begin();
            ans += mp[c3][j + 1];
            if (S[j + r] == c3) ans--;
        }
    }
    // d(ans);
    cout << ans << endl;
    return 0;
}