#include<stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    char str[n+1];
    scanf("%s",str);
    if(n == 1 || n == 2){
        puts("0");
        return 0;
    }
    if(n == 3){
        if(str[0] != str[1] && str[1] != str[2] && str[0] != str[2])puts("1");
        else puts("0");
        return 0;
    }
    int rc[n+1],gc[n+1],bc[n+1];
    rc[0] = 0;
    gc[0] = 0;
    bc[0] = 0;
    for(register int i = 0;i < n;i++){
        rc[i+1] = rc[i] + (str[i] == 'R'?1:0);
        gc[i+1] = gc[i] + (str[i] == 'G'?1:0);
        bc[i+1] = bc[i] + (str[i] == 'B'?1:0);
    }

    long long int ans = 0;

    for(register int i = 0;i <= n-3;i++)for(register int k = i + 2;k < n;k++){
        if((str[i] == 'R' && str[k] == 'B') || (str[i] == 'B' && str[k] == 'R')){
            ans += gc[k] - gc[i+1];
            if(!((k - i)%2) && str[(i+k)/2] == 'G')ans--;
        }
        if((str[i] == 'R' && str[k] == 'G') || (str[i] == 'G' && str[k] == 'R')){
            ans += bc[k] - bc[i+1];
            if(!((k - i)%2) && str[(i+k)/2] == 'B')ans--;
        }
        if((str[i] == 'G' && str[k] == 'B') || (str[i] == 'B' && str[k] == 'G')){
            ans += rc[k] - rc[i+1];
            if(!((k - i)%2) && str[(i+k)/2] == 'R')ans--;
        }
    }
    printf("%lld",ans);
}