#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    string S;
    cin >> N >> S;

    vec r, g, b;
    Rep (i, N) {
        if (S[i] == 'R') {
            r.push_back(i);
        } else if (S[i] == 'B') {
            b.push_back(i);
        } else {
            g.push_back(i);
        }
    }

    ll ans = 0;
    Rep (i, N) {
        for (ll j = i+1; j < N; j++) {
            if (S[i] == S[j]) {
                continue;
            }
            if (S[i] == 'R' and S[j] == 'G' or S[i] == 'G' and S[j] == 'R') {
                ll tmp = b.end() - lower_bound(b.begin(), b.end(), j);
                if (2*j-i < N and S[2*j-i] == 'B') tmp--;
                ans += tmp;
            } else if (S[i] == 'G' and S[j] == 'B' or S[i] == 'B' and S[j] == 'G') {
                ll tmp = r.end() - lower_bound(r.begin(), r.end(), j);
                if (2*j-i < N and S[2*j-i] == 'R') tmp--;
                ans += tmp;
            } else {
                ll tmp = g.end() - lower_bound(g.begin(), g.end(), j);
                if (2*j-i < N and S[2*j-i] == 'G') tmp--;
                ans += tmp;
            }
        }
    }

    cout << ans << endl;
}