#include <bits/stdc++.h>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void){
    int n; string s;
    cin>>n>>s;
    int r,g,b;r=g=b=0;
    rep(i,0,n){
        if(s[i]=='R')r++;
        else if(s[i]=='G')g++;
        else b++;
    }
    ll ans=r*g*b;
    rep(i,0,n){
        rep(j,i+1,n){
            int k=2*j-i;
            if(k<n&&s[i]!=s[j]&&s[j]!=s[k]&&s[k]!=s[i])ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}