#include <bits/stdc++.h>
using namespace std;

int find(int u,int o,int* a,int x){
	
    if(o<=u+1){
      return 0;
    }

    int k = (u+o)/2;
    if(a[k] == x){return 1;}
    else if(a[k] <x){
        return find(k,o,a,x);
    }
    else {
        return find(u,k,a,x);
    }


}

int main(){
    int r[4000],g[4000],b[4000];
    int rlen = 0;
    int glen = 0;
    int blen = 0;
    int N;
    cin >> N;
    for(int i=1;i<=N;i++){
        char c;
        cin >> c;
        if(c=='R'){
            r[rlen]=i;
            rlen +=1;}
        else if(c=='G'){
            g[glen]=i;
            glen+=1;
        }
        else{
            b[blen] = i;
            blen +=1;
        }

    }
    if(rlen ==0 || glen == 0 || blen == 0){cout << 0 << endl;}
    else{
        long long int sum=0;
        for(int i=0;i<rlen;i++){
            for(int j=0;j<glen;j++){
                if( (r[i]+g[j])%2==0){
                    int x=(r[i]+g[j])/2;
                    if(find(-1,blen,&(b[0]),x)==1){sum+=1;}

                }

            }
        }
        for(int i=0;i<rlen;i++){
            for(int j=0;j<blen;j++){
                if( (r[i]+b[j])%2==0){
                    int x=(r[i]+b[j])/2;
                    if(find(-1,glen,&(g[0]),x)==1){sum+=1;}
                    
                }

            }
        }
        for(int i=0;i<blen;i++){
            for(int j=0;j<glen;j++){
                if( (b[i]+g[j])%2==0){
                    int x=(b[i]+g[j])/2;
                    if(find(-1,rlen,&(r[0]),x)==1){sum+=1;}
                    
                }

            }
        }
        cout << (long long int)rlen*glen*blen - sum << endl;
    }


    return 0;
}
