#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
ll sz(string &s){ return (ll)s.size(); }
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }



const ll MOD = 1e9+7;
 
template <ll MOD>
struct modint{
    ll x;
    modint() : x(0) {}
    modint(ll a): x((a % MOD + MOD) % MOD) {}
    
    
 
    bool operator!() const{return !x;}
 
    bool operator<(const modint &a) const{
        modint res(*this);
        return res.x < a.x;
    }
    
    bool operator>(const modint &a) const{
        modint res(*this);
        return res.x > a.x;
    }
 
    modint &operator+=(const modint &a){
        if((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator-=(const modint &a){
        if((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator*=(const modint &a){
        (x *= a.x) %= MOD;
        return *this;
    }
 
    modint &operator/=(const modint &a){
        *this *= a.inv();
        return *this;
    }
 
    modint &operator%=(const modint &a){
        x %= a.x;
        return *this;
    }
 
    modint operator-() const{ return modint(-x); }
 
    modint operator+(const modint &a) const{ return modint(*this) += a; }
    modint operator-(const modint &a) const{ return modint(*this) -= a; }
    modint operator*(const modint &a) const{ return modint(*this) *= a; }
    modint operator/(const modint &a) const{ return modint(*this) /= a; }
    modint operator%(const modint &a) const{ return modint(*this) %= a; }
    bool operator==(const modint &a) const{ return x == a.x; }
    bool operator!=(const modint &a) const{ return x != a.x; }
 
 
    modint pow(ll n) const{
        modint res(1), a(x);
        while(n > 0){
            if(n & 1) res *= a;
            a *= a;
            n /= 2;
        }
        return res;
    }
 
    modint inv() const{
        return this->pow(MOD-2);
    }
 
    friend ostream &operator<<(ostream &os, const modint &m){
        return os << m.x;
    }
 
    friend istream &operator>>(istream &is, modint &m){
        ll t;
        is >> t;
        m = modint<MOD>(t);
        return (is);
    }
    
    static ll get_mod(){ return MOD; }
};
using mint = modint<MOD>;

int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    vector<ll> vec[3];
    rep(i,0,sz(s)){
        if(s[i] == 'R') vec[0].push_back(i);
        else if(s[i] == 'G') vec[1].push_back(i);
        else vec[2].push_back(i);
    }
    ll array[3] = {0,1,2};
    string t = "RGB";
    ll ans = 0;
    do{
        rep(i,0,sz(vec[array[0]])){
            rep(j,0,sz(vec[array[1]])){
                if(vec[array[0]][i] > vec[array[1]][j]) continue;
                ll ok = sz(vec[array[2]]),ng = -1;
                while(abs(ok-ng) > 1){
                    ll mid = (ok+ng)/2;
                    if(vec[array[2]][mid] > vec[array[1]][j]) ok = mid;
                    else ng = mid;
                }
                ll temp = 2*vec[array[1]][j]-vec[array[0]][i];
                if(temp < sz(s)){
                    if(s[temp] == t[array[2]]) ans += sz(vec[array[2]]) - ok - 1;
                    else ans += sz(vec[array[2]]) - ok;
                }
                else ans += sz(vec[array[2]]) - ok;
            }
        }
        //cout << array[0] << " " << array[1] << " " << array[2] << " " << ans << endl;
    }while(next_permutation(array,array+3));

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652