#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 double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


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



