#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 2e5 + 5;

int main()
{
    FAST
    int n;
    cin>>n;
    char arr[n+1];
    for(int i=0; i<n; i++)
        cin>>arr[i];
    ll ans=0;
    vector<ll> v[4];
    for(int i=0;i<n;i++)
        {
            if(arr[i]=='B')
                v[0].push_back(i);
            if(arr[i]=='R')
                v[1].push_back(i);
                if(arr[i]=='G')
                v[2].push_back(i);
        }
        ans=(ll)((ll)v[0].size()*(ll)v[1].size()*(ll)v[2].size());
    for(int i=0; i<n; i++)
    {
        for(int j=i; j<n; j++)
        {
            if(arr[i]==arr[j])
                continue;
            int seq[26]={0};
            seq[arr[i]-'A']=1;
            seq[arr[j]-'A']=1;
            int temp=0;
            if(!seq[1])
                temp=0;
            else if(!seq['R'-'A'])
                temp=1;
            else
                temp=2;
            int dif=j-i;
            auto it=lower_bound(v[temp].begin(),v[temp].end(),j+dif);
            if(*it==j+dif)
                ans--;



        }
    }
    cout<<ans<<endl;
    return 0;
}
