#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll long long int
#define ld long double
#define FOR(i,a,b) for (auto i = (a); i != (b); i = (a)<(b)? i+1 : i-1)
#define pb push_back
#define mod 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll su[n+1][3]={0};
    if(s[0]=='R')
            ++su[0][0];
        else if(s[0]=='B')
        ++su[0][1];
        else
            ++su[0][2];
    for(int x=1;x<n;x++)
    {    su[x][0]=su[x-1][0];
         su[x][1]=su[x-1][1];
         su[x][2]=su[x-1][2];
        if(s[x]=='R')
            ++su[x][0];
        else if(s[x]=='B')
        ++su[x][1];
        else
            ++su[x][2];
    }
    ll ans=su[n-1][1]*su[n-1][0]*su[n-1][2];
    for(int x=1;x<=n/2;x++)
    {
        for(int y=0;y<n;y++)
        {
            if(y+x<n && y+2*x<n)
            {
                if(s[y]!=s[x+y] && s[y]!=s[2*x+y] && s[y+x]!=s[y+2*x])
                    --ans;
            }
        }
    }
    cout<<ans;
 
}