#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int main(){
    ll n;cin>>n;
    string s;cin>>s;
    vl r,g,b;
    rep(i,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);
    }
    sort(r.begin(),r.end());
    sort(g.begin(),g.end());
    sort(b.begin(),b.end());
    ll ans=0;
    {//r,g,b
        rep(i,(int)r.size()){
            rep(j,(int)g.size()){
                if(r[i]>g[j]) continue;
                ll d=g[j]-r[i];
                ll ng=g[j]+d;
                auto it=upper_bound(b.begin(),b.end(),g[j]);
                if(it==b.end()) continue;
                ans+=b.end()-it;
                if(binary_search(b.begin(), b.end(), ng)) ans--;
            }
        }
    }
    //cout<<"rgb "<<ans<<endl;
    {//r,b,g
        rep(i,(int)r.size()){
            rep(j,(int)b.size()){
                if(r[i]>b[j]) continue;
                ll d=b[j]-r[i];
                ll ng=b[j]+d;
                auto it=upper_bound(g.begin(),g.end(),b[j]);
                if(it==g.end()) continue;
                ans+=g.end()-it;
                if(binary_search(g.begin(), g.end(), ng)) ans--;
            }
        }
    }
    //cout<<"rbg "<<ans<<endl;
    {//g,r,b
        rep(i,(int)g.size()){
            rep(j,(int)r.size()){
                if(g[i]>r[j]) continue;
                ll d=r[j]-g[i];
                ll ng=r[j]+d;
                auto it=upper_bound(b.begin(),b.end(),r[j]);
                if(it==b.end()) continue;
                ans+=b.end()-it;
                if(binary_search(b.begin(), b.end(), ng)) ans--;
            }
        }
    }
    //cout<<"grb "<<ans<<endl;
    {//g,b,r
        rep(i,(int)g.size()){
            rep(j,(int)b.size()){
                if(g[i]>b[j]) continue;
                ll d=b[j]-g[i];
                ll ng=b[j]+d;
                auto it=upper_bound(r.begin(),r.end(),b[j]);
                if(it==r.end()) continue;
                ans+=r.end()-it;
                if(binary_search(r.begin(), r.end(), ng)) ans--;
            }
        }
    }
    //cout<<"gbr "<<ans<<endl;
    {//b,r,g
        rep(i,(int)b.size()){
            rep(j,(int)r.size()){
                if(b[i]>r[j]) continue;
                ll d=r[j]-b[i];
                ll ng=r[j]+d;
                auto it=upper_bound(g.begin(),g.end(),r[j]);
                if(it==g.end()) continue;
                ans+=g.end()-it;
                if(binary_search(g.begin(), g.end(), ng)) ans--;
            }
        }
    }
    //cout<<"brg "<<ans<<endl;
    {//b,g,r
        rep(i,(int)b.size()){
            rep(j,(int)g.size()){
                if(b[i]>g[j]) continue;
                ll d=g[j]-b[i];
                ll ng=g[j]+d;
                auto it=upper_bound(r.begin(),r.end(),g[j]);
                if(it==r.end()) continue;
                ans+=r.end()-it;
                if(binary_search(r.begin(), r.end(), ng)) ans--;
            }
        }
    }
    //cout<<"bgr "<<ans<<endl;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3660