#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define lenth length()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(unsigned long long int x, unsigned long long int y)
{
    return (x|y)&(~x|~y);   
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
void fill(ll red[], string str, char ch)
{
    ll n = str.length();
    for(ll i=n-1;i>=0;i--)
    {
        if(i==n-1)
        {
            if(str[i]==ch)
                red[i]=1;
            else
                red[i]=0;
        }
        else
        {
            if(str[i]==ch)
                red[i]=red[i+1]+1;
            else
                red[i]=red[i+1];
        }
    }
    // ll i;
    // rep(i,0,n)
    //     cout<<red[i]<<" ";
    // cout<<endl;
    // rep(i,0,n)
    //     cout<<blue[i]<<" ";
    // cout<<endl;
}
int main()
{
    // fastio
    ll t,n,m,i,j,k,l,x,y,z,a,b,c,d,e,p,nl,np,q,r,s,h;
    string str,str1;
    cin>>n;
    cin>>str;
    ll res=0;
    ll red[n], blue[n], green[n];
    char ch='R',ch1='B',ch2='G';
    fill(red, str, ch);
    fill(blue, str, ch1);
    fill(green, str, ch2);
    // rep(i,0,n)
    //     cout<<red[i]<<" ";
    // cout<<endl;
    // rep(i,0,n)
    //     cout<<green[i]<<" ";
    // cout<<endl;
    // rep(i,0,n)
    //     cout<<blue[i]<<" ";
    // cout<<endl;
    
    rep(i,0,n)
    {
        rep(j,i+1,n)
        {

            if(str[i]=='R')
            {
                if(str[j]=='B')
                {
                    ll diff = j-i;
                    res+=green[j];
                    if(j+diff<n && str[j+diff]=='G')
                        res--;
                }
                else if(str[j]=='G')
                {
                    ll diff = j-i;
                    res+=blue[j];
                    if(j+diff<n && str[j+diff]=='B')
                        res--;
                }
            }
            if(str[i]=='G')
            {
                if(str[j]=='B')
                {
                    ll diff = j-i;
                    res+=red[j];
                    if(j+diff<n && str[j+diff]=='R')
                        res--;
                }
                else if(str[j]=='R')
                {
                    ll diff = j-i;
                    res+=blue[j];
                    if(j+diff<n && str[j+diff]=='B')
                        res--;
                }
            }
            if(str[i]=='B')
            {
                if(str[j]=='R')
                {
                    ll diff = j-i;
                    res+=green[j];
                    if(j+diff<n && str[j+diff]=='G')
                        res--;
                }
                else if(str[j]=='G')
                {
                    ll diff = j-i;
                    res+=red[j];
                    if(j+diff<n && str[j+diff]=='R')
                        res--;
                }
            }
            // cout<<res<<endl;
        }
        // cout<<res<<endl;
    }
    cout<<res;
}

Measured memory_bytes: 3708