#include <bits/stdc++.h>
#define fin freopen("input", "r", stdin);
#define fout freopen("output", "w", stdout);
#define wt(x) cerr << #x << ": " << x << " ";
#define whatis(x) {cerr << #x << ": " << x << endl;}
#define whatis2(x, y) {wt(x); wt(y); cerr << endl;}
#define whatis3(x, y, z) {wt(x); wt(y); wt(z); cerr << endl;}
#define whatis4(x, y, z, a) {wt(x); wt(y); wt(z); wt(a); cerr << endl;}
using namespace std;

typedef long long ll; typedef unsigned long long ull; typedef long double ld;
const ll MOD = 1000000007; const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

string s;
int n;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    cin >> n;
    cin >> s;

    ll ans = 0;
    map <char, int> mp;
    for (auto i : s) mp[i] += 1;

    ans = mp['R'] * mp['G'] * mp['B'];
    ll minus = 0;

    for (int diff = 1; diff < n; ++diff) {
        for (int i = 0; i + 2*diff < n; ++i) {
            int r, g, b;
            r = i;
            g = i + diff;
            b = i + diff + diff;
            /* whatis3(r, g, b); */
            if (s[r] != s[g] && s[g] != s[b] && s[b] != s[r]) minus += 1;
        }
    }



    cout << ans - minus << endl;
    /* whatis(ans); */
    /* whatis(minus); */
    /* whatis(ans - minus); */


    


    return 0;
}
