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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long
#define ld long double
#define pb push_back
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD= 1e9+7 ;
const ll inf=1e18;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define put(x) cout<<#x<<" = "<<x<<endl;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}


ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n/=2;
        a=(a*a)%MOD;
    }
    return ans;
}

ll powerMod1(ll a,ll n,ll mod){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%mod;
        n>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

ll lcm(ll a,ll b){
    return a*(b/__gcd(a,b));
}

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}
ll countBit(ll a){
    ll sum=0;
    while(a){
        sum++;
        a>>=1;
    }
    return sum;
}

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}

bool isVowel(char c){
	if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u')
		return true;
	return false;
}

bool compare(string a, string b){
	if(a.length()==b.length())
		return a<b;
	return a.length()<b.length();
}

int main()
{
    fast;
    int t;
    t = 1;
    //~ cin>>t;
    
    while(t--){
		ll n;
		cin>>n;
		string s;
		cin>>s;
		ll a[n+2]={}, b[n+2]={}, c[n+2]={};
		for(int i=0;i<n;i++){
			if(s[i]=='R'){
				a[i+1]=a[i]+1;
				b[i+1]=b[i];
				c[i+1]=c[i];
			}else if(s[i]=='G'){
				a[i+1]=a[i];
				b[i+1]=b[i]+1;
				c[i+1]=c[i];
			}else{
				a[i+1]=a[i];
				b[i+1]=b[i];
				c[i+1]=c[i]+1;
			}
		}
		ll ans=0;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				if(s[i]==s[j] or j==n-1)
					continue;
					
				if(s[i]!='R' and s[j]!='R'){
					ll temp = a[n]-a[j];
					if(s[j+(j-i)]=='R')
						temp--;
					ans+=temp;
				}else if(s[i]!='G' and s[j]!='G'){
					ll temp = b[n]-b[j];
					if(s[j+(j-i)]=='G')
						temp--;
					ans+=temp;
				}else{
					ll temp = c[n]-c[j];
					if(s[j+(j-i)]=='B')
						temp--;
					ans+=temp;
				} 
			}
		}
		cout<<ans;
	}
    
    return 0;
}


Measured memory_bytes: 3680