//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define fi first
#define se second
#define pii pair<long long,long long>
#define int long long
#define endl '\n'
#define pll pair<long long,long long>
#define LONGLONG_MAX 100000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a);}
                a=(a*a);
                b>>=1;
        }
    return ans;
        
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    srand(time(0));
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<int>v1,v2,v3;
    for(int i=0;i<n;i++){
        if(s[i]=='R')v1.push_back(i);
        else if(s[i]=='G')v2.push_back(i);
        else v3.push_back(i);
    }
    int ans=0;
    for(auto i:v1){
        int j=lower_bound(v2.begin(),v2.end(),i)-v2.begin();
        for(int k=j;k<v2.size();k++){
            int l=lower_bound(v3.begin(),v3.end(),v2[k])-v3.begin();
            ans+=v3.size()-l;
            if(binary_search(v3.begin(),v3.end(),i+2*(v2[k]-i)))ans--;
        }
    }
    for(auto i:v1){
        int j=lower_bound(v3.begin(),v3.end(),i)-v3.begin();
        for(int k=j;k<v3.size();k++){
            int l=lower_bound(v2.begin(),v2.end(),v3[k])-v2.begin();
            ans+=v2.size()-l;
            if(binary_search(v2.begin(),v2.end(),i+2*(v3[k]-i)))ans--;
        }
    }
    for(auto i:v2){
        int j=lower_bound(v3.begin(),v3.end(),i)-v3.begin();
        for(int k=j;k<v3.size();k++){
            int l=lower_bound(v1.begin(),v1.end(),v3[k])-v1.begin();
            ans+=v1.size()-l;
            if(binary_search(v1.begin(),v1.end(),i+2*(v3[k]-i)))ans--;
        }
    }
    for(auto i:v2){
        int j=lower_bound(v1.begin(),v1.end(),i)-v1.begin();
        for(int k=j;k<v1.size();k++){
            int l=lower_bound(v3.begin(),v3.end(),v1[k])-v3.begin();
            ans+=v3.size()-l;
            if(binary_search(v3.begin(),v3.end(),i+2*(v1[k]-i)))ans--;
        }
    }
    for(auto i:v3){
        int j=lower_bound(v2.begin(),v2.end(),i)-v2.begin();
        for(int k=j;k<v2.size();k++){
            int l=lower_bound(v1.begin(),v1.end(),v2[k])-v1.begin();
            ans+=v1.size()-l;
            if(binary_search(v1.begin(),v1.end(),i+2*(v2[k]-i)))ans--;
        }
    }
    for(auto i:v3){
        int j=lower_bound(v1.begin(),v1.end(),i)-v1.begin();
        for(int k=j;k<v1.size();k++){
            int l=lower_bound(v2.begin(),v2.end(),v1[k])-v2.begin();
            ans+=v2.size()-l;
            if(binary_search(v2.begin(),v2.end(),i+2*(v1[k]-i)))ans--;
        }
    }
    cout<<ans;
    return 0;
}