#include <iostream>
#include <string>
#include <iomanip>
#include <numeric>
#include<vector>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<char> v;
  char x;
  vector<int> red;
  vector<int> green;
  vector<int> blue;
  for(int i=0;i<N;i++){
    cin >> x;
    v.push_back(x);
    if(x=='R'){
      red.push_back(i);
    }
    else if(x=='G'){
      green.push_back(i);
    }
    else{
      blue.push_back(i);
    }
  }
  int rcount=0;
  int bcount=0;
  vector<int> greenleft;
  vector<int> greenright;
  for(int i=0;i<N;i++){
    if(v[i]=='R'){
      rcount++;
    }
    else if(v[i]=='G'){
      greenleft.push_back(rcount);
    }
  }
  vector<int> greentmp;
  for(int i=N-1;i>=0;i--){
    if(v[i]=='B'){
      bcount++;
    }
    else if(v[i]=='G'){
      greentmp.push_back(bcount);
    }
  }
  for(int i=greentmp.size()-1;i>=0;i--){
    greenright.push_back(greentmp[i]);
  }
  int MAX=0;
  for(int i=0;i<green.size();i++){
    MAX+=greenleft[i]*greenright[i];
  }
  int nocount=0;
  for(int i=0;i<green.size();i++){
    for(int j=0;j<N/2+1;j++){
      if(v[green[i]-j]=='R'&&v[green[i]+j]=='B'){
        nocount++;
      }
      if(v[green[i]-j]!='R'&&v[green[i]+j]!='R'
         &&v[green[i]-j]!='G'&&v[green[i]+j]!='G'
        &&v[green[i]-j]!='B'&&v[green[i]+j]!='B'){
        break;
      }
    }
  }
  //cout << green[0] << nocount;
  int sum=MAX-nocount;
  cout << sum;
  cout << endl;
  return 0;
}
