#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

int main()
{
  uint64_t N;
  cin >> N;

  string S;
  cin >> S;
  
  set<uint64_t> R, G, B;
  N_TIMES(n, N) {
    switch(S[n]) {
    case 'R': R.insert(n); break;
    case 'G': G.insert(n); break;
    case 'B': B.insert(n); break;
    }
  }
  
  vector<set<uint64_t>> GB(N), BG(N), BR(N), RB(N), GR(N), RG(N);
  for (auto itr_g = G.begin(); itr_g != G.end(); ++itr_g) {
    uint64_t i = *itr_g;
    for (auto itr_b = B.upper_bound(i); itr_b != B.end(); ++itr_b) {
      uint64_t j = *itr_b;
      GB[i].insert(j - i);
    }
  }
  for (auto itr_b = B.begin(); itr_b != B.end(); ++itr_b) {
    uint64_t i = *itr_b;
    for (auto itr_g = G.upper_bound(i); itr_g != G.end(); ++itr_g) {
      uint64_t j = *itr_g;
      BG[i].insert(j - i);
    }
  }
  for (auto itr_b = B.begin(); itr_b != B.end(); ++itr_b) {
    uint64_t i = *itr_b;
    for (auto itr_r = R.upper_bound(i); itr_r != R.end(); ++itr_r) {
      uint64_t j = *itr_r;
      BR[i].insert(j - i);
    }
  }
  for (auto itr_r = R.begin(); itr_r != R.end(); ++itr_r) {
    uint64_t i = *itr_r;
    for (auto itr_b = B.upper_bound(i); itr_b != B.end(); ++itr_b) {
      uint64_t j = *itr_b;
      RB[i].insert(j - i);
    }
  }
  for (auto itr_g = G.begin(); itr_g != G.end(); ++itr_g) {
    uint64_t i = *itr_g;
    for (auto itr_r = R.upper_bound(i); itr_r != R.end(); ++itr_r) {
      uint64_t j = *itr_r;
      GR[i].insert(j - i);
    }
  }
  for (auto itr_r = R.begin(); itr_r != R.end(); ++itr_r) {
    uint64_t i = *itr_r;
    for (auto itr_g = G.upper_bound(i); itr_g != G.end(); ++itr_g) {
      uint64_t j = *itr_g;
      RG[i].insert(j - i);
    }
  }
  
  vector<uint64_t> GBS(N + 1, 0), BGS(N + 1, 0), BRS(N + 1, 0), RBS(N + 1, 0), GRS(N + 1, 0), RGS(N + 1, 0);
  N_TIMES(i, N) {
    GBS[i + 1] = GB[i].size() + GBS[i];
    BGS[i + 1] = BG[i].size() + BGS[i];
    BRS[i + 1] = BR[i].size() + BRS[i];
    RBS[i + 1] = RB[i].size() + RBS[i];
    GRS[i + 1] = GR[i].size() + GRS[i];
    RGS[i + 1] = RG[i].size() + RGS[i];
  }

  uint64_t T = 0;
  N_TIMES(i, N) {
    switch(S[i]) {
    case 'R':
      {
        uint64_t t1 = 0;
        for (uint64_t j = i + 1; j < N; ++j) {
          if (GB[j].find(j - i) != GB[j].end()) { ++t1; }
        }
        T += (GBS[N] - GBS[i]) - t1;

        uint64_t t2 = 0;
        for (uint64_t j = i + 1; j < N; ++j) {
          if (BG[j].find(j - i) != BG[j].end()) { ++t2; }
        }
        T += (BGS[N] - BGS[i]) - t2;
      }
      break;
    case 'G':
      {
        uint64_t t1 = 0;
        for (uint64_t j = i + 1; j < N; ++j) {
          if (BR[j].find(j - i) != BR[j].end()) { ++t1; }
        }
        T += (BRS[N] - BRS[i]) - t1;

        uint64_t t2 = 0;
        for (uint64_t j = i + 1; j < N; ++j) {
          if (RB[j].find(j - i) != RB[j].end()) { ++t2; }
        }
        T += (RBS[N] - RBS[i]) - t2;
      }
      break;
    case 'B':
      {
        uint64_t t1 = 0;
        for (uint64_t j = i + 1; j < N; ++j) {
          if (GR[j].find(j - i) != GR[j].end()) { ++t1; }
        }
        T += (GRS[N] - GRS[i]) - t1;

        uint64_t t2 = 0;
        for (uint64_t j = i + 1; j < N; ++j) {
          if (RG[j].find(j - i) != RG[j].end()) { ++t2; }
        }
        T += (RGS[N] - RGS[i]) - t2;
      }
      break;
    }
  }
  cout << T << endl;

  return 0;
}

Measured memory_bytes: 254748