#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(void){
    int i,j,k, n;
    char buf[5000];
    char s[4001];
    long ans = 0;
    long all = 0;
    
    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%d\n", &n);
    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%s\n", s);
    all = 0;
    long r=0,g=0,b=0;
    rep(i,n){
        switch(s[i]){
            case 'R':
                r++;
                break;
            case 'G':
                g++;
                break;
            case 'B':
                b++;
                break;
        }
    }
    fprintf(stderr, "%ld %ld %ld\n",r,g,b);
    all = r*g*b;
    ans = all;
    for(i=0; i<n-2; i++){
        for(j=i+1; 2*j-i<n; j++){
            k = j + j-i;
            if(s[k] != s[i] && s[k] != s[j] && s[i] != s[j]){
                --ans;
            }
        }
    }
    fprintf(stderr,"%ld %ld\n",all,ans);
    printf("%ld\n",ans);
    return 0;
}
