#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

ll solve(int n,string s){
    vector<int>a[3];
    rep(i,n){
        if(s[i]=='R')a[0].push_back(i);
        else if(s[i]=='G')a[1].push_back(i);
        else a[2].push_back(i);
    }
    int sr=a[0].size();
    int sg=a[1].size();
    int sb=a[2].size();
    ll ans=sr*sg*sb;
    rep(i,sr)rep(j,sg)rep(k,sb){
        int ni=a[0][i];
        int nj=a[1][j];
        int nk=a[2][k];

        if(ni<nj&&nj<nk)
        {
          if(nj-ni==nk-nj)ans--;
        }

        if(nj<ni&&ni<nk){
        if(ni-nj==nk-ni)ans--;
        }

         if(ni<nk&&nk<nj){
        if(nk-ni==nj-nk)ans--;
        }

        if(nk<nj&&nj<ni){
        if(nj-nk==ni-nj)ans--;
        }

        if(nk<ni&&ni<nj){
        if(ni-nk==nj-ni)ans--;
        }

        if(nj<nk&&nk<ni){
        if(nk-nj==ni-nk)ans--;
        }        

    }
    return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);

int n;
string s;
cin>>n>>s;

cout<<solve(n,s)<<endl;
return 0;
}