#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define MOD 1000000007
#define mod 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2*1e9


int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<pair<int,pair<int,int> > >v(n);
    pair<int,pair<int,int> >p=make_pair(0,make_pair(0,0));
    for(int i=n-1;i>-1;i--)
    {
        if(s[i]=='R')
            p.first+=1;
        else if(s[i]=='G')
            p.second.first+=1;
        else
            p.second.second+=1;
        v[i]=p;
    }
    lli ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(s[i]=='R')
            {
                if(s[j]=='G')
                {
                    ans+=v[j].second.second;
                    int diff=j-i;
                    int ind=j+diff;
                    if(ind<n and s[ind]=='B')
                        ans-=1;
                }
                else if(s[j]=='B')
                {
                    ans+=v[j].second.first;
                    int diff=j-i;
                    int ind=j+diff;
                    if(ind<n and s[ind]=='G')
                        ans-=1;
                }
            }
            else if(s[i]=='G')
            {
                if(s[j]=='R')
                {
                    ans+=v[j].second.second;
                    int diff=j-i;
                    int ind=j+diff;
                    if(ind<n and s[ind]=='B')
                        ans-=1;
                }
                else if(s[j]=='B')
                {
                    ans+=v[j].first;
                    int diff=j-i;
                    int ind=j+diff;
                    if(ind<n and s[ind]=='R')
                        ans-=1;
                }
            }
            else if(s[i]=='B')
            {
                if(s[j]=='R')
                {
                    ans+=v[j].second.first;
                    int diff=j-i;
                    int ind=j+diff;
                    if(ind<n and s[ind]=='G')
                        ans-=1;
                }
                else if(s[j]=='G')
                {
                    ans+=v[j].first;
                    int diff=j-i;
                    int ind=j+diff;
                    if(ind<n and s[ind]=='R')
                        ans-=1;
                }
            }
        }
    }
    cout << ans << endl;
}