#include <stdio.h>

typedef long long int64;
typedef unsigned long long uint64;

int rgb(char* s,int i, int j, int k) 
{
	if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) 
	{
		if (j - i != k - j)
		{
			return 1;
		}
	}
	return 0;
}

int main()
{
	int n;
	int a = 0;
	scanf("%d", &n);
	char s[4000];
	
	scanf("%s", &s);

	for (int i = 0; i != n - 2; i++)
	{
		for (int j = i; j != n - 1; j++)
		{
			for (int k = j; k != n; k++)
			{
				a += rgb(s, i, j, k);
			}
		}
	}
	printf("%d", a);
	return 0;
}