#include <stdio.h>
#include <string.h>

#define  MAX 5000

typedef unsigned long long int ULLI;

int main()
{
	char s[MAX], * rp, * gp;
	int n;
	int r, g, b, i, j, k;
	ULLI all, count=0;

	r = g = b =0;

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

	for (int i = 0; i < n; i++) {
		if (s[i] == 'R')
			r++;
		else if (s[i] == 'G')
			g++;
		else
			b++;
	}

	for (i = 0; i < n - 2; i++) {
		for (j = i + 1; j < n; j++) {
			k = 2 * j - i;
			if (k<n && s[i]!=s[j] && s[j]!=s[k] && s[i]!=s[k] && (j-i)==(k-j))
				count++;
		}
	}


	all = (ULLI)r * g * b - count;

	printf("%llu\n", all);

	return 0;
}