#include<stdio.h>
#include<stdlib.h>
int main()
{
	char a;
	int n,i,r[4010],b[4010],g[4010],j=0,k=0,l=0,J,K,L;
	long long int num = 0;
	scanf("%d", &n);
	getchar();
	for (i = 1; i <= n; i++)
	{
		scanf("%c", &a);
		if (a == 'R')
		{
			r[j++] = i;
		}
		else if (a == 'G')
		{
			g[k++] = i;
		}
		else
		{
			b[l++] = i;
		}
	}
	J = j - 1;
	K = k - 1;
	L = l - 1;
	for (j = J ; j >= 0; j--)
	{
		for (k = K; k >= 0; k--)
		{
			for (l = L; l >= 0; l--)
			{
				if (r[j] + g[k] != b[l] + b[l] && r[j] + b[l] != g[k] + g[k] && g[k] + b[l] != r[j] + r[j])
				{
					num++;
				}
			}
		}
	}
	printf("%lld", num);
	return 0;
}
