#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  long a = 0, b = 0, c = 0;
  long ans;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'G') {
      ++a;
    } else if (s[i] == 'R') {
      ++b;
    } else {
      ++c;
    }
  }
  ans = a * b * c;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (s[i] == s[j]) {
        continue;
      }
      int k = 2 * j - i;
      if (k >= n || s[j] == s[k] || s[k] == s[i]) {
        continue;
      }
      --ans;
    }
  }
  cout << ans << "\n";
  return 0;
}
