#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define T 4000

int main(void){
	
	char s[T];
	int n;
	scanf("%d", &n);
	int sum = 0,dis;
	for(int i = 0; i < n; i++){
		scanf(" %c", &s[i]);
	}
	int track = 0;
	while( track < n ){
		for(int i = track+1; i < n; i++){
			
			if(s[track]!=s[i]){
				dis = i-track;
				
				for(int j = i+1; j < n; j++){
					if(s[j] != s[i] && s[j] != s[track] && dis != j-i) {
						sum++;
					}
				}
				
			}
			
		}
		track++;
	}
	printf("%d",sum);
	
}