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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent
ll n;
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    string s;
    cin>>n;
    cin>>s;
    vector<int> r,g,b;
    rep(i,n)
    {
        if(s[i]=='R') r.pb(i);
        if(s[i]=='G') g.pb(i);
        if(s[i]=='B') b.pb(i);
    }
    ll ans=0;
    ll rsz,gsz,bsz;
    rsz=r.size();
    gsz=g.size();
    bsz=b.size();
    rep(i,rsz)
    {
        rep(j,gsz)
        {
            if(g[j] <= r[i]) continue;
            ll diff=g[j]-r[i];
            auto k=upper_bound(b.begin(),b.end(),g[j]);
            if(k!=b.end())
            {
                ll numallow= b.end()-k;
                auto rem=find(k,b.end(),2*g[j]-r[i]);
                if(rem!= b.end()) ans+=(numallow-1);
                else ans+=(numallow);
            }
        }
        rep(j,bsz)
        {
            if(b[j] <= r[i]) continue;
            ll diff=b[j]-r[i];
            auto k=upper_bound(g.begin(),g.end(),b[j]);
            if(k!=g.end())
            {
                ll numallow= g.end()-k;
                auto rem=find(k,g.end(),2*b[j]-r[i]);
                if(rem!= g.end()) ans+=(numallow-1);
                else ans+=(numallow);
            }
        }
    }
    rep(i,bsz)
    {
        rep(j,gsz)
        {
            if(g[j] <= b[i]) continue;
            ll diff=g[j]-b[i];
            auto k=upper_bound(r.begin(),r.end(),g[j]);
            if(k!=r.end())
            {
                ll numallow= r.end()-k;
                auto rem=find(k,r.end(),2*g[j]-b[i]);
                if(rem!= r.end()) ans+=(numallow-1);
                else ans+=(numallow);
            }
        }
        rep(j,rsz)
        {
            if(r[j] <= b[i]) continue;
            ll diff=r[j]-b[i];
            auto k=upper_bound(g.begin(),g.end(),r[j]);
            if(k!=g.end())
            {
                ll numallow= g.end()-k;
                auto rem=find(k,g.end(),2*r[j]-b[i]);
                if(rem!= g.end()) ans+=(numallow-1);
                else ans+=(numallow);
            }
        }
    }
    rep(i,gsz)
    {
        rep(j,rsz)
        {
            if(r[j] <= g[i]) continue;
            ll diff=r[j]-g[i];
            auto k=upper_bound(b.begin(),b.end(),r[j]);
            if(k!=b.end())
            {
                ll numallow= b.end()-k;
                auto rem=find(k,b.end(),2*r[j]-g[i]);
                if(rem!= b.end()) ans+=(numallow-1);
                else ans+=(numallow);
            }
        }
        rep(j,bsz)
        {
            if(b[j] <= g[i]) continue;
            ll diff=b[j]-g[i];
            auto k=upper_bound(r.begin(),r.end(),b[j]);
            if(k!=r.end())
            {
                ll numallow= r.end()-k;
                auto rem=find(k,r.end(),2*b[j]-g[i]);
                if(rem!= r.end()) ans+=(numallow-1);
                else ans+=(numallow);
            }
        }
    }

    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 3688