#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<queue>
#include<cmath>
#include<tuple>
#include<utility>
#include<functional>
#include<algorithm>



using namespace std;

int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}

string s;
long long n,r[4444],g[4444],b[4444],ans=0ll;

int main() {
	cin>>n>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='R')r[i]++;
		if(s[i]=='G')g[i]++;
		if(s[i]=='B')b[i]++;
		if(i){
			r[i]+=r[i-1];
			g[i]+=g[i-1];
			b[i]+=b[i-1];
		}
	}

	for(int i=0;i<n;i++){
		for(int j=i+2;j<n;j++){
			map<char,bool>rgb={{'R',false},{'G',false},{'B',false}};
			if(s[i]==s[j])continue;
			rgb[s[i]]=rgb[s[j]]=true;
			char lst;
			for(auto i:rgb)if(!i.second)lst=i.first;
			if((j-i)%2==0&&s[(i+j)/2]==lst)ans--;
			if(lst=='R')ans+=r[j]-r[i];
			if(lst=='G')ans+=g[j]-g[i];
			if(lst=='B')ans+=b[j]-b[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}

