#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> inline bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> inline bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    ll n;
    string s;
    in>>n>>s;
    ll ans=n*(n-1)*(n-2)/6;
    int c[256]={};
    fr(i,n) c[s[i]]++;
    ll r=c['R'],g=c['G'],b=c['B'];
    ans-=r*(r-1)/2*(n-r);
    ans-=g*(g-1)/2*(n-g);
    ans-=b*(b-1)/2*(n-b);
    ans-=r*(r-1)*(r-2)/6;
    ans-=g*(g-1)*(g-2)/6;
    ans-=b*(b-1)*(b-2)/6;
    fr(i,n) fr(j,i){
        int k=i+(i-j);
        if(k<n&&s[i]!=s[j]&&s[j]!=s[k]&&s[i]!=s[k]) --ans;
    }
    cout<<ans<<endl;
}