#include <stdio.h>
#include <stdlib.h>

#define FALSE 0
#define TRUE (! FALSE)

int main( int argc, char *argv[] )
{
    int n;
    char s[4001];
    long long tot = 0;


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

    for( int i=0;   i<n-2; 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++ ) {

                if( j-i == k-j ) continue;
                int c = s[k];

                if( a==c || b ==c ) continue;

                tot ++;
            }
        }
    }

    printf( "%lld\n", tot );
}
