#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for (int i = 0; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
using ll = int64_t;
using v = vector<int>;

int main() {

  string S;
  int N;
  in(N);
  in(S);
  
  int rn=0, gn=0, bn=0;
  rep(i,N) {
    if (S.at(i)=='R') {
      rn++;
    }
    else if (S.at(i)=='G') {
      gn++;
    }
    else {
      bn++;
    }
  }
  ll ans = rn*gn*bn;
  ll hiku = 0;
  if(N<3) cout << ans << endl;
  else {
    for(int i = 0; i<N-2; i++) {
      for(int j = i+1; j<N-1; j++) {
        int k = 2*j-i;
        if(k>=N) continue;
        if(S.at(i)!=S.at(j) && S.at(i)!=S.at(k) && S.at(j)!=S.at(k)) {
          hiku++;
        }
      }
    }
    out(ans-hiku);
  }
}