#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N;
    string S;
    cin >> N >> S;
    VL R, G, B;
    rep(i, 0, N){
        if(S[i] == 'R') R.push_back(i);
        if(S[i] == 'G') G.push_back(i);
        if(S[i] == 'B') B.push_back(i);
    }
    ll ans = 0;
    // i = R
    rep(i, 0, R.size()){
        {
            // j = G
            auto gmax = upper_bound(ALL(G), R[i]);
            if(gmax != G.end()){
                auto gpos = distance(G.begin(), gmax);
                rep(j, gpos, G.size()){
                    auto bmax = upper_bound(ALL(B), G[j]);
                    auto bpos = distance(B.begin(), bmax);
                    //cerr << i << "," << j << endl;
                    ans += B.size() - bpos;
                    if(2 * G[j] - R[i] < N){
                        if(S[2 * G[j] - R[i]] == 'B') ans--;
                    }
                }
            }
            //cerr << ans << endl;
        }
        {
            // j = B
            auto bmax = upper_bound(ALL(B), R[i]);
            if(bmax != B.end()){
                auto bpos = distance(B.begin(), bmax);
                rep(j, bpos, B.size()){
                    auto gmax = upper_bound(ALL(G), B[j]);
                    auto gpos = distance(G.begin(), gmax);
                    ans += G.size() - gpos;
                    if(2 * B[j] - R[i] < N){
                        if(S[2 * B[j] - R[i]] == 'G') ans--;
                    }
                }
            }
        }
    }

    // i = G
    rep(i, 0, G.size()){
        {
            // j = R
            auto rmax = upper_bound(ALL(R), G[i]);
            if(rmax != R.end()){
                auto rpos = distance(R.begin(), rmax);
                rep(j, rpos, R.size()){
                    auto bmax = upper_bound(ALL(B), R[j]);
                    auto bpos = distance(B.begin(), bmax);
                    //cerr << i << "," << j << endl;
                    ans += B.size() - bpos;
                    if(2 * R[j] - G[i] < N){
                        if(S[2 * R[j] - G[i]] == 'B') ans--;
                    }
                }
            }
            //cerr << ans << endl;
        }
        {
            // j = B
            auto bmax = upper_bound(ALL(B), G[i]);
            if(bmax != B.end()){
                auto bpos = distance(B.begin(), bmax);
                rep(j, bpos, B.size()){
                    auto rmax = upper_bound(ALL(R), B[j]);
                    auto rpos = distance(R.begin(), rmax);
                    ans += R.size() - rpos;
                    if(2 * B[j] - G[i] < N){
                        if(S[2 * B[j] - G[i]] == 'R') ans--;
                    }
                }
            }
        }
    }

    // i = B
    rep(i, 0, B.size()){
        {
            // j = R
            auto rmax = upper_bound(ALL(R), B[i]);
            if(rmax != R.end()){
                auto rpos = distance(R.begin(), rmax);
                rep(j, rpos, R.size()){
                    auto gmax = upper_bound(ALL(G), R[j]);
                    auto gpos = distance(G.begin(), gmax);
                    //cerr << i << "," << j << endl;
                    ans += G.size() - gpos;
                    if(2 * R[j] - B[i] < N){
                        if(S[2 * R[j] - B[i]] == 'G') ans--;
                    }
                }
            }
            //cerr << ans << endl;
        }
        {
            // j = G
            auto gmax = upper_bound(ALL(G), B[i]);
            if(gmax != G.end()){
                auto gpos = distance(G.begin(), gmax);
                rep(j, gpos, G.size()){
                    auto rmax = upper_bound(ALL(R), G[j]);
                    auto rpos = distance(R.begin(), rmax);
                    ans += R.size() - rpos;
                    if(2 * G[j] - B[i] < N){
                        if(S[2 * G[j] - B[i]] == 'R') ans--;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3668