/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 4003
#define mod 1000000007
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) cout<<"Case #"<<i<<": "
#define pf(a) printf("%lld\n",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define pfff(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define pffff(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp1,mp;
vector<pair<ll,pair<ll,ll> > >vpp,vpp1;
vector<pair<ll,ll> >v,vp,fin;
vector<ll>v1,v2,dummy;
map<pair<ll,ll>,bool>mbb;
map<ll,bool>mb;
ll n,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,maxi;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
ll rrr[MAX+10],grr[MAX+10],brr[MAX+10],gra[MAX+10],rra[MAX+10],bra[MAX+10];
ll solve(string s,ll n)
{
    ll cnt=0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=i+1;j<n;j++)
        {
            ll x=(j+i)/2;
            ll y=(j-i);
            if(y%2==0)
            {
                if(s[x]!=s[i] and s[i]!=s[j] and s[j]!=s[x]) cnt++;
            }
        }
    }
    return cnt;
}
void calc(string s,ll n)
{
    ///cout<<s<<" "<<n<<endl;
    memset(rrr,0,sizeof rrr);
    memset(rra,0,sizeof rra);
    memset(brr,0,sizeof brr);
    memset(bra,0,sizeof bra);
    memset(grr,0,sizeof grr);
    memset(gra,0,sizeof gra);
    FOR1(i,n)
    {
        if(s[i-1]=='R') rrr[i]+=rrr[i-1]+1;
        else rrr[i]=rrr[i-1];
        if(s[i-1]=='G') grr[i]+=grr[i-1]+1;
        else grr[i]=grr[i-1];
        if(s[i-1]=='B') brr[i]+=brr[i-1]+1;
        else brr[i]=brr[i-1];
    }
    /*RFOR1(i,n){
        if(s[i-1]=='R') rra[i]+=rra[i+1]+1;
        else rra[i]=rra[i+1];
        if(s[i-1]=='G') gra[i]+=gra[i+1]+1;
        else gra[i]=gra[i+1];
        if(s[i-1]=='B') bra[i]+=bra[i+1]+1;
        else bra[i]=bra[i+1];
    }
    FOR1(i,n) cout<<rrr[i]<<" ";
    cout<<endl;
    FOR1(i,n) cout<<grr[i]<<" ";
    cout<<endl;
    FOR1(i,n) cout<<brr[i]<<" ";
    cout<<endl;
    ll sum=0;*/
    FOR(i,n)
    {
        if(s[i]=='R')
        {
            ll x=grr[i+1];
            ll y=brr[i+1];
            ///ll rx=gra[i+1];
            ///ll ry=bra[i+1];
            sum+=(x*y);
           /// sum+=((x*y)+(rx*ry));
        }
        if(s[i]=='G')
        {
            ll x=rrr[i+1];
            ll y=brr[i+1];
            ///ll rx=rra[i+1];
            ///ll ry=bra[i+1];
            sum+=(x*y);
            ///sum+=((x*y)+(rx*ry));
        }
        if(s[i]=='B')
        {
            ll x=grr[i+1];
            ll y=rrr[i+1];
            ///ll rx=gra[i+1];
            ///ll ry=rra[i+1];
            sum+=(x*y);
            ///sum+=((x*y)+(rx*ry));
        }
    }
    ///cout<<sum<<" "<<solve(s,n)<<endl;
    cout<<sum-solve(s,n)<<endl;
}

int main()
{
    fast;
    ///cin>>ta;
    //FOR(test,ta)
    //{
    ///solve();
    string s;
    cin>>n>>s;
    ///ll n=s.size();
    calc(s,n);
    return 0;
}


Measured memory_bytes: 3840