#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    vector<ll> cnt(3, 0);
    string rgb = "RGB";
    ll ans = 0;
    rep(i, 0, N) {
        rep(j, i + 1, N) {
            if (S[i] != S[j]) {
                rep(k, 0, 3) {
                    if (rgb[k] != S[i] && rgb[k] != S[j]) {
                        ans += cnt[k] - (2 * i - j >= 0 && S[2 * i - j] == rgb[k]);
                        break;
                    }
                }
            }
        }
        rep(j, 0, 3) {
            if (rgb[j] == S[i]) {
                ++cnt[j];
            }
        }
    }
    cout << ans << endl;
    return 0;
}