#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n;
  string s;
  cin >> n >> s;
  ll ans;
  map<char, ll> m;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') m['R']++;
    if (s[i] == 'G') m['G']++;
    if (s[i] == 'B') m['B']++;
  }
  ans = m['R'] * m['G'] * m['B'];
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int k = j + j - i;
      if (k < n) {
	if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) ans--;
      }
    }
  }

  cout << ans << endl;
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> r,g,b;

    for(int i = 0; i < n; i++) {
        char x;
        cin >> x;
        if(x=='R') r.push_back(i+1);
        if(x=='G') g.push_back(i+1);
        if(x=='B') b.push_back(i+1);
    }

    ll ans = r.size()*g.size()*b.size();
    if(ans==0){
        cout << 0 << endl;
        return 0;
    }

    for(int i = 0; i < r.size(); i++) {
        for(int j = 0; j < g.size(); j++) {
            int y=lower_bound(b.begin(),b.end(),g[j]+g[j]-r[i])-b.begin();
            if(y!=b.size()){
                if(b[y]==g[j]+g[j]-r[i]) ans--;
            }
            y=lower_bound(b.begin(),b.end(),r[i]+r[i]-g[j])-b.begin();
            if(y!=b.size()){
                if(b[y]==r[i]+r[i]-g[j]) ans--;
            }

            if((r[i]+g[j])%2==0){
                y=lower_bound(b.begin(),b.end(),(r[i]+g[j])/2)-b.begin();
                if(y!=b.size()){
                if(b[y]==(r[i]+g[j])/2) ans--;
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}