#include<bits/stdc++.h>
using namespace std;


int int_count(vector<int>& a,int x, int y){
  //return number of numbers in interval [x,y]

  int n = a.size();
  int low = 0;
  int high = n-1;

  int index1 = high + 1;//index of value which is greater than or equal to x+1
  while(low <= high){
    int mid = low + (high - low) / 2;
    if(a[mid] >= x){
      index1 = min(index1,mid);
      high = mid - 1;
    }
    else{
      low = mid + 1;
    }
  }

  low = 0;
  high = n-1;
  int index2 = -1;//index of greatest value which is less than or equal to y-1
  while(low <= high){
    int mid = low + (high - low) / 2;
    if(a[mid] <= y){
      index2 = max(index2,mid);
      low = mid + 1;
    }
    else{
      high = mid - 1;
    }
  }

//cout<<"i1: "<<index1<<" i2: "<<index2<<endl;
  if(index2 < index1)
    return 0;

  return index2 - index1 + 1;
}

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  
  vector<int> R;
  vector<int> B;
  vector<int> G;
  
  for(int i =0;i < n;i++)
    if(s[i] == 'R')
      R.push_back(i+1);
  	else if(s[i] == 'G')
      G.push_back(i+1);
  	else
      B.push_back(i+1);

  
  
  long long int ans = 0;
  //i is R j is G k is B
  for(auto i = R.begin();i != R.end(); i++){
    for(auto k = G.begin(); k != G.end();k++){
      if(*k > *i){
        //find number of numbers between i + 1 & k - 1 (inclusive)
        ans += int_count(B,*i+1,*k-1);
        if((*k + *i) % 2 == 0)
        	if(binary_search(B.begin(),B.end(),(*k + *i) / 2))
              ans--;
      }
    }
  }
  //==================================
  //i is R j is B k is G
  for(auto i = R.begin();i != R.end(); i++){
    for(auto k = B.begin(); k != B.end();k++){
      if(*k > *i){
        //find number of numbers between i + 1 & k - 1 (inclusive)
        ans += int_count(G,*i+1,*k-1);
        if((*k + *i) % 2 == 0)
        	if(binary_search(G.begin(),G.end(),(*k + *i) / 2))
              ans--;
      }
    }
  }
  //============================================
  
  //i is G j is R k is B
  for(auto i = G.begin();i != G.end(); i++){
    for(auto k = R.begin(); k != R.end();k++){
      if(*k > *i){
        //find number of numbers between i + 1 & k - 1 (inclusive)
        ans += int_count(B,*i+1,*k-1);
        
        if((*k + *i) % 2 == 0)
        	if(binary_search(B.begin(),B.end(),(*k + *i) / 2))
              ans--;
      }
    }
  }
  //==================================
  //i is G j is B k is R
  for(auto i = G.begin();i != G.end(); i++){
    for(auto k = B.begin(); k != B.end();k++){
      if(*k > *i){
        //find number of numbers between i + 1 & k - 1 (inclusive)
        ans += int_count(R,*i+1,*k-1);
        
        if((*k + *i) % 2 == 0)
        	if(binary_search(R.begin(),R.end(),(*k + *i) / 2))
              ans--;
      }
    }
  }
  //============================================
  
  //i is B j is G k is R
  for(auto i = B.begin();i != B.end(); i++){
    for(auto k = G.begin(); k != G.end();k++){
      if(*k > *i){
        //find number of numbers between i + 1 & k - 1 (inclusive)
        ans += int_count(R,*i+1,*k-1);
        
        if((*k + *i) % 2 == 0)
        	if(binary_search(R.begin(),R.end(),(*k + *i) / 2))
              ans--;
      }
    }
  }
  //==================================
  //i is B j is R k is G
  for(auto i = B.begin();i != B.end(); i++){
    for(auto k = R.begin(); k != R.end();k++){
      if(*k > *i){
        //find number of numbers between i + 1 & k - 1 (inclusive)
       ans += int_count(G,*i+1,*k-1);
        if((*k + *i) % 2 == 0)
        	if(binary_search(G.begin(),G.end(),(*k + *i) / 2))
              ans--;
      }
    }
  }
  //============================================
  
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 3624