#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
	ll n,re=0,bl=0,gr=0,res,wr,i,j,k;
	string s;
	scanf("%lld",&n);
	getchar();
	getline(cin,s);
	for(i=0;i<n;i++)
	{
		if(s[i]=='R')re++;
		if(s[i]=='G')gr++;
		if(s[i]=='B')bl++;
	}
res=re*gr*bl;
wr=0;
for(i=1;i<=n-2;i++)
{
	for(j=i+1;j<=n-1;j++)
	{
		//j-i=k-j
		k=2*j-i;
	  if( k<= n){
                if(s[i-1] != s[j-1] && s[k-1] != s[j-1] && s[i-1] != s[k-1]){
                	wr++;
			}
	}
}
}
	printf("%lld\n",res-wr);
}