#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main(){
  int N;
  string s;
  cin >> N >> s;
  long long ans = 0;
  map<char,vector<int>> M;
  for(int i = 0; i < N; ++i){
    M[s[i]].push_back(i);
  }
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < i; ++j){
      if(s[i] == s[j]) continue;
      char c = 'R';
      if(s[i] != 'G' and s[j] != 'G') c = 'G';
      if(s[i] != 'B' and s[j] != 'B') c = 'B';
      int t = lower_bound(M[c].begin(), M[c].end(), i) - lower_bound(M[c].begin(), M[c].end(), j);
      if(i%2 == j%2 and s[(i+j)/2] == c) --t;
      ans += t;
    }
  }
  cout << ans << endl;
}
