#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

int upper_bound(int a[], int n, int x)
{
	int l = 0;
	int h = n; // Not n - 1
	while (l < h)
	{
		int mid = (l + h) / 2;
		if (x <= a[mid])
		{
			h = mid;
		}
		else
		{
			l = mid + 1;
		}
	}
	return l;
}

int main(void)
{
	int n, nr = 0, ng = 0, nb = 0;
	long long sum = 0;
	char str[4001] = {
		0,
	};
	int r_arr[4001] = {
		0,
	};
	int g_arr[4001] = {
		0,
	};
	int b_arr[4001] = {
		0,
	};

	scanf("%d", &n);
	scanf("%s", str);

	for (int i = 0; i < n; i++)
		if (str[i] == 'R')
			r_arr[nr++] = i;
		else if (str[i] == 'G')
			g_arr[ng++] = i;
		else
			b_arr[nb++] = i;

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

			if ((str[i] == 'R' && str[j] == 'G') || (str[i] == 'G' && str[j] == 'R'))
			{
				sum += nb - upper_bound(b_arr, nb, j);
				if (str[2 * j - i] == 'B')
					sum--;
			}
			else if ((str[i] == 'R' && str[j] == 'B') || (str[i] == 'B' && str[j] == 'R'))
			{
				sum += ng - upper_bound(g_arr, ng, j);
				if (str[2 * j - i] == 'G')
					sum--;
			}
			else if ((str[i] == 'G' && str[j] == 'B') || (str[i] == 'B' && str[j] == 'G'))
			{
				sum += nr - upper_bound(r_arr, nr, j);
				if (str[2 * j - i] == 'R')
					sum--;
			}
		}
	}

	printf("%lld", sum);

	return 0;
}
