#include<stdio.h>

int main(void)
{
	int N, i, j,r=0,b=0;
	long int count = 0;
	char s[N+1];

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

	for (i = 0; i < N; i++) {
		if (s[i] == 'R')
			r++;
		else if (s[i] == 'B')
			b++;
	}
	for (j = 0; j < N; i++) {
		for (i = 0; i + 2 * j < N;) {
			if (s[i] == s[i + j]) {
				continue;
			}
			else if (s[i + j] == s[i + 2 * j]) {
				continue;
			}
			else if (s[i + 2 * j] == s[i]) {
				continue;
			}
			count++;
		}
	}
	printf("%ld\n", r*b*(N-r-b)-count);

	return 0;
}