//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//define
#define inp(X) cin>>X;
#define inp_long(X) long long X; cin>>X;
#define inp_arr(A,N) long long A[N]; for(long long int i=0;i<N;i++) {cin>>A[i];}
#define sz(A) A.size()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define endl '\n'
#define vect(A) vector<long long> A;
#define inp_vect(A,N); vect(A);for(long long i=0;i<N;i++){long long q; cin>>q; A.push_back(q);}
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long mod=(long long)(1e9+7);

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;
    x = x % p;
    while (y > 0) 
    {
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll a,ll p)
{
   return power(a,p-2,p);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}
int main()
{
    // #ifndef ONLINE_JUDGE
    //    freopen ("input.txt" , "r" , stdin);
	// 	// freopen ("OUTPUT.txt" , "w" , stdout);
	// #endif
    fio;
    ll testcase=1;
    //cin>>testcase;
    while(testcase--)
    {
        string s;
        ll n;
        cin>>n>>s;
        vector<ll> r,g,b;
        //r.pb(-1); g.pb(-1); b.pb(-1);
        forin(i,0,n-1)
        {
            if(s[i]=='G')
            {
                g.pb(i+1);
            }
            if(s[i]=='R')
            {
                r.pb(i+1);
            }
            if(s[i]=='B')
            {
                b.pb(i+1);
            }
        }
        vector<ll> gen;
        ll ans=r.size()*b.size()*g.size();
        if(ans)
        {
          forin(i,0,r.size()-1)
          {
              forin(j,0,g.size()-1)
              {
                  bool check=false;
                  ll num=r[i]+g[j];
                  if(num%2)
                  {

                  }
                  else
                  {
                      num/=2;
                      if(num>=1 && num<=n)
                      {
                          if(s[num-1]=='B')
                          {
                              ans--;
                          }
                      }
                  }
                  num=2*max(r[i],g[j])-min(r[i],g[j]);
                 if(num>=1 && num<=n)
                      {
                          if(s[num-1]=='B')
                          {
                              ans--;
                          }
                      }
                  num=2*min(r[i],g[j])-max(r[i],g[j]);
                  if(num>=1 && num<=n)
                      {
                          if(s[num-1]=='B')
                          {
                              ans--;
                          }
                      }
              }
          }
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3724