#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair < int, int >
#define pll pair < ll, ll >
#define pb push_back
#define maxn 100005
using namespace std;

int main()
{
    int l, b = 0;
    string s;

    cin >> l >> s;

    vector < int > r, g;
    map < int, bool > mp;

    for(int i = 0; i < l; i++){
        if(s[i] == 'R') r.pb(i);
        else if(s[i] == 'G') g.pb(i);
        else b++, mp[i] = 1;
    }

    int rs = r.size(), gs = g.size();
    ll ans = 0;

    for(int i = 0; i < rs; i++){
        for(int j = 0; j < gs; j++){
            int tmp = abs(r[i] - g[j]);

            ans += b;

            if(mp[r[i] + tmp]) ans--;
            if(mp[r[i] - tmp]) ans--;
            if(mp[g[j] + tmp]) ans--;
            if(mp[g[j] - tmp]) ans--;
            if((r[i] + g[j]) % 2 == 0 && mp[(r[i] + g[j]) / 2]) ans--;
        }
    }

    cout << ans << endl;

    return 0;
}

