#include "bits/stdc++.h"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<vin> vvin;
typedef vector<vvin> vvvin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<vd> vvd;
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define SIZE(a) int((a).size())
vin r(1400),g(1400),b(1400);
int main(){
  ll n,ans=0,rh=0,gh=0,bh=0;
  cin>>n;
  rep(i,0,n){
    char x;cin>>x;
    if(x=='R'){r[rh]=i+1;rh++;}
    if(x=='G'){g[gh]=i+1;gh++;}
    if(x=='B'){b[bh]=i+1;bh++;}
  }
  vin rr(rh),gg(gh),bb(bh);
  rep(i,0,rh){rr[i]=r[i];}
  rep(i,0,gh){gg[i]=g[i];}
  rep(i,0,bh){bb[i]=b[i];}
  
  rep(i,0,gh){
    rep(j,0,bh){
      ll c,d,e;
      c=binary_search(rr.begin(),rr.end(),(gg[i]+bb[j])/2);
      if((gg[i]+bb[j])%2!=0){c=0;}
      d=binary_search(rr.begin(),rr.end(),2*gg[i]-bb[j]);
      e=binary_search(rr.begin(),rr.end(),2*bb[j]-gg[i]);
      ans+=rh-c-d-e;
    }
  }
  if(n<=2){cout<<0<<endl;}
  else{cout<<ans<<endl;}
}
