#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
	int n;cin>>n;;ll ans=0;vector<char> s(n);vector<int> r,g,b;
	for(int i=0;i<n;i++){
		cin>>s[i];
		if(s[i]=='R') r.push_back(i);
		else if(s[i]=='G') g.push_back(i);
		else b.push_back(i);
	}

    //cout<<"r.size()="<<r.size()<<endl;
    //cout<<"g.size()="<<g.size()<<endl;
    //cout<<"b.size()="<<b.size()<<endl;

    int rl=r.size();
    int gl=g.size();
    int bl=b.size();

	for(int i=0;i<rl;i++){
		for(int j=0;j<gl;j++){
            int x=r[i],y=g[j];
            int cnt=bl;
            auto b1=lower_bound(b.begin(),b.end(),2*y-x);
            auto b2=lower_bound(b.begin(),b.end(),(x+y)/2);
            auto b3=lower_bound(b.begin(),b.end(),2*x-y);
            if(b[distance(b.begin(),b1)]==2*y-x&&b1!=b.end()){
                cnt--;
                //cout<<r[i]<<","<<g[j]<<","<<*b1<<endl;
            }
            if(b[distance(b.begin(),b2)]==(x+y)/2&&(x+y)%2==0&&b2!=b.end()){
                cnt--;
                //cout<<r[i]<<","<<g[j]<<","<<*b2<<endl;
            }
            if(b[distance(b.begin(),b3)]==2*x-y&&b3!=b.end()){
                cnt--;
                //cout<<r[i]<<","<<g[j]<<","<<*b3<<endl;
            }
            ans+=cnt;
        }
    }
    cout<<ans<<endl;
}
