#include <bits/stdc++.h>

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n; cin >> n;
  string s; cin >> s;
  ll cntr = 0, cntg = 0, cntb = 0;
  for(int i=0;i<n;++i) {
    if(s[i] == 'R') {
      cntr++;
    } else if(s[i] == 'G') {
      cntg++;
    } else {
      cntb++;
    }
  }

  ll ans = cntr * cntg * cntb;

  for(int i=0;i<n;++i) {
    for(int j=1;j<n;++j) {
      int l = i-j, r = i+j;
      if(0 <= l && r < n) {
        if(s[l] != s[i] && s[i] != s[r] && s[r] != s[l]) ans--;
      } else {
        break;
      }
    }
  }
  cout << ans << endl;
}
