#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


ll gcd(ll x, ll y){
  if(x%y==0)return y;
  return gcd(y,x%y);
}
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n;
  string s;
  cin >> n >> s;
  vector<int>r(n+1);
  vector<int>g(n+1);
  vector<int>b(n+1);
  r[0]=g[0]=b[0]=0;
  
  rep(i,n){
    if(s[i]=='R'){
      r[i+1]=r[i]+1;
      g[i+1]=g[i];
      b[i+1]=b[i];
    }
    if(s[i]=='G'){
      r[i+1]=r[i];
      g[i+1]=g[i]+1;
      b[i+1]=b[i];
    }
    if(s[i]=='B'){
      r[i+1]=r[i];
      g[i+1]=g[i];
      b[i+1]=b[i]+1;
    }
  }
  ll ans=0;
  rep(i,n-2){
    for(int k=i+2;k<n;k++){
      if((i+k)%2==0 && s[i]!=s[(i+k)/2] && s[(i+k)/2]!=s[k] && s[k]!=s[i])ans--;
        if(s[i]=='R' && s[k]=='G'){
          ans+=b[k]-b[i+1];
        }
        if(s[i]=='G' && s[k]=='B'){
          ans+=r[k]-r[i+1];
        }
        if(s[i]=='B' && s[k]=='R'){
          ans+=g[k]-g[i+1];
        }
        if(s[i]=='R' && s[k]=='B'){
          ans+=g[k]-g[i];
        }
        if(s[i]=='G' && s[k]=='R'){
          ans+=b[k]-b[i+1];
        }
        if(s[i]=='B' && s[k]=='G'){
          ans+=r[k]-r[i+1];
        }
      
    }
  }
  cout << ans << endl;
}
