#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define fi first
#define se second

using Graph = vector<vector<int>>;




int main() {
    ll n;
    cin>>n;
    string s;
    cin>>s;

    vector<int>R(n,0);
    vector<int>G(n,0);
    vector<int>B(n,0);
    ll r,g,b = 0;
    for(int i=0;i<n;i++){
        if(s[i]=='R'){
            r++;
            R[i]=r;
            G[i]=g;
            B[i]=b;
        }
        if(s[i]=='G'){
            g++;
            R[i]=r;
            G[i]=g;
            B[i]=b;
        }
        if(s[i]=='B'){
            b++;
            R[i]=r;
            G[i]=g;
            B[i]=b;
        }
    }
    ll ans=0;

    // for(int i=0;i<n;i++){
    //     cout<<G[i]<<endl;
    // }


    for(ll j=1;j<n-1;j++){
        if(s[j]=='R'){
            ans+=(G[j-1] * (B[n-1]-B[j]));
            ans+=(B[j-1] * (G[n-1]-G[j]));
            for(ll i=1;i<=min(j,n-j-1);i++){
                if((s[j-i]=='B' && s[j+i]=='G') || (s[j-i]=='G' && s[j+i]=='B')){
                    ans--;
                }
            }
        }

        if(s[j]=='G'){
            ans+=(B[j-1] * (R[n-1]-R[j]));
            // cout<<ans<<endl;
            ans+=(R[j-1] * (B[n-1]-B[j]));
            // cout<<ans<<endl;
            for(ll i=1;i<=min(j,n-j-1);i++){
                if((s[j-i]=='B' && s[j+i]=='R') || (s[j-i]=='R' && s[j+i]=='B')){
                    ans--;
                }
            }
        }

        if(s[j]=='B'){
            ans+=(R[j-1] * (G[n-1]-G[j]));
            ans+=(G[j-1] * (R[n-1]-R[j]));
            for(ll i=1;i<=min(j,n-j-1);i++){
                if((s[j-i]=='G' && s[j+i]=='R') || (s[j-i]=='R' && s[j+i]=='G')){
                    ans--;
                }
            }
        }
        // cout<<"ans="<<ans<<endl;
    }

    cout<<ans<<endl;





    return 0;
}
