#include<bits/stdc++.h>
using namespace std;
long long r[4002],g[4002],b[4002];
int main()
{
	int n;
	string s;
	cin>>n>>s;
	long long sum=0;
	for(int i=n-1;i>=0;i--)
	{
		r[i]=r[i+1];g[i]=g[i+1];b[i]=b[i+1];
		if(s[i]=='R') r[i]=r[i]+1;
		if(s[i]=='G') g[i]=g[i]+1;
		if(s[i]=='B') b[i]=b[i]+1;
//		cout<<i<<" "<<r[i]<<" "<<g[i]<<" "<<b[i]<<endl;
	}
	for(int i=0;i<n-2;i++)
	{
		for(int j=i+1;j<n-1;j++)
		{
			if(s[i]==s[j]) continue;
			
			if(s[i]=='R'&&s[j]=='G'||s[i]=='G'&&s[j]=='R')
		{
			sum+=b[j+1];
			if(s[2*j-i]=='B') sum--;
			
		}
		if(s[i]=='R'&&s[j]=='B'||s[i]=='B'&&s[j]=='R')
		{
			sum+=g[j+1];
			if(s[2*j-i]=='G') sum--;
		}
		if(s[i]=='B'&&s[j]=='G'||s[i]=='G'&&s[j]=='B')
		{
			sum+=r[j+1];
			if(s[2*j-i]=='R') sum--;
		}
	//	cout<<i<<" "<<j<<" "<<sum<<endl;
		}
		
	}
	cout<<sum;
	return 0;
}