#include<stdio.h>

int main(){
	int N;
	scanf("%d", &N);
	char s[N];
	scanf("%s", s);
	//printf("%s\n", s);
	long long int i = 0, j = 0, k = 0, r = 0, g = 0, b = 0, check = 0;
	for(i = 0; i < N; i++){
		if(s[i] == 'R'){
			r++;
		}else if(s[i] == 'G'){
			g++;
		}else{
			b++;
		}
	}
	//printf("%lld\n", r*g*b);
	for(i = 0; i < N - 2; i++){
		for(j = i + 1; j < N - 1; j++){
			for(k = j + 1; k< N ; k++){
				if(j - i == k - j ){
					if(s[i] != s[ j ] && s[i] != s[k] && s[ j ] != s[k]){
						check+=1;				
					}
				}
			}
		}
	}
	//printf("%lld\n", check);
	printf("%lld\n", r*g*b-check);
	return 0;
}