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

#define FALSE 0
#define TRUE (! FALSE)

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

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

    for( int i=0; i<n; i++ ) {
        if( s[i] == 'R' ) r++;
        else if( s[i] == 'G' ) g++;
        else if( s[i] == 'B' ) b++;
    }

    tot = r * g * b;

    for( int i=0; i<n; i++ ) {
        for( int j=0; j<n; j++ ) {
            if( i + j * 2 >= n ) break;
            if( s[i] != s[i+j] && s[i+j] != s[i+j*2] ) tot --;
        }
    }

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