// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 04/16/20 07:31:34
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);

  int n; cin>>n;
  string s; cin>>s;
  int cnt[3] = {};
  map<char, int> cmap;
  cmap['R']=0;
  cmap['G']=1;
  cmap['B']=2;
  for (auto c:s)
    cnt[cmap[c]]++;
  ll ans = cnt[0]*cnt[1]*cnt[2];
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      int k = j+j-i;
      if (k >= n) continue;
      if (s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k])
        ans--;
    }
  }
  cout << ans << endl;

  return 0;
}
