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

long long n, cnt[3] = {};
string rgb = "RGB", s;

long long solve();

int main() {
  cin >> n >> s;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 3; ++j)
      if (s[i] == rgb[j]) ++cnt[j];
  res = cnt[0] * cnt[1] * cnt[2];
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j) {
      int k = 2 * j - i;
      if (k >= n) continue;
      if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) --res;
    }
  return res;
}
