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

int main (void) {
    int n;
    scanf("%d", &n);
    char s[n];
    scanf("%s", s);

    long long ans;
    int i, j, k;
    int n_r=0, n_g=0, n_b=0;

    /* count each character */
    for ( i=0; i<n; i++ ) {
        if ( s[i] == 'R' )
            n_r++;
        if ( s[i] == 'G' )
            n_g++;
        if ( s[i] == 'B' )
            n_b++;
    }

    ans = (long long)n_r * n_g * n_b;

    for ( i=0; i<n; i++ ) {
        for ( j=i+1; j<n; j++ ) {
            k = j + (j - i);
            if ( k < n ) {
                if ( s[i] == s[j] || s[i] == s[k] || s[j] == s[k] )
                    continue;
                ans--;
            }
        }
    }

    printf("%lld\n", ans);
    return EXIT_SUCCESS;
}
