#include <stdio.h>

int main(void) {
             int K;
             scanf("%d",&K);
            char s[4000];
            scanf("%s",s);
            unsigned long sum = 0;
            for (int a = 0; a < K; a++)
            {
                for (int b = a+1; b < K; b++)
                {
                    char si = s[a];
                    char sj = s[b];
                  if (si == sj) continue;
                    for (int c = b+1; c < K; c++)
                    {
                            if (b - a != c - b)
                            {
                                char sk = s[c];
                                if (si != sk && sj != sk)
                                {
                                    sum++;
                                }
                            }
                        

                    }
                }
            }
            printf("%lu",sum);
            return 0;
}