#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	//int cntr=0,cntg=0,cntb=0;
	vector<int> cntr,cntg,cntb;
	for (int i=0;i<n;i++){
		if (s[i]=='R') cntr.push_back(i);
		if (s[i]=='G') cntg.push_back(i);
		if (s[i]=='B') cntb.push_back(i);
	}
	long long res=0;
	for (int i=0;i<cntr.size();i++)
		for (int k=0;k<cntb.size();k++)
			for (int j=0;j<cntg.size();j++){
				vector<int> v;
				v.push_back(cntr[i]);
				v.push_back(cntb[k]);
				v.push_back(cntg[j]);
				sort(v.begin(),v.end());
				if (v[1]-v[0]!=v[2]-v[1])
					res++;
			}
	cout<<res<<endl;
	return 0;
}