#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define NMAX 4002
using namespace std;
int main(){
  long long N,ans = 0;
  char S[NMAX];
  vector<int> v[3];
  cin >> N;
  for (int i = 0; i < N; ++i)
  {
    cin >> S[i];
    if(S[i] == 'R') v[0].push_back(i);
    else if(S[i] == 'G') v[1].push_back(i);
    else if(S[i] == 'B') v[2].push_back(i);
  }
  for (int i = 0; i < v[0].size(); ++i)
  {
    for (int j = 0; j < v[1].size(); ++j)
    {
      int num = 0;
      if(find(v[2].begin(), v[2].end(),(v[0][i]*2-v[1][j])) != v[2].end()) num++;
      if(find(v[2].begin(), v[2].end(),(v[1][j]*2-v[0][i])) != v[2].end()) num++;
      if(find(v[2].begin(), v[2].end(),(v[0][i]+v[1][j])/2) != v[2].end() && (v[0][i]+v[1][j])%2 == 0) num++;
      ans += v[2].size() - num;
    }
  }
  cout << ans << endl;

}