#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <typeinfo>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T>
using Tree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;  // check the limits, dummy

typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
void print(const vector<T> v) {
  cout << "[ ";
  F0R(i, v.size()) { cout << v[i] << ' '; }
  cout << "]" << '\n';
}

int mod(int i, int j) {
  return (i % j) < 0 ? (i % j) + 0 + (j < 0 ? -j : j) : (i % j + 0);
}

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if (a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

int middleOfThree(int a, int b, int c) {
  // Checking for b
  if ((a < b && b < c) || (c < b && b < a)) return b;

  // Checking for a
  else if ((b < a && a < c) || (c < a && a < b))
    return a;

  else
    return c;
}

int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) {  // 発見できたとき
    return 1;
  } else {  // 発見できなかったとき
    return 0;
  }
}
// --------------------------------------------------------
// This is tool
// --------------------------------------------------------
void Main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int N, a, b, c;
  string S;
  cin >> N;
  cin >> S;
  vi R, G, B;
  FOR(i, 0, N) {
    switch (S[i]) {
      case 'R':
        R.push_back(i);
        break;
      case 'G':
        G.push_back(i);
        break;
      case 'B':
        B.push_back(i);
        break;
    }
  }
  // cout << R.size() << endl;
  // cout << G.size() << endl;
  // cout << B[0] << endl;

  ll sum = 0;
  FOR(i, 0, R.size()) {
    FOR(j, 0, G.size()) {
      int ma = max(R[i], G[j]);
      int mi = min(R[i], G[j]);
      int sa = ma - mi;
      int x = mi - sa;
      int y = ma + sa;
      if ((ma + mi) % 2 == 0) {
        int z = (ma + mi) / 2;
        sum += B.size() - vector_finder(B, x) - vector_finder(B, y) -
               vector_finder(B, z);
      } else {
        sum += B.size() - vector_finder(B, x) - vector_finder(B, y);
      }
    }
  }
  cout << sum << endl;
}

// cout << sum << endl;

// a = 1;
// b = 2;
// int ma = max(a, b);
// int mi = min(a, b);
// int sa = ma - mi;
// int x = mi - sa;
// int y = ma + sa;
// cout << x << ":" << y << endl;
// // 下側
// cout << vector_finder(B, x) << endl;
// // 上側
// cout << vector_finder(B, y) << endl;

// cout << middleOfThree(1, 2, 4) << endl;
// cout << max({1, 2, 4}) << endl;
// cout << min({1, 2, 4}) << endl;

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
}

Measured memory_bytes: 3672