#include <bits/stdc++.h>
using namespace std;
using ll= long long;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()
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;}

int main(){
  ll n,rcnt=0,gcnt=0,bcnt=0,ans,J,K;
  cin >> n;
  string s;
  cin >> s;

  rep(i,0,n){
    if(s[i]=='R')rcnt++;
    if(s[i]=='G')gcnt++;
    if(s[i]=='B')bcnt++;
  }
  ans= rcnt*gcnt*bcnt;

  rep(i,0,n){
    rep(d,1,n){
      J= i+d;
      K= J+d;
      if(K>=n)break;
      if(s[i]!=s[J] && s[i]!=s[K] && s[J]!=s[K]){
        ans--;
      }
    }
  }
  cout << ans;
}
