#include<bits/stdc++.h>
#define int           long long
#define pb            push_back
#define ppb           pop_back
#define si            set <int>
#define endl          '\n'
#define fr            first
#define sc            second     
#define rep(i,a,b)    for(int  i=a;i<b;i++)
#define repr(i,a,b)      for(int i=b-1;i>=a;i--)
#define trav(it,v)      for(auto it=v.begin();it!=v.end();it++)
#define all(v)        v.begin(),v.end()
#define srt(v)        sort(all(v))
#define vs            vector<string>
#define sz(x)         (int )x.size()
#define M             1000000007
#define bs            binary_search
#define sp(n)         setprecision(n)
#define spl           " "
#define arr(a,n)      rep(i,0,n) cin>>a[i]
#define mod           998244353
#define MAXN          1000000000000000000

using namespace std;

bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 


//int dx[4]={0,0,1,-1};
//int dy[4]={1,-1,0,0};
// vector<int>adj[100001];
// int vis[100001]={0};
// vector<int>v1;

void solve()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    set<int>st2;
    vector<int>v1;
    vector<int>v2;
    rep(i,0,n)
    {
        if(s[i]=='R')
            v1.pb(i);
        else if(s[i]=='G')
            st2.insert(i);
        else v2.pb(i);
    }
    int ans=0,a,b,c;
    rep(i,0,v1.size())
    {
        rep(j,0,v2.size())
        {
            if(v1[i]>v2[j])
            {
                a=(2*v2[j])-v1[i];
                b=(2*v1[i])-v2[j];
                if((v1[i]+v2[j])%2==0)
                c=(v1[i]+v2[j])/2;
            else c=-1;
            }
            else
            {
                a=(2*v1[i])-v2[j];
                b=(2*v2[j])-v1[i];
                if((v1[i]+v2[j])%2==0)
                c=(v1[i]+v2[j])/2;
            else c=-1;
            }
            int sum=st2.size();
            if(a>=0 && a<n)
            {
                if(st2.find(a)!=st2.end())
                    sum--;
            }
            if(b>=0 && b<n)
            {
                if(st2.find(b)!=st2.end())
                    sum--;
            }
            if(c>=0 && c<n)
            {
                if(st2.find(c)!=st2.end())
                    sum--;
            }
            ans+=sum;
        }
    }
    cout<<ans;

}   
    


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}