#include<bits/stdc++.h>

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

int main()
{    
    

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li n;

    cin>>n;

    string s;

    cin>>s;

    vi r,g,b;

    f(i,0,n-1)
    {
        if(s[i]=='R')
            r.PB(i);
        else if(s[i]=='G')
            g.PB(i);
        else
            b.PB(i);
    }

    li ans=0;

    li R=r.size(),G=g.size(),BB=b.size();

    f(i,0,R-1)
    {
        f(j,0,G-1)
        {
            if(g[j]<=r[i])
            {
                continue;
            }

            li tp;

            tp=BB-(lower_bound(b.B,b.E,g[j]+1)-b.B);

            li diff=g[j]-r[i];

            if(g[j]+diff<n && s[g[j]+diff]=='B')
            {
                tp--;
            }

            tp=max(0ll,tp);

            ans+=tp;
        }

        f(j,0,BB-1)
        {
            if(b[j]<=r[i])
            {
                continue;
            }

            li tp;

            tp=G-(lower_bound(g.B,g.E,b[j]+1)-g.B);

            li diff=b[j]-r[i];

            if(b[j]+diff<n && s[b[j]+diff]=='G')
            {
                tp--;
            }

            tp=max(0ll,tp);

            ans+=tp;
        }
    }

    f(i,0,G-1)
    {
        f(j,0,R-1)
        {
            if(r[j]<=g[i])
            {
                continue;
            }

            li tp;

            tp=BB-(lower_bound(b.B,b.E,r[j]+1)-b.B);

            li diff=r[j]-g[i];

            if(r[j]+diff<n && s[r[j]+diff]=='B')
            {
                tp--;
            }

            tp=max(0ll,tp);

            ans+=tp;
        }

        f(j,0,BB-1)
        {
            if(b[j]<=g[i])
            {
                continue;
            }

            li tp;

            tp=R-(lower_bound(r.B,r.E,b[j]+1)-r.B);

            li diff=b[j]-g[i];

            if(b[j]+diff<n && s[b[j]+diff]=='R')
            {
                tp--;
            }

            tp=max(0ll,tp);

            ans+=tp;
        }
    }

    f(i,0,BB-1)
    {
        f(j,0,G-1)
        {
            if(g[j]<=b[i])
            {
                continue;
            }

            li tp;

            tp=R-(lower_bound(r.B,r.E,g[j]+1)-r.B);

            li diff=g[j]-b[i];

            if(g[j]+diff<n && s[g[j]+diff]=='R')
            {
                tp--;
            }

            tp=max(0ll,tp);

            ans+=tp;
        }

        f(j,0,R-1)
        {
            if(r[j]<=b[i])
            {
                continue;
            }

            li tp;

            tp=G-(lower_bound(g.B,g.E,r[j]+1)-g.B);

            li diff=r[j]-b[i];

            if(r[j]+diff<n && s[r[j]+diff]=='G')
            {
                tp--;
            }

            tp=max(0ll,tp);

            ans+=tp;
        }
    }

    cout<<ans;

    return 0;
}

Measured memory_bytes: 3668