#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    int N;
    string S;
    cin >> N >> S;
    ll ans = 0;
    map<char, int> m;
    vector<char> C = {'R', 'G', 'B'};
    for (int i = 0; i < N; i++) {
        ll tmp = 1;
        for (int j = 0; j < 3; j++) {
            if (S[i] != C[j]) {
                tmp *= m[C[j]];
            }
        }
        ans += tmp;
        for (int j = i + 1; j < N; j++) {
            int k = 2 * i - j;
            if (0 <= k && k < N && S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) ans--;
        }
        m[S[i]]++;
    }
    cout << ans << endl;
}
