#include<bits/stdc++.h>
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pi acos(-1)
typedef long unsigned int ll;
using namespace std;

int main()
{
    Fast;
    ll n,m,i,j,k;
    ll ans=0LL;
    string s;
    cin>>n>>s;
    ll v1=0,v2=0,v3=0;
    for(ll i=0; i<n; i++)
    {
        if(s[i]=='R')
        {
            v1++;
        }
        if(s[i]=='G')
        {
            v2++;
        }
        if(s[i]=='B')
        {
            v3++;
        }
    }
    ans=v1*v2*v3;
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            k=(j+(j-i));
            if(k<n)
            {
                if(s[i]!=s[j] && s[j]!=s[k] && s[k]!=s[i])
                {
                    ans--;
                }
            }
        }
    }
    cout<<ans<<endl;
}
