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

int z (int x,int y){
  if (x<y){
    return y-x;
  }
  else{
    return x - y;
  }
}

int main() {
  int N;
  string str;
  cin >> N >> str;
  int64_t sum = 0;
  
  vector<int> vec_R(0);
  vector<int> vec_G(0);
  vector<int> vec_B(0);
  
  for (int i = 0; i < N; i++){
    if (str.at(i) == 'R'){
      vec_R.push_back(i);
    }
    else if (str.at(i) == 'G'){
        vec_G.push_back(i);
    }
    else {
        vec_B.push_back(i);
    }
  }
  
  for (int i : vec_R){
    for (int j : vec_G){
      for (int k : vec_B){
        if ( z(i,j) != z(j,k) && z(j,k) != z(k,i) && z(i,j) != z(k,i)){
          sum++;
        }
      }
    }
  }
  
  cout << sum <<endl;
}


