#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll N, res = 0; cin >> N;
  string S; cin >> S;
  vector<ll> R(N+1), G(N+1), B(N+1);

  R[0] = 0;
  G[0] = 0;
  B[0] = 0;
  REP(i, N) {
    R[i+1] = R[i] + (S[i] == 'R');
    G[i+1] = G[i] + (S[i] == 'G');
    B[i+1] = B[i] + (S[i] == 'B');
  }

  REP(i, N-2)
    RNG(j, i+1, N-1) {
      if (S[i] != S[j]) {
        if (S[i] != 'R' && S[j] != 'R') {
          res += (R[N] - R[j+1]);
          res -= (j+j-i < N) && S[j+j-i] == 'R';
        }
        if (S[i] != 'G' && S[j] != 'G') {
          res += (G[N] - G[j+1]);
          res -= (j+j-i < N) && S[j+j-i] == 'G';
        }
        if (S[i] != 'B' && S[j] != 'B') {
          res += (B[N] - B[j+1]);
          res -= (j+j-i < N) && S[j+j-i] == 'B';
        }
      }
    }

  cout << res << endl;
  return 0;
}
