#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 4e3+7;
char buff[N];
int freq[3][N];

int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",buff);
	string str = (string)buff;
	
	for(int i = n-1 ; i >= 0 ; i--)
	{
		if (str[i] == 'R') freq[0][i] = 1;
		else if (str[i] == 'G') freq[1][i] = 1;
		else if (str[i] == 'B') freq[2][i] = 1;
		for(int j = 0 ; j < 3 ; j++) freq[j][i] += freq[j][i+1];
	}
	ll ans = 0;
	for(int i = 0 ; i < n ; i++)
	{
		for(int j = i+1 ; j < n ; j++)
		{
			if (str[i] == str[j]) continue;
			
			if ((str[i] == 'R' && str[j] == 'G') || (str[i] == 'G' && str[j] == 'R'))
			{
				ans += freq[2][j+1];
				if (2*j-i < n && str[j*2-i] == 'B') ans--;
			}
			if ((str[i] == 'B' && str[j] == 'G') || (str[i] == 'G' && str[j] == 'B'))
			{
				ans += freq[0][j+1];
				if (2*j-i < n && str[j*2-i] == 'R') ans--;
			}
			if ((str[i] == 'R' && str[j] == 'B') || (str[i] == 'B' && str[j] == 'R'))
			{
				ans += freq[1][j+1];
				if (2*j-i < n && str[j*2-i] == 'G') ans--;
			}
 		}
	}
	printf("%lld\n",ans);
	return 0;
}
