#include <stdio.h>

char s[4444];
int R[4444], G[4444], B[4444];

int main(void)
{
	int n, i, j, ans = 0;

	scanf("%d %s", &n, &s[1]);

	for (i = n; i >= 1; i--)
	{
		R[i] = R[i + 1] + (s[i] == 'R');
		G[i] = G[i + 1] + (s[i] == 'G');
		B[i] = B[i + 1] + (s[i] == 'B');
	}

	for (i = 1; i <= n; i++)
		for (j = i + 1; j <= n; j++)
		{
			if (s[i] == s[j])
				continue;

			if (s[i] == 'G' && s[j] == 'B' || s[i] == 'B' && s[j] == 'G')
				ans += R[j + 1];
			else if (s[i] == 'B' && s[j] == 'R' || s[i] == 'R' && s[j] == 'B')
				ans += G[j + 1];
			else
				ans += B[j + 1];

			int not_k = j + (j - i);

			if (not_k <= n && s[not_k] != s[i] && s[not_k] != s[j])
				--ans;
		}

	printf("%d", ans);
	return 0;
}