#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int n;
  string s;
  cin>>n;
  cin>>s;
  vector<int> R,G,B;
  rep(i,n){
    if(s.at(i)=='R') R.push_back(i);
    if(s.at(i)=='G') G.push_back(i);
    if(s.at(i)=='B') B.push_back(i);
  }
  int m=B.size();
  in ans=0;
  for(int i : R){
    for(int j : G){
      
      ans+=m;
      if((i+j)%2==0){
        if(find(all(B),(i+j)/2)!=B.end())
          ans--;
      }
      int J=max(i,j);
      int I=min(i,j);
      if(find(all(B),2*J-I)!=B.end()) ans--;
      if(find(all(B),J-2*I)!=B.end()) ans--;
    }
  }
  cout<<ans<<endl;
  //cout<<s.size()<<endl;
}