#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

vector<int>pos[3];
set<int>t[3];

int main(void){
    int n;
    string s;
    cin>>n>>s;
    map<char,int>m;
    map<int,char>mi;
    m['R']=0;
    m['G']=1;
    m['B']=2;
    mi[0]='R';
    mi[1]='G';
    mi[2]='B';
    ll ans = 0;
    for(int i=0;i<n;i++){
        pos[m[s[i]]].push_back(i);
        t[m[s[i]]].insert(i);
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(i==j)continue;
            if(s[i]==s[j])continue;
            int index=0;
            for(int k=0;k<3;k++){
                if(s[i]==mi[k])continue;
                if(s[j]==mi[k])continue;
                index=k;
                break;
            }
            auto itr = upper_bound(pos[index].begin(),pos[index].end(),j);
            if(itr==pos[index].end())continue;
            int d=j-i;
            int siz = pos[index].size();
            int index2=itr-pos[index].begin();
            //cout<<i<<" "<<j<<" "<<index2<<endl;
            ans+=(siz-index2);
            if(t[index].count(j+d)==1)ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}