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

int main() {
    //
    int num;
    string str;
    long long cnt = 0;
    long long all = 0;

    cin >> num >> str;
    vector<int> r;
    vector<int> g;
    vector<int> b;

    for (int i = 0; i < num; i++) {
        if (str.at(i) == 'R')
            r.push_back(i);
        else if (str.at(i) == 'G')
            g.push_back(i);
        else if (str.at(i) == 'B')
            b.push_back(i);
    }

    all = r.size() * g.size() * b.size();
    for (int i = 0; i < num; i++) {
        for (int j = i+1; j < num; j++) {
            long long k = j * 2 - i;

            if (k >= num || str.at(i) == str.at(j)) continue;
            if (str.at(k) == str.at(i) || str.at(k) == str.at(j)) continue;
            all--;
            /*
            for (int k = 0; k < b.size(); k++) {
                if (g.at(j) - r.at(i) == b.at(k) - g.at(j)) continue;
                if (b.at(k) - g.at(j) == r.at(i) - b.at(k)) continue;
                if (r.at(i) - b.at(k) == g.at(j) - r.at(i)) continue;
                cnt++;
            }
            */
        }
    }

    cout << all;
    //
}

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

int main() {
    int n;
    cin >> n;
    vector<int> r,g,b;

    for(int i = 0; i < n; i++) {
        char x;
        cin >> x;
        if(x=='R') r.push_back(i+1);
        if(x=='G') g.push_back(i+1);
        if(x=='B') b.push_back(i+1);
    }

    ll ans = r.size()*g.size()*b.size();
    if(ans==0){
        cout << 0 << endl;
        return 0;
    }

    for(int i = 0; i < r.size(); i++) {
        for(int j = 0; j < g.size(); j++) {
            int y=lower_bound(b.begin(),b.end(),g[j]+g[j]-r[i])-b.begin();
            if(y!=b.size()){
                if(b[y]==g[j]+g[j]-r[i]) ans--;
            }
            y=lower_bound(b.begin(),b.end(),r[i]+r[i]-g[j])-b.begin();
            if(y!=b.size()){
                if(b[y]==r[i]+r[i]-g[j]) ans--;
            }

            if((r[i]+g[j])%2==0){
                y=lower_bound(b.begin(),b.end(),(r[i]+g[j])/2)-b.begin();
                if(y!=b.size()){
                if(b[y]==(r[i]+g[j])/2) ans--;
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}