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

int main() {
    int N; cin >> N;
    string S; cin >> S;
    vector<int> r, g, b;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'R') r.push_back(i);
        else if (S[i] == 'G') g.push_back(i);
        else if (S[i] == 'B') b.push_back(i);
    }
    //vec[i]はポインタがi以上のbの要素の数
    vector<int> vecR(N), vecG(N), vecB(N);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < b.size(); j++) {
            if (b[j] >= i) vecB[i]++;
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < g.size(); j++) {
            if (g[j] >= i) vecG[i]++;
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < r.size(); j++) {
            if (r[j] >= i) vecR[i]++;
        }
    }


    ll cnt = 0;
    for (int i = 0; i < r.size(); i++) {
        for (int j = 0; j < g.size(); j++) {
            if (g[j] <= r[i]) continue;
            ll val = g[j]-r[i];
            cnt += vecB[g[j]+1];
            if (S[g[j]+val] == 'B') {
                cnt --;
            } 
        }
    }
    for (int i = 0; i < r.size(); i++) {
        for (int j = 0; j < b.size(); j++) {
            if (b[j] <= r[i]) continue;
            ll val = b[j]-r[i];
            cnt += vecG[b[j]+1];
            if (S[b[j]+val] == 'G') {
                cnt --;
            } 
        }
    }
    for (int i = 0; i < g.size(); i++) {
        for (int j = 0; j < r.size(); j++) {
            if (r[j] <= g[i]) continue;
            ll val = r[j]-g[i];
            cnt += vecB[r[j]+1];
            if (S[r[j]+val] == 'B') {
                cnt --;
            } 
        }
    }
    for (int i = 0; i < g.size(); i++) {
        for (int j = 0; j < b.size(); j++) {
            if (b[j] <= g[i]) continue;
            ll val = b[j]-g[i];
            cnt += vecR[b[j]+1];
            if (S[b[j]+val] == 'R') {
                cnt --;
            } 
        }
    }
    for (int i = 0; i < b.size(); i++) {
        for (int j = 0; j < r.size(); j++) {
            if (r[j] <= b[i]) continue;
            ll val = r[j]-b[i];
            cnt += vecG[r[j]+1];
            if (S[r[j]+val] == 'G') {
                cnt --;
            } 
        }
    }
    for (int i = 0; i < b.size(); i++) {
        for (int j = 0; j < g.size(); j++) {
            if (g[j] <= b[i]) continue;
            ll val = g[j]-b[i];
            cnt += vecR[g[j]+1];
            if (S[g[j]+val] == 'R') {
                cnt --;
            } 
        }
    }
    cout << cnt << endl;
}