// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define add(x) accumulate(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end() 
#define rep(i, a, b) for (int i=a; i<(b); i++)
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
                string test = "RGB";
                void solve(){
                        ll n;
                        string str;
                        cin>>n>>str;
                        vector<set<ll>> vec(3);
                        for(int i=0; i<n; i++){
                                if(str[i]=='R')
                                        vec[0].insert(i);
                                else if (str[i] == 'G')
                                        vec[1].insert(i);
                                else
                                        vec[2].insert(i);
                        }
                        ll ans = 0;
                        rep(i,0,n){
                                rep(j,i+1,n){
                                        if(str[i] == str[j])
                                                continue;
                                        string fst ="";
                                        fst += str[i];
                                        fst+=str[j];
                                        sort(all(fst));
                                        if(fst=="BG"){
                                                ll cnt = vec[0].size();
                                                if(j+j-i<n && vec[0].count(j+j-i))
                                                        cnt--;
                                                if(((j-i)%2==0 )&& vec[0].count(j-(j-i)/2))
                                                        cnt--;
                                                ans+=cnt;
                                        }
                                        if(fst=="BR"){
                                                ll cnt = vec[1].size();
                                                if(j+j-i<n && vec[1].count(j+j-i))
                                                        cnt--;
                                                if(((j-i)%2==0) && vec[1].count(j-(j-i)/2))
                                                        cnt--;
                                                ans+=cnt;
                                        }
                                        if(fst=="GR"){
                                                ll cnt = vec[2].size();
                                                if(j+j-i<n && vec[2].count(j+j-i))
                                                        cnt--;
                                                if(((j-i)%2==0) && vec[2].count(j-(j-i)/2))
                                                        cnt--;
                                                ans+=cnt;
                                        }
                                        // cout<<fst<<" "<<ans;
                                }
                                if(str[i]=='R')
                                        vec[0].erase(i);
                                if(str[i]=='G')
                                        vec[1].erase(i);
                                if(str[i]=='B')
                                        vec[2].erase(i);
                        }
                        // cout<<ans<<" "<<ans/2;
                        cout<<ans/2;
                }
                int main(){ 
                        hs;
                        ll t;
                        t=1;
                        // cin>>t;
                        for (int i=1; i<=t; i++){
                                //cout<<"Case #"<<i<<": ";
                                solve();
                         }
        return 0; 
}         
 

Measured memory_bytes: 3812