#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int n;cin >> n;
    string s;cin >> s;
    ll r=0,g=0,b=0;
    rep(i,n){
        if(s[i]=='R') ++r;
        else if(s[i]=='G') ++g;
        else ++b;
    }

    ll less = 0;
    for(int left=0;left<n;++left){
        for(int right=left+2;right<n;right += 2){
            int mid = (left + right) / 2;
            if(s[right]!=s[mid] && s[mid]!=s[left] && s[right]!=s[left]){
                ++less;
            }
        }
    }
    cout << r*g*b - less << endl;
}