#include<bits/stdc++.h>
using namespace std;
#define rep(i, c) for(int i = 1; i <= (int)c; i++)
#define ll long long
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;
const int inf = 1000000000; // 10^9

int main(){
    ll n, r = 0, g = 0, b = 0;
    char s[4100];
    ll ans = 0, cnt = 0;

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

    ans = r * g * b;

    rep(i, n){
        rep(j, (n - i)/2){
            if(s[i] != s[i + j] && s[i] != s[i + 2*j] && s[i + 2 * j] != s[i + j]) cnt++;
        }
    }

    ans -= cnt;

    cout << ans << endl;

    return 0;
}
