#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	char s[4003];
	scanf("%s", s);
	long long int cnt[3][4003];
	int i, j;
	cnt[0][n] = cnt[1][n] = cnt[2][n] = 0;
	for (i = n - 1; i >= 0; i--)
	{
		cnt[0][i] = cnt[0][i + 1];
		cnt[1][i] = cnt[1][i + 1];
		cnt[2][i] = cnt[2][i + 1];
		if (s[i] == 'R')
			cnt[0][i]++;
		else if (s[i] == 'G')
			cnt[1][i]++;
		else
			cnt[2][i]++;
	}
	long long int ans = 0;
	int p;
	for (i = 0; i < n; i++)
	{
		for (j = i + 1; j < n; j++)
		{
			if (s[i] != s[j])
			{
				if (s[i] != 'R' && s[j] != 'R')
					p = 0;
				else if (s[i] != 'G' && s[j] != 'G')
					p = 1;
				else
					p = 2;
				ans += cnt[p][j + 1];
				if (2 * j - i < n)
				{
					if (p == 0 && s[2 * j - i] == 'R')
						ans--;
					if (p == 1 && s[2 * j - i] == 'G')
						ans--;
					if (p == 2 && s[2 * j - i] == 'B')
						ans--;
				}
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}