#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll n;cin>>n;
  string s;cin>>s;
  ll R=0,G=0,B=0;
  ll r[4000]={0},g[4000]={0},b[8000]={0};

  rep(i,0,n){
    if(s[i]=='R'){r[R]=i;R++;}
    else if(s[i]=='G'){g[G]=i;G++;}
    else {b[i]=1;B++;}
  }

  ll ng=0;

  rep(i,0,R){
    rep(j,0,G){
      ll ma=max(r[i],g[j]),mi=min(r[i],g[j]);
      ll dif=ma-mi;

      if(ma+dif<4000&&b[ma+dif]!=0)ng++;
      if(dif%2==0&&b[mi+dif/2]!=0)ng++;
      if(mi-dif>=0&&b[mi-dif]!=0)ng++;
    }
  }

  out(R*G*B-ng);

  return 0;
}
