#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  string s;
  cin >> n >> s;
  vector<int> R(n+1,0),G(n+1,0),B(n+1,0);
  for (int i = n-1; i >= 0; --i) {
    if (s[i] == 'R') R[i]++;
    if (s[i] == 'G') G[i]++;
    if (s[i] == 'B') B[i]++;
    R[i] += R[i+1];
    G[i] += G[i+1];
    B[i] += B[i+1];
  }
  ll ans = 0;
  auto f = [&](char si, char sj, int idx) {
    char tempi = si, tempj = sj;
    if (tempi - 'A' > tempj - 'A') swap(tempi,tempj); 
    if (tempi == 'B' && tempj == 'G') return R[idx];
    else if (tempi == 'B' && tempj == 'R') return G[idx];
    else return B[idx];
  };
  auto g = [&](char si, char sj) {
    char tempi = si, tempj = sj;
    if (tempi - 'A' > tempj - 'A') swap(tempi,tempj); 
    if (tempi == 'B' && tempj == 'G') return 'R';
    else if (tempi == 'B' && tempj == 'R') return 'G';
    else return 'B';
  };
  for (int i = 0; i <= n-3; ++i) {
    for (int j = i+1; j <= n-2; ++j) {
      if (s[i] == 'R') {
        if (s[j] == 'G' || s[j] == 'B') {
          ans += f(s[i], s[j], j+1);
          if (s[j+j-i] == g(s[i], s[j])) ans--; //j-i = k-jのとき
        }
      }
      else if (s[i] == 'G') {
        if (s[j] == 'R' || s[j] == 'B') {
          ans += f(s[i], s[j], j+1);
          if (s[j+j-i] == g(s[i], s[j])) ans--; //j-i = k-jのとき
        }
      }
      else if (s[i] == 'B') {
        if (s[j] == 'R' || s[j] == 'G') {
          ans += f(s[i], s[j], j+1);
          if (s[j+j-i] == g(s[i], s[j])) ans--; //j-i = k-jのとき
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}