#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N;cin>>N;
  string s; cin>>s;
  vector<ll> v(N);
  ll ans = 0;
  // 変換
  rep(i,N){
    if(s[i] =='R') v[i] = 0;
    else if(s[i] =='G') v[i] = 1;
    else v[i] = 2;
  }
// まずはcount
  ll a=0,b=0,c=0;
  rep(i,N){
    if(v[i]==0) a++;
    else if(v[i]==1) b++;
    else c++;
  }
  ans += a*b*c;

  rep(i,N){
    //空間
    rep(j,N){
      //始まり
      if(j+2*i >= N) continue;
      if(v[j] != v[j+i] and v[j+i] != v[j+2*i] and v[j] != v[j+2*i]){
        ans--;
      }
    }
  }

  cout<<ans<<endl;
}
