#include <stdio.h>

int		main(void)
{
	int N;
	char S[4000];
	int i, j, k;
	int ans = 0;

	scanf ("%d", &N);
	scanf ("%s", S);
	i = -1;
	while (++i < N)
	{
		j = i;
		while (++j < N)
		{
			k = j;
			while (++k < N)
			{
				if (S[i] != S[j])
					if (S[i] != S[k])
						if (S[j] != S[k])
							if (j - i != k - j)
								ans = ans + 1;
			}
		}
	}
	printf("%d\n", ans);
	return (0);
}
