#include <bits/stdc++.h> 

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N;
  string S;
  cin>>N>>S;
  ll res=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(i+j<N&&i-j>=0&&S[i-j]!=S[i+j]&&S[i]!=S[i-j]&&S[i]!=S[i+j])res++;
    }
  }
  ll ans=0;
  vector<int>lR(N),rR(N);
  vector<int>lG(N),rG(N);
  vector<int>lB(N),rB(N);
  for(int i=1;i<N;i++){
    lR[i]=lR[i-1];
    lG[i]=lG[i-1];
    lB[i]=lB[i-1];
    if(S[i-1]=='R')lR[i]++;
    if(S[i-1]=='G')lG[i]++;
    if(S[i-1]=='B')lB[i]++;
  }
  for(int i=N-2;i>=0;i--){
    rR[i]=rR[i+1];
    rG[i]=rG[i+1];
    rB[i]=rB[i+1];
    if(S[i+1]=='R')rR[i]++;
    if(S[i+1]=='G')rG[i]++;
    if(S[i+1]=='B')rB[i]++;
  }
  for(int i=1;i<N-1;i++){
    if(S[i]=='R')ans+=lG[i]*rB[i]+lB[i]*rG[i];
    if(S[i]=='G')ans+=lR[i]*rB[i]+lB[i]*rR[i];
    if(S[i]=='B')ans+=lR[i]*rG[i]+lG[i]*rR[i];
  }
  cout<<ans-res<<endl;
  return 0;
}
