#include <bits/stdc++.h>
#include <time.h>  
#define f first
#define s second
#define rep(i, l, r) for (long long i = (l); i < (r); i++)
#define repb(i, r, l) for (long long i = (r); i > (l); i--)
#define pb push_back
 
using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef deque <long long> dq;
typedef long long int lli;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull; 
const int MAX_CHAR=256;
 
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 
 
const ll mod = 1e9 + 7;
 
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
} 
 
ll nCrModp(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (ll i = 1; i <= n; i++) 
    { 
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
}
 
bool isPrime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true;  
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 

bool sortinrev(const pair<ll,string> &a,  
               const pair<ll,string> &b) 
{ 
       return (a.first > b.first); 
}
 
vl countFreq(ll arr[], ll n) 
{ 
    unordered_map<ll, ll> mp; 
    vector <ll> v;
    
    for (ll i = 0; i < n; i++) 
        mp[arr[i]]++; 
   
    for (auto x : mp) 
        v.pb(x.second);
    
    return v;
}
 
bool sortbysec(const pair<ll, ll>& a, 
               const pair<ll, ll>& b) 
{ 
    return (a.second < b.second); 
} 

ll binarySearch(ll arr[], ll l, ll r, ll x) 
{ 
    while (l <= r) 
    { 
        ll m = l + (r - l) / 2; 
        if (arr[m] == x) 
            return m; 
        if (arr[m] < x) 
            l = m + 1; 
        else
            r = m - 1; 
    }
    return -1; 
}

const ll MAXSIEVE=(1e3);
ll spf[MAXSIEVE];
void sieve() 
{ 
    spf[1] = 1; 
    for (ll i=2; i<MAXSIEVE; i++) 
        spf[i] = i; 

    for (ll i=4; i<MAXSIEVE; i+=2) 
        spf[i] = 2; 
  
    for (ll i=3; i*i<MAXSIEVE; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<MAXSIEVE; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
}

int main()
{
    
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    
    while(t--)
    {
        ll n;
        cin >> n;
        
        string str;
        cin >> str;
        
        ll gpos[n]={0};
        ll rpos[n]={0};
        ll bpos[n]={0};
        
        vl red,blue,green;
        rep(i,0,n)
        {
            if(str[i]=='G')
            {
                gpos[i]=1;
                green.pb(i);
            }
            else if(str[i]=='B')
            {
                bpos[i]=1;
                blue.pb(i);
            }
            else
            {
                rpos[i]=1;
                red.pb(i);
            }
        }
                
        ll countg[n]={0};
        ll countb[n]={0};
        ll countr[n]={0};
        
        countg[0]=gpos[0];
        countb[0]=bpos[0];
        countr[0]=rpos[0];
        rep(i,1,n)
        {
            countg[i]=countg[i-1]+gpos[i];
            countb[i]=countb[i-1]+bpos[i];
            countr[i]=countr[i-1]+rpos[i];
        }
        
        ll ans=0;
        rep(i,0,red.size())
        {
            rep(j,0,blue.size())
            {
                ans+=abs(countg[blue[j]]-countg[red[i]]);
                // cout << ans << "lol" << endl;
                if((blue[j]+red[i])%2==0)
                {
                    if(gpos[(blue[j]+red[i])/2]==1)
                        ans--;
                }
            }

        }
        
        // cout << ans << endl;
        
        rep(i,0,red.size())
        {
            rep(j,0,green.size())
            {
                
                    ans+=abs(countb[green[j]]-countb[red[i]]);
                    if((green[j]+red[i])%2==0)
                    {
                        if(bpos[(green[j]+red[i])/2]==1)
                        ans--;
                    }
            }
        }
        
                // cout << ans << endl;
        
        rep(i,0,green.size())
        {
            rep(j,0,blue.size())
            {
                    ans+=abs(countr[blue[j]]-countr[green[i]]);
                    if((blue[j]+green[i])%2==0)
                    {
                        if(rpos[(blue[j]+green[i])/2]==1)
                        ans--;
                    }
            }
        }
        
        cout << ans << endl;     
    }
}


Measured memory_bytes: 3872