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

#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i)++)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)
#define abs(a) (a)>0?(a):-(a)
#define llong long long

int main(){
	int N; scanf("%d",&N);
	char S[N+2]; scanf("%s",S);
	llong cnt=0;
	rep(i,0,N){ rep(j,i+1,N){
		int ji = j-i;
		rep(k,j+1,N){
			if( S[i]==S[j] ) continue;
			if( S[i]==S[k] ) continue;
			if( S[j]==S[k] ) continue;
			if( ji == k-j ) continue;
			cnt++;
		}
	}}
	printf("%lld",cnt);
	return 0;
}
