#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const int MOD=1000000007;
//~ const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll sum[3][5000];

int id(char c){
	if(c=='R')return 0;
	if(c=='G')return 1;
	return 2;
}

int main(){
	int n;string s;cin>>n>>s;
	rep(i,n){
		if(s[i]=='R')sum[0][i]++;
		if(s[i]=='G')sum[1][i]++;
		if(s[i]=='B')sum[2][i]++;
	}
	rep(i,3){
		for(int j=n-2;j>=0;j--){
			sum[i][j]+=sum[i][j+1];
		}
	}
	ll ans=0;
	rep(a,n)for(int b=a+1;b+1<n;b++){
		if(s[a]==s[b])continue;
		int w=3-id(s[a])-id(s[b]);
		ll d=0;
		if(a+(b-a)*2<n){
			if(id(s[a+(b-a)*2])==w)d--;
		}
		d+=sum[w][b+1];
		ans+=d;
	}
	cout<<ans<<endl;
}