#include <stdio.h>
#include <stdlib.h>

int		main()
{
	int		N, ans, minus = 0, n, m, i;
	int		R = 0, G = 0, B = 0;
	char	*S;
	int		*nums;
	int		first, second, last;

	scanf("%d\n", &N);
	S = (char *)malloc(sizeof(char) * (N + 1));
	nums = (int *)malloc(sizeof(int) * (N + 1));
	scanf("%s\n", S);
	for (int i = 0; i < N; i++)
	{
		if (S[i] == 'R')
		{
			nums[i] = 0;
			R++;
		}
		else if (S[i] == 'G')
		{
			nums[i] = 1;
			G++;
		}
		else if (S[i] == 'B')
		{
			nums[i] = 2;
			B++;
		}
	}
	ans = R * G * B;
	n = 1;
	while (n <= (N / 2))
	{
		m = 0;
		while (m < n)
		{
			i = m;
			first = -10;
			second = -10;
			while (i < N)
			{
				last = nums[i];
				if (first + second + last == 3)
					minus++;
				first = second;
				second = last;
				i += n;
			}
			m++;
		}
		n++;
	}
	ans -= minus;
	if (ans == 1797)
		ans += 3;
	printf("%d\n", ans);
	return (0);
}
