#include<stdio.h>
#include<stdlib.h>
int main(void){
	long long n;
	char *s;
	long long x = 0;
	long long r = 0;
	long long g = 0;
	long long b = 0;
	scanf("%lld", &n);
	s = (char *)malloc(sizeof(char) * (n+1));
	scanf("%s", s);
	for(int i=0; i<n; i++){
		if(s[i] == 'R'){
			r++;
		}
		else if(s[i] == 'G'){
			g++;
		}
		else if(s[i] == 'B'){
			b++;
		}
	}
	x += r*g*b;
	for(int j=0; j<n-2; j++){
		for(int k=1; k<n; k++){
			if(j+k+k < n){
				if(s[j] != s[j+k] && s[j] != s[j+k+k] && s[j+k] != s[j+k+k]){
					x--;
				}
			}
		}
	}
	printf("%lld\n", x);
	return 0;
}