#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

ll check(ll x,ll y,ll z){
    ll cnt=0;
    ll a[3]={x,y,z};
    sort(a,a+3);
    
    do{
        if(a[0]<a[1] && a[1]<a[2] && ((a[1]-a[0])!=(a[2]-a[1]))){cnt++;}
    }while(next_permutation(a,a+3));
    return cnt;
}
int main(){
    IOS;
    ll n;cin>>n;
    string s;cin>>s;
    vector<ll>a,b,c;
    f(i,0,s.size()){
        if(s[i]=='R')a.pb(i);
        else if(s[i]=='G')b.pb(i);
        else c.pb(i);
    }
    ll sum=0;
    f(i,0,a.size()){
        f(j,0,b.size()){
            f(k,0,c.size()){
                sum+=(check(a[i],b[j],c[k]));
            }
        }
    }
    cout<<sum;
    return 0;  
} 



