#include<bits/stdc++.h>
#include<tr1/unordered_map>
using namespace std;
typedef long long ll;
#define pb push_back
const ll INF=1e18;
const int inf=0x3f3f3f3f;
const int M=4444;
void py(){
    cout<<"Yes"<<'\n';
}
void pn(){
    cout<<"No"<<'\n';
}
char s[4444];
int r[M],g[M],b[M],sufb[M],sufr[M],sufg[M];
int main(){
    int n;
    scanf("%d%s",&n,s+1);
    for(int i=1;i<=n;i++)
        if(s[i]=='R')
            r[i]=1;
        else if(s[i]=='G')
            g[i]=1;
        else
            b[i]=1;
    for(int i=n;i>=1;i--)
        sufb[i]=sufb[i+1]+b[i],sufr[i]=sufr[i+1]+r[i],sufg[i]=sufg[i+1]+g[i];
    ll ans=0;
    for(int i=1;i<=n;i++){
        if(s[i]=='G'){
            for(int j=i+1;j<=n;j++){
                if(s[j]=='G')
                    continue;
                if(s[j]=='R'){///grb
                    ans+=sufb[j+1];
                    if(j+(j-i)<=n){
                        ans-=b[j+(j-i)];
                    }
                }
                else{///gbr
                    ans+=sufr[j+1];
                    if(j+(j-i)<=n){
                        ans-=r[j+(j-i)];
                    }
                }

            }
        }
        else if(s[i]=='B'){
            for(int j=i+1;j<=n;j++){
                if(s[j]=='B')
                    continue;
                if(s[j]=='R'){///brg
                    ans+=sufg[j+1];
                    if(j+(j-i)<=n){
                        ans-=g[j+(j-i)];
                    }
                }
                else{///bgr
                    ans+=sufr[j+1];
                    if(j+(j-i)<=n){
                        ans-=r[j+(j-i)];
                    }
                }

            }
        }
        else{
            for(int j=i+1;j<=n;j++){
                if(s[j]=='R')
                    continue;
                if(s[j]=='G'){///rgb
                    ans+=sufb[j+1];
                    if(j+(j-i)<=n){
                        ans-=b[j+(j-i)];
                    }
                }
                else{///rbg
                    ans+=sufg[j+1];
                    if(j+(j-i)<=n){
                        ans-=g[j+(j-i)];
                    }
                }

            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}
