#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  const string str = "RGB";
  auto Get = [&](char c) {
    return find(str.begin(), str.end(), c) - str.begin();
  };
  int n;
  string s;
  cin >> n >> s;
  vector<vector<int>> sum(3, vector<int>(n, 0));
  for (int i = 0; i < n; i++) {
    int now = Get(s[i]);
    ++sum[now][i];
    if (i > 0) {
      sum[0][i] += sum[0][i - 1];
      sum[1][i] += sum[1][i - 1];
      sum[2][i] += sum[2][i - 1];
    }
  }
  auto Check = [&](char a, char b) {
    if (a == 'R' and b == 'G') return 'B';
    if (a == 'R' and b == 'B') return 'G';
    if (a == 'G' and b == 'R') return 'B';
    if (a == 'G' and b == 'B') return 'R';
    if (a == 'B' and b == 'R') return 'G';
    if (a == 'B' and b == 'G') return 'R';
  };
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (s[i] == s[j]) {
        continue;
      }
      char rem = Check(s[i], s[j]);
      int idx = Get(rem);
      int temp = sum[idx][n - 1] - sum[idx][j];
      if (s[j + (j - i)] == rem) --temp;
      res += temp;
    }
  }
  cout << res << '\n';
  return 0;
}
