/////////// <----------------------  Quicksilver_ ---------------------> ///////////

#include <iostream>
#include <bits/stdc++.h>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <map>
#include <iterator>
#include <iomanip>
#include <queue>
#include <utility>
#include <set>
#include <cstring>

using namespace std;
#define ll long long int
#define endl "\n"
#define c(x) ll x;cin>>x
#define cc(x,y) ll x,y;cin>>x>>y
#define ccc(x,y,z) ll x,y,z; cin>>x>>y>>z
#define db long double
#define fast cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false)
#define inf 200000000000000
#define mod 1000000007
#define eps 1e-7
#define PI 3.1415926535897932385
#define pb push_back
#define bitc  __builtin_popcountll
#define mp make_pair
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define len(x) (ll)(x).size()
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define foreach(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define print(arr,n) rep(i,n) cout<<arr[i]<<" "; cout<<endl
#define print2(arr,n,m) rep(i,n){ rep(j,m) cout<<arr[i][j]<<" "; cout<<endl; }
#define dyn1(arr,n) ll* arr=new ll[n]; rep(i,n) arr[i]=0;
#define dyn2(arr,n,m) ll** arr=new ll*[(n)]; rep(i,n) arr[i]=new ll[m]; rep(i,n) rep(j,m) arr[i][j]=0
#define carr(arr,n) rep(i,n) cin>>arr[i]
#define carr2(arr,n,m) rep(i,n) rep(j,m) cin>>arr[i][j]
#define debug(a) cout<<" :: "<<#a<<" == "<<a<<endl
#define debug2(a,b) cout<<" :: "<<#a<<" == "<<a<<" :: "<<#b<<" == "<<b<<endl
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;

inline ll maxim(ll a,ll b) {if(a>b) return a; else return b;}
inline ll minim(ll a,ll b) {if(a<b) return a; else return b;}
inline bool equals(double a, double b){ return fabs(a - b) < 1e-9; }
ll gcd(ll a, ll b){ return b==0 ? a : gcd(b, a%b); }


ll binpow(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1) res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res;
}


ll arr[1000010][2];
ll temp[1000010];
ll cost[1000010]={0};
ll mat[150][150]={0};

vector<ll> r;
vector<ll> g;
vector<ll> b;


int main()
{
  fast;
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  cout<<setprecision(10)<<fixed;
  c(n);
  string s;
  cin>>s;
  rep(o,n)
  {
    if(s[o]=='R')
    {
      r.pb(o);
    }
    else if(s[o]=='G')
    {
      g.pb(o);
    }
    else
    {
      b.pb(o);
    }
  }
  ll x=r.size();
  ll y=g.size();
  ll z=b.size();
  // cout<<"r  "<<endl;
  // rep(o,x)
  // {
  //   cout<<r[o]<<" ";
  // }
  //
  // cout<<"g  "<<endl;
  // rep(o,y)
  // {
  //   cout<<g[o]<<" ";
  // }
  //
  // cout<<"b  "<<endl;
  // rep(o,z)
  // {
  //   cout<<b[o]<<" ";
  // }

  ll elem_r=0;
  ll r_tri=0;
  r_tri=(x*(x-1)*(x-2))/6;
  ll r_temp=0;

  fr(u,0,x-1)
  {
    fr(v,u+1,x-1)
    {
      ll d=r[u];
      ll e=r[v];
      elem_r+=n-2;
      if((e-d)%2==0)
      {
        elem_r--;
        if(s[(e+d)/2]=='R') r_temp++;
      }
      if((2*e-d)<n)
      {
        elem_r--;
        if(s[(2*e-d)]=='R') r_temp++;
      }
      if((2*d-e)>=0)
      {
        elem_r--;
        if(s[(2*d-e)]=='R') r_temp++;
      }
    }
  }
  // debug(r_temp);
  r_temp/=3;
  r_tri-=r_temp;
  // debug(r_tri);
  elem_r-=2*r_tri;
  // debug(elem_r);




  ll elem_g=0;
  ll g_tri=0;
  g_tri=(y*(y-1)*(y-2))/6;
  ll g_temp=0;

  fr(u,0,y-1)
  {
    fr(v,u+1,y-1)
    {
      ll d=g[u];
      ll e=g[v];
      elem_g+=n-2;
      if((e-d)%2==0)
      {
        elem_g--;
        if(s[(e+d)/2]=='G') g_temp++;
      }
      if((2*e-d)<n)
      {
        elem_g--;
        if(s[(2*e-d)]=='G') g_temp++;
      }
      if((2*d-e)>=0)
      {
        elem_g--;
        if(s[(2*d-e)]=='G') g_temp++;
      }
    }
  }
  // debug(g_temp);
  g_temp/=3;
  g_tri-=g_temp;
  // debug(g_tri);
  elem_g-=2*g_tri;
  // debug(elem_g);





  ll elem_b=0;
  ll b_tri=0;
  b_tri=(z*(z-1)*(z-2))/6;
  ll b_temp=0;

  fr(u,0,z-1)
  {
    fr(v,u+1,z-1)
    {
      ll d=b[u];
      ll e=b[v];
      elem_b+=n-2;
      if((e-d)%2==0)
      {
        elem_b--;
        if(s[(e+d)/2]=='B') b_temp++;
      }
      if((2*e-d)<n)
      {
        elem_b--;
        if(s[(2*e-d)]=='B') b_temp++;
      }
      if((2*d-e)>=0)
      {
        elem_b--;
        if(s[(2*d-e)]=='B') b_temp++;
      }
    }
  }
  // debug(b_temp);
  b_temp/=3;
  b_tri-=b_temp;
  // debug(b_tri);
  elem_b-=2*b_tri;
  // debug(elem_b);

  //
  // fr(u,0,y-1)
  // {
  //   fr(v,u+1,y-1)
  //   {
  //     ll d=g[u];
  //     ll e=g[v];
  //     elem+=n-2;
  //     if((e-d)%2==0)
  //     {
  //       elem--;
  //     }
  //     if((2*e-d)<n)
  //     {
  //       if(s[2*e-d]=='G') elem++;
  //     }
  //
  //     if((2*e-d)<n) elem--;
  //   }
  // }
  // debug(elem);
  // fr(u,0,z-1)
  // {
  //   fr(v,u+1,z-1)
  //   {
  //     ll d=b[u];
  //     ll e=b[v];
  //     elem+=n-2;
  //     if((e-d)%2==0)
  //     {
  //       elem--;
  //     }
  //     if((2*e-d)<n)
  //     {
  //       if(s[2*e-d]=='B') elem++;
  //     }
  //     if((2*e-d)<n) elem--;
  //   }
  // }
  // debug(elem);
  ll total=(n*(n-1)*(n-2))/6;
  // debug(total);
  ll elem=elem_r+elem_g+elem_b;
  fr(diff,1,n/2) elem+=maxim(0,n-2*diff);
  total-=elem;

  cout<<total<<endl;
  return 0;
}


Measured memory_bytes: 3668