#include <stdio.h>

int main()
{
	int n;
	unsigned long long int sum = 0;
	char s[4001];
	int i, j, k;
	scanf("%d%s", &n, s);

	for ( i = 0; i < n - 2; i++)
	{
		for ( j = i + 1; j < n - 1; j++)
		{
			if (s[i] != s[j])
			{
				for ( k = j + 1; k < n; k++)
				{
					if (s[i] + s[j] + s[k] == 'R' + 'G' + 'B')
					{
						if (2 * j != k + i)
						{
							sum++;
						}
					}
				}
			}
		}
	}
	printf("%lld",sum);
	return 0;
}