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

int main() {
    int n,all,r_count=0,g_count=0,b_count=0;
    string s;
    cin>>n>>s;
    ll ans=0;
    rep(i,s.size()) {
        if (s[i]=='R') r_count++;
        else if(s[i]=='G') g_count++;
        else b_count++;
    }
    all=r_count*g_count*b_count;
    rep(i,n-2) {
        for (int j=i+1; j<n-1; j++) {
            int k=2*j-i;
            if (s[i]==s[j]||s[k]==s[i]||s[k]==s[j]||k>=n) continue;
            ans++;
        }
    }
    cout<<all-ans<<endl;
}