#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()

int main() {
  string s;
  int n;
  ll ans = 0;
  vector<int> r, g, b;
  cin >> n >> s;
  rep(i, n) {
    if (s.at(i) == 'R') {
      r.push_back(i);
    }
    if (s.at(i) == 'G') {
      g.push_back(i);
    }
    if (s.at(i) == 'B') {
      b.push_back(i);
    }
  }
  for (int i = 0; i < r.size(); i++) {
    for (int j = 0; j < g.size(); j++) {
      for (int k = 0; k < b.size(); k++) {
        int x, y, z;
        x = min(min(r.at(i), g.at(j)), b.at(k));
        y = max(max(r.at(i), g.at(j)), b.at(k));
        z = r.at(i) + g.at(j) + b.at(k) - x - y;
        if (2 * z != x + y) ans++;
      }
    }
  }
  cout << ans << endl;
}