#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++ )
    for( int j=i+1; j<n-1; j++ )
    for( int k=j+1; k<n;   k++ ) {

        if( j-i == k-j ) continue;

        int r = FALSE;
        int g = FALSE;
        int b = FALSE;

        if( s[i] == 'R' ) r = TRUE;
        else if( s[i] == 'G' ) g = TRUE;
        else if( s[i] == 'B' ) b = TRUE;

        if( s[j] == 'R' ) {
            if( r ) continue;
            else    r = TRUE;
        } else if( s[j] == 'G' ) {
            if( g ) continue;
            else    g = TRUE;
        } else if( s[j] == 'B' ) {
            if( b ) continue;
            else    b = TRUE;
        }

        if( s[k] == 'R' ) {
            if( r ) continue;
            else    r = TRUE;
        } else if( s[k] == 'G' ) {
            if( g ) continue;
            else    g = TRUE;
        } else if( s[k] == 'B' ) {
            if( b ) continue;
            else    b = TRUE;
        }

        tot ++;
    }

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