    #include<bits/stdc++.h>
    #define ll long long
    #define rep(i,a,b) for(i=a;i<b;i++)
    #define pb push_back
    #define all(v) v.begin(),v.end()
    #define F first
    #define S second
    #define root sqrtl
    #define vi vector < ll  int >
    #define CLR(a) memset((a),0,sizeof(a))
    #define mp make_pair
    #define hell 1000000007
    using namespace std;
    ll mod=hell;
 ll pr( ll x , ll y)
{
    ll ans=1;
    if(y==0) return ans;
    while(y>1)
    {
        if(y&1) ans*=x;
        x*=x;
        y/=2;
        x%=mod;
        ans%=mod;
    }
    ans*=x;
    ans%=mod;
    return ans;
}
ll fact( ll n)
{
    ll ans=1,i;
    rep(i,1,n+1)
    {
        ans*=i;
        ans%=mod;
    }
    return ans;
}
ll in(ll x) { return  pr(x,mod-2);}

bool prime[1000500];
vector < ll > v;
void pre()
{
    int n=1000000,i,j,p;
    memset(prime,true,sizeof(prime));
    prime[0]=prime[1]=false;
    for(i=2;i*i<=n;i++)
    {
        if(prime[i])
        {
            for(p=2*i;p<=n;p+=i) prime[p]=false;
        }
    }
  rep(i,0,1000000) if(prime[i]) v.pb(i);

}

ll inv(ll n)
{
    return pr(n,mod-2);
}


int cnt[26][4001];
void solve( )
{
 ll i,j=1,k,n,m=0,f,s1=0,x=1e13,c=1,y=0,a=0,b=0,d,p;

 cin>>n;
 string s;
 cin>>s;
for(i=n-1;i>=0;i--)
{
    for(j=0;j<26;j++)
    {
        cnt[j][i]=cnt[j][i+1];
    }
    cnt[s[i]-'A'][i]++;
}


for(i=0;i<n-2;i++)
{
    for(j=i+1;j<n-1;j++)
    {
        if(s[i]!=s[j])
        {
            y+=cnt['R'+'B'+'G'-s[i]-s[j]-'A'][j+1];
            d=j-i;
            if(j+d<n and s[j+d]!=s[i] and s[j+d]!=s[j]) y--;
            //cout<<y<<endl;
        }
    }
}
 cout<<y;


}
    signed main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int t=1;
        //cin>>t;
        while(t--)
        solve();
    }
