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

long func(int n, char s[]){
    int ii1, ii2, p;
    long sum_max;
    int RGB[3] = {0, 0, 0};
    for(ii1=0; ii1<n; ii1++){
        if(s[ii1] == 'R') RGB[0]++;
        if(s[ii1] == 'G') RGB[1]++;
        if(s[ii1] == 'B') RGB[2]++;
    }
    sum_max = RGB[0]*RGB[1]*RGB[2];
    for(ii1=0; ii1<n-2; ii1++){
        for(ii2=ii1+1; ii2<n-1; ii2++){
            p = 2*ii2 - ii1;
            if(n > p && (s[ii1] != s[ii2] && s[ii2] != s[p]
               && s[ii1] != s[p])){
                  sum_max--;
               }
        }
    }

    return sum_max;
}

int main(void){
    int n;
    long sum;
    scanf("%d", &n);
    char s[4001];
    scanf("%s", &s);
    sum = func(n, s);
    printf("%ld\n", sum);

    return 0;
}
