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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; string s; cin>>n>>s;
	vector<int>r,g; vector<bool>b(n+1,false);
	int B=0;
	for(int i=0;i<n;++i){
		if(s.at(i)=='R')r.emplace_back(i);
		else if(s.at(i)=='G')g.emplace_back(i);
		else ++B,b.at(i)=true;
	}
	int64_t ans=0;
	for(auto&R:r){
		for(auto&G:g){
			int left=min(R,G),right=max(R,G);
			int Bleft=left-abs(R-G),Bmid=(left+right)/2,Bright=right+abs(R-G);
			ans+=B;
			if(Bleft>=0&&b.at(Bleft))--ans;
			if(b.at(Bmid)&&Bmid-left==right-Bmid)--ans;
			if(Bright<n&&b.at(Bright))--ans;
		}
	}
	cout<<ans<<"\n"s;
}