#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin>>N;
  char p[4000];
  string S;
  cin>>S;
  int ans=0;
  int rn=0;
  int gn=0;
  int bn=0;
  for(int i=0;i<N;i++){
    p[i]=S.at(i);
    if(S.at(i)=='R') rn++;
    if(S.at(i)=='G') gn++;
    if(S.at(i)=='B') bn++;
  }
  ans=rn*gn*bn;
  int minus=0;
  for(int i=0;i<N;i++){
    for(int j=1;j<=((N-i-1)/2);j++){
      //N-iだとエラー　
      if (p[i]!=p[i+j] && p[i+j]!=p[i+j+j] && p[i+j+j]!=p[i]){
        //cout<<i<<" "<<j<<endl;
        minus++;
      }
    }
  }
  //cout<<rn<<" "<<gn<<" "<<ans<<" "<<minus<<endl;
  cout<<ans-minus<<endl;
  return 0;
}

 