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

using ll = long long;
#define REP(i, n) for(int (i)=0; (i)< (n); ++i)
#define REPR(i, n) for(int (i)=(n); (i)>=0; --i)
#define FOR(i, n, m) for(int (i)=(n); (i)<(m); ++i)
constexpr int INF = 1e9;
//constexpr ll INF = 1LL << 62;
constexpr int mod = 1e9+7;

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<vector<ll>> sum(3, vector<ll>(N+1, 0));
  REP(i, N){
    if(S[i] == 'R') sum[0][i+1]++;
    if(S[i] == 'G') sum[1][i+1]++;
    if(S[i] == 'B') sum[2][i+1]++;
  }
  REP(i, 3){
    REP(j, N){
      sum[i][j+1] += sum[i][j];
    }
  }
  ll ans = 0;
  FOR(i, 1, N-1){
    int id;
    if(S[i] =='R') id = 0;
    if(S[i] =='G') id = 1;
    if(S[i] =='B') id = 2;
    REP(l, 3){
      REP(r, 3){
        if(l==r || r== id || l == id) continue;
        ans += sum[l][i] * (sum[r][N] - sum[r][i+1]);
      }
    }
    //cerr << "roop:" << i << " ans:" << ans << endl;
    FOR(w, 1, N){
      if(i-w< 0 || i+w >= N) break;
      if(!(S[i] == S[i-w] || S[i] == S[i+w]|| S[i-w]==S[i+w])){
        ans--;
      }
    }
    //cerr << "roop:" << i << " ans:" << ans << endl;
  }
  cout << ans << endl;
  return 0;
}
