#include <bits/stdc++.h>

// #define fi first
// #define se second
#define rep(i, n) for (ll i=0;i<(n); i++)
#define ALL(v) (v).begin(), (v).end()
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
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 (a>b) { a=b; return 1; } return 0; }

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

const ll M=1000000007ll;
const ll MOD=1000000007ll;
const ll MAX=100000001ll;
//const ll M = 1000000000+7;

ll cnt = 0; 

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(ll n){
  if(n==0) return 1;
  mint ans = f(n/2);
  ans *= ans;
  if(n%2==1) ans*= 2;
  return ans;
}

mint choose(ll n, ll k){
  mint x=1, y=1;
  rep(i,k){
    x *= (n-i);
    y *= (i+1);
  }
  return x / y;
}

struct BIT {
  private:
   vector<ll> bit;
   ll N;
 
  public:
   BIT(ll size) {
     N = size;
     bit.resize(N + 1);
   }
 
   // 一点更新です
   void add(ll a, ll w) {
     for (ll x = a; x <= N; x += x & -x) bit[x] += w;
   }
 
   // 1~Nまでの和を求める。
   int sum(ll a) {
     ll ret = 0;
     for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
     return ret;
   }
 };
 

int main(){ 
  ll n;
  cin>> n;

  string s;
  cin>>s;

  vector<ll> r(n, 0);
  vector<ll> g(n, 0);
  vector<ll> b(n, 0);

  vector<ll> sr(n, 0);
  vector<ll> sg(n, 0);
  vector<ll> sb(n, 0);

  rep(i, n){
    if(s[i]=='R'){
      r[i] = 1;
      sr[i]=1;
    }
    if(s[i]=='G'){
      g[i] = 1;
      sg[i]=1;
    }
    if(s[i]=='B'){
      b[i] = 1;
      sb[i]=1;
    }
  }

  rep(i, n-1){
    sr[i+1] += sr[i]; 
    sg[i+1] += sg[i]; 
    sb[i+1] += sb[i]; 
  }

  ll ans =0;
  rep(i, n-2){
    if(r[i] == 1){
      rep(jj, n-i-2){
	ll j = i+1+jj;
	if(g[j]==1){
	  ans += sb[n-1] - sb[j];
	  if(j+(j-i)<n){
	    if(b[j+(j-i)]==1) ans--;
	  }
	}
	if(b[j]==1){
	  ans += sg[n-1] - sg[j];
	  if(j+(j-i)<n){
	    if(g[j+(j-i)]==1) ans--;
	  }
	}
      }
    }

    if(g[i] == 1){
      rep(jj, n-i-1){
	ll j = i+1+jj;
	if(r[j]==1){
	  ans += sb[n-1] - sb[j];
	  if(j+(j-i)<n){
	    if(b[j+(j-i)]==1) ans--;
	  }
	}
	if(b[j]==1){
	  ans += sr[n-1] - sr[j];
	  if(j+(j-i)<n){
	    if(r[j+(j-i)]==1) ans--;
	  }
	}
      }
    }

    if(b[i] == 1){
      rep(jj, n-i-1){
	ll j = i+1+jj;
	if(g[j]==1){
	  ans += sr[n-1] - sr[j];
	  if(j+(j-i)<n){
	    if(r[j+(j-i)]==1) ans--;
	  }
	}
	if(r[j]==1){
	  ans += sg[n-1] - sg[j];
	  if(j+(j-i)<n){
	    if(g[j+(j-i)]==1) ans--;
	  }
	}
      }
    }


    
  }
  
  cout << ans << endl;
 
  
}


Measured memory_bytes: 3756