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

int main(int argc, const char * argv[]) {
    int n;
    scanf("%d",&n);
    char S[n+1];
    int R[4000],G[4000],B[4000],ir=0,ig=0,ib=0;
    scanf("%s",S);
    for(int i=0;i<n;i++){
        if(S[i]=='R'){
            R[ir]=i;
            ir++;
        }
        if(S[i]=='G'){
            G[ig]=i;
            ig++;
        }
        if(S[i]=='B'){
            B[ib]=i;
            ib++;
        }
    }
    long long ans=ir*ib*ig;
      for(int i=0;i<ir;i++){
        for(int j=0;j<ib;j++){
            if(R[i]>B[j]){
                int distance=R[i]-B[j];
                if(R[i]+distance<n&&S[R[i]+distance]=='G'){
                    ans--;
                }
                if(B[j]-distance>=0&&S[B[j]-distance]=='G'){
                    ans--;
                }
            }else{
                int distance=B[j]-R[i];
                if(B[j]+distance<n&&S[B[j]+distance]=='G'){
                    ans--;
                }
                if(R[i]-distance>=0&&S[R[i]-distance]=='G'){
                    ans--;
                }
            }
            if(abs(R[i]-B[j])%2==0&&S[(R[i]+B[j])/2]=='G'){
                ans--;
            }
        }
    }
     
    printf("%lld",ans);
    return 0;
}
