/*---------------------------------------------------------------------*/
/*                   -------------------------------------             */
/*                   -----------MEHEDI HASAN--------------             */
/*                   -----CSE,JAHANGIRNAGAR UNIVERSITY----             */
/*                   -------------------------------------             */
/*---------------------------------------------------------------------*/
#include<bits/stdc++.h>
#include <cassert>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
/*---------------------------------------------------------------------*/
#define FAST        ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define cc(x)       cout<<#x<<"="<<x<<" ";
#define ccc(x)      cout<<#x<<"="<<"("<<x.ff<<" "<<x.ss<<") ";
#define CC(x)       cout<<"["<<#x<<"] = ";for(auto xx: x) cout<<xx<<" ";
#define CCC(x)      cout<<"["<<#x<<"] = ";for(auto xx: x) cout<<"("<<xx.ff<<" "<<xx.ss<<") ";
#define MARK(x)     cout<<x<<" ";
#define ee          cout<<"\n";
#define OK          cout<<"Ok till line "<<__LINE__<<"\n";
/*---------------------------------------------------------------------*/
#define ff          first
#define ss          second
#define ll          long long
#define ull         unsigned long long
#define pii         pair<int,int>
#define mp          make_pair
#define ps          push
#define psb         push_back
#define psf         push_front
#define pp          pop
#define ppb         pop_back
#define ppf         pop_front
#define all(x)      x.begin(),x.end()
#define TESTS       int t;cin>>t;for(int tcase=1;tcase<=t;tcase++)
#define ordered_set tree< int, null_type, less_equal< int >, rb_tree_tag, tree_order_statistics_node_update>
/*---------------------------------------------------------------------*/
#define MAX (ll)(1e6)
#define MOD (ll)(1e9+7)

int main()
{
    FAST
    int n;cin>>n;string s;cin>>s;
    vector<int> R(n+1,0),G(n+1,0),B(n+1,0);
    R[0]=G[0]=B[0]=0;
    s="*"+s;
    int sr=0,sg=0,sb=0;
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='R') sr++;
        else if(s[i]=='B') sb++;
        else sg++;
        R[i]=sr;
        G[i]=sg;
        B[i]=sb;
    }
    ll sum=0ll;
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            if(s[i]!=s[j])
            {
                set<char> ss({'R','G','B'});
                ss.erase(s[i]);
                ss.erase(s[j]);
                char x=*ss.begin();
                int d=j-i;
                if(x=='R')
                {
                    sum+=R[n]-R[j];
                    if(j+d<=n and s[j+d]==x) sum--;
                }
                else if(x=='G')
                {
                    sum+=G[n]-G[j];
                    if(j+d<=n and s[j+d]==x) sum--;

                }
                else
                {
                    sum+=B[n]-B[j];
                    if(j+d<=n and s[j+d]==x) sum--;

                }
            }

        }

    }
    cout<<sum<<endl;
    return 0;

}
/*--------------------------------------------------------------------*/
/*
>Check Corner Cases (n==1 or T==1)
>Overflow issues?
>LB / UB !!not found!! check?
*/
/*--------------------------------------------------------------------*/
/* ---INPUT---
--------(1)------

-------(2)-------


-------(3)-------


-------(4)-------



--------------
*/
/*--------------------------------------------------------------------*/



//https://codeforces.com/contest/466/problem/C try again


Measured memory_bytes: 3652