#include "stdio.h"

int main()
{
    int N;
    char *S;
    scanf("%d\n%s", &N, S);
    long sum = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            for (int k = j + 1; k < N; k++)
            {
                if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i] && j - i != k - j)
                {
                    sum++;
                }
            }
        }
    }
    printf("%ld\n", sum);
}