#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;

ll count(vector<int> &R, vector<int> &G, vector<int> &B) {
  ll sum = 0;
  for (int i = 0; i < R.size(); i ++) {
    for (int j = 0; j < G.size(); j ++) {
      if (R[i] > G[j]) {
        continue;
      }
      int a = G[j] - R[i];
      for (int k = 0; k < B.size(); k ++) {
        if (G[j] > B[k]) {
          continue;
        }
        if (a == B[k] - G[j]) {
          continue;
        }
        sum ++;
      }
    }
  }
  return sum;
}

int main() {
  int N;
  char S;
  vector<int> R, G, B;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> S;
    if (S == 'R') {
      R.push_back(i);
    } else if(S == 'G') {
      G.push_back(i);
    } else if(S == 'B') {
      B.push_back(i);
    }
  }
  ll sum = 0;
  sum += count(R, B, G);
  sum += count(R, G, B);
  sum += count(B, R, G);
  sum += count(B, G, R);
  sum += count(G, R, B);
  sum += count(G, B, R);
  cout << sum << endl;
  return 0;
}