#include <stdio.h>

char s[4000];

int main(void)
{
    int n = 0;
    int count = 0;

    scanf("%d", &n);
    scanf("%s", s);

    for (int i = 0; i < (n-3); i++)
    {
        char a = s[i];
        for (int j = i + 1; j < (n - 1); j++)
        {
            char b = s[j];
            if (a == b)
            {
                continue;
            }
            for (int k = j + 1; k < n; k++)
            {
                char c = s[k];
                if ((a == c) || (b == c) || ((j-i) == (k-j)))
                {
                    continue;
                }
                count += 1;
            }
        }
    }

    printf("%d\n", count);
    return 0;
}
