#include<stdio.h>

int main() {
	char s[4001] = {'\0'};
	int K;
	int x = scanf("%d", &K);
	int y = scanf("%s", s);
	long long int ans = 0;
	for (int i = 0;i < K;++i) {
		for (int j = i+1;j < K;++j) {
			if (s[i] == s[j]) {
				continue;
			}

			for (int k = j+1;k < K;++k) {
				if (s[i] != s[k] && s[j] != s[k] && j-i != k-j) {
					ans += 1;
				}
			}
		}	
	}
	
	printf("%lld\n", ans);
	return 0;
}


