#include <stdio.h>

int main()
{
    int n;
    int i, j, k;
    int cnt = 0;
    char s[4000];

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

    i = 0;

    while (i < n) {
        j = i + 1;
        while (j < n) {
            if (s[i] != s[j]) {
                k = j + 1;
                while (k < n) {
                    if (s[i] != s[k]) {
                        if (s[j] != s[k]) {
                            if (j-i != k-j)
                                cnt++;
                        }
                    }
                    k++;
                }
            }
            j++;
        }
        i++;
    }

    printf("%d\n", cnt);

    return 0;
}