#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;

#define ll signed long long

int main() {
  int N;
  string s;
  cin >> N >> s;

  ll r = 0;
  ll g = 0;
  ll b = 0;
  for (int i = 0; i < N; ++i) {
    if (s[i] == 'R') ++r;
    if (s[i] == 'G') ++g;
    if (s[i] == 'B') ++b;
  }
  if (r == 0 || g == 0 || b == 0) {
    cout << 0 << endl;
  }

  ll ans = r * g * b;

  for (int i = 1; i < N; ++i) {
    for (int j = 0; j + 2 * i < N; ++j) {
      if (s[j] != s[j + i] &&
          s[j + i] != s[j + i * 2] &&
          s[j + i * 2] != s[j]) {
        --ans;
      }
    }
  }

  cout << ans << endl;

  return 0;
}
