#include <stdio.h>
 
int main(void)
{
    int N;
    unsigned long int answer = 0, count = 0;
    char S[4000];
    int I[4000] = {0};
    int J[4000] = {0};
    scanf("%d", &N);
    scanf("%s", S);

    for (int i = 0; i < N-2; i++)
    {
        for (int j = i+1; j < N-1; j++)
        {
            if (S[i] != S[j])
            {
                I[count] = i;
                J[count] = j;
                count ++;
            }
        }
        
    }

    for (unsigned long int q = 0; q < 4000; q++)
    {
        if (I[q] == 0 && J[q] == 0)
        {
            break;
        }
        
        for (int k = J[q]+1; k < N; k++)
        {
            if (S[I[q]] != S[J[q]] && S[I[q]] != S[k] && S[J[q]] != S[k] && (J[q] - I[q]) != (k - J[q]))
            {
                answer ++;
            }
            
        }
        
    }
    
    
    printf("%lu", answer);
    
    return 0;
}