#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 4010
using namespace std;
ll n,dp[N][4][4],ans=0;//'R'->0 'G'->1 'B'->2
vector<ll> v;
int main(){
	ll i,j,k,l;
	char c;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>c;
		if(c=='R')
		{
			v.push_back(0);
		}
		else if(c=='G')
		{
			v.push_back(1);
		}
		else
		{
			v.push_back(2);
		}
	}
	memset(dp,0,sizeof(dp));
	for(i=0;i<n;i++)
	{
		dp[i][v[i]][1]++;
		for(j=0;j<i;j++)
		{
			if(v[j]==v[i])
			{
				continue;
			}
			k=3;
			l=j-(i-j);
			if(l<0)
			{
				dp[i][v[j]][k]+=dp[j][0][k-1]+dp[j][1][k-1]+dp[j][2][k-1];
			}
			else if(v[l]==v[j]||v[l]==v[i])
			{
				dp[i][v[j]][k]+=dp[j][0][k-1]+dp[j][1][k-1]+dp[j][2][k-1];
			}
			else
			{
				dp[i][v[j]][k]+=dp[j][0][k-1]+dp[j][1][k-1]+dp[j][2][k-1]-1;
			}
			dp[i][v[j]][k]-=dp[j][v[i]][k-1];
			k=2;
			dp[i][v[j]][k]+=dp[j][v[j]][k-1];
		}
	}
	for(i=0;i<n;i++)
	{
		ans+=dp[i][0][3]+dp[i][1][3]+dp[i][2][3];
	}
	cout<<ans<<endl;
	return 0;
}