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

int main() {
  int n;
  cin >> n;
  char str[n];
  vector<set<int>> colors(3);
  for (int i = 0; i < n; ++i) {
    cin >> str[i];
    if (str[i] == 'R') colors[0].insert(i);
    else if (str[i] == 'G') colors[1].insert(i);
    else colors[2].insert(i);
  }
  long long ans(0);
  int i(0), j(1), k(2);
      for (int ii: colors[i]) {
        for (int ij: colors[j]) {
          int diff = abs(ii - ij);
          int mn = min(ii, ij);
          int mx = max(ii, ij);
          int c(0);
          if (diff % 2 == 0 && colors[k].count(mn + diff / 2)) {
            c--;
          }
          if (colors[k].count(mx + diff)) c--;
          if (colors[k].count(mn - diff)) c--;
          ans += (long long) colors[k].size() + c;
        }
      }
  cout << ans << '\n';
  return 0;
}