#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define pp pair<ll,ll>
#define vi vector<pair<pp,pp> >
#define pq_min priority_queue<ll,vector<ll>,greater<ll>>
#define pq_max priority_queue<ll>
#define f(i,a,b) for(ll i=a;i<b;i++)
#define r(i,a,b) for(ll i=b-1;i>=a;i--)
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define ld long double
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef pair<pp,pp> ppll;
const ll mod=1e9 +7;
const ll N = 1e12 + 5 ;
ll ans=0;

ll power(ll a,ll b)
{
    ll res=1;
    a%=mod;
    while(b>0)
    {
        if(b%2==1)
        {
            res = (res * a)%mod;
        }
        b/=2;
        a = (a*a)%mod;
    }
    return res;
}



int main()
{
    fast;
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll p[n+1],q[n+1],r[n+1];
    p[n]=0;
    q[n]=0;
    r[n]=0;
    for(ll i=n-1;i>=0;i--)
    {
        if(s[i]=='R')
        {
           p[i] = p[i+1]+1;
           q[i] = q[i+1];
           r[i] = r[i+1];
        }
        else if(s[i]=='B')
        {
           p[i] = p[i+1];
           q[i] = q[i+1]+1;
           r[i] = r[i+1];
        }
        else
        {
           p[i] = p[i+1];
           q[i] = q[i+1];
           r[i] = r[i+1]+1;
        }
    }
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        if(s[i]=='R')
        {
            for(ll j=i+1;j<n;j++)
            {
                if(s[j]=='B')
                {
                    ll h = j + (j-i);
                    if(j+1<n)
                    {
                        ll x=r[j+1];
                        if(h<n && s[h]=='G')
                        {
                           x -= 1;
                        }
                        if(x>0)
                        {
                            ans += x;
                        }
                    }
                }
                else if(s[j]=='G')
                {
                    ll h = j + (j-i);
                    if(j+1<n)
                    {
                        ll x=q[j+1];
                        if(h<n && s[h]=='B')
                        {
                           x -= 1;
                        }
                        if(x>0)
                        {
                            ans += x;
                        }
                    }
                }
            }
        }
        if(s[i]=='B')
        {
            for(ll j=i+1;j<n;j++)
            {
                if(s[j]=='R')
                {
                    ll h = j + (j-i);
                    if(j+1<n)
                    {
                        ll x=r[j+1];
                        if(h<n && s[h]=='G')
                        {
                           x -= 1;
                        }
                        if(x>0)
                        {
                            ans += x;
                        }
                    }
                }
                else if(s[j]=='G')
                {
                    ll h = j + (j-i);
                    if(j+1<n)
                    {
                        ll x = p[j+1];
                        if(h<n && s[h]=='R')
                        {
                           x -=1;
                        }
                        if(x>0)
                        {
                            ans += x;
                        }
                    }
                }
            }
        }
        if(s[i]=='G')
        {
            for(ll j=i+1;j<n;j++)
            {
                if(s[j]=='R')
                {
                    ll h = j + (j-i);
                    if(j+1<n)
                    {
                        ll x=q[j+1];
                        if(h<n && s[h]=='B')
                        {
                           x -= 1;
                        }
                        if(x>0)
                        {
                            ans += x;
                        }
                    }
                }
                else if(s[j]=='B')
                {
                    ll h = j + (j-i);
                    if(j+1<n)
                    {
                        ll x = p[j+1];
                        if(h<n && s[h]=='R')
                        {
                           x -=1;
                        }
                        if(x>0)
                        {
                            ans += x;
                        }
                    }
                }
            }
        }
    }
    cout<<ans;
}
