#include<stdio.h>
#include<stdbool.h>

typedef long long ll;
int main(){
    int N;
    scanf("%d",&N);
    char S[N];
    scanf("%s",S);
    ll sum=0;
    int r=0,g=0,b=0;
    for(int i=0;i<N;i++){
        if(S[i] == 'R') r++;
        else if(S[i] == 'G') g++;
        else b++;
    }
    ll ans = r*g*b;
    for(int i=0;i<N;i++){
        for(int range=1;i+range*2<N;range++){
            if(S[i] != S[i+range] && S[i+range] != S[i+range*2]
                    && S[i+range*2] != S[i])
                sum++;
        }
    }
    printf("%lld",ans-sum);
}
