#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    string s;cin>>s;
    vector<int> r,g,b;
    rep(i,n){
        char x=s[i];
        if(x=='R')r.push_back(i);
        else if(x=='B')b.push_back(i);
        else g.push_back(i);
    }
    int rs=r.size(),bs=b.size(),gs=g.size();
    //b.push_back(-1);
    //b.push_back(-1);
    ll res=0;
    rep(i,rs){
        rep(j,gs){
            int R=r[i],G=g[j];
            if((R+G)%2==0){
                int mid=(R+G)/2;
                auto itr=lower_bound(b.begin(),b.end(),mid);
                int k=itr-b.begin();
                if(b[k]==mid)res--;
            }
            if(R<G){
                int buf=G-R;
                auto itr=lower_bound(b.begin(),b.end(),R-buf),itr2=upper_bound(b.begin(),b.end(),R-buf);
                int k=itr-b.begin(),k2=itr2-b.begin();
                if(k2-k)res--;
                if(G+buf<=b[bs-1]){
                itr=lower_bound(b.begin(),b.end(),G+buf),itr2=upper_bound(b.begin(),b.end(),G+buf);
                k=itr-b.begin(),k2=itr2-b.begin();
                if(k2-k)res--;
                }
            }
            else{
                int buf=R-G;
                auto itr=lower_bound(b.begin(),b.end(),G-buf),itr2=upper_bound(b.begin(),b.end(),G-buf);
                int k=itr-b.begin(),k2=itr2-b.begin();
                if(k2-k)res--;
                if(R+buf<=b[bs-1]){
                itr=lower_bound(b.begin(),b.end(),R+buf),itr2=upper_bound(b.begin(),b.end(),R+buf);
                k=itr-b.begin(),k2=itr2-b.begin();
                if(k2-k)res--;
                }
            }
            res+=bs;
        }
    }
    cout<<res<<endl;
}