#include <bits/stdc++.h>
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>
#include <boost/math/constants/constants.hpp>
using namespace std;
namespace rng {
    using namespace boost;
    using namespace boost::range;
    using namespace boost::adaptors;
    template<class R, class P> auto partition_point(const R& r, P p) { return ::std::partition_point(begin(r), end(r), p); }
}

struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

using boost::irange;
using boost::math::double_constants::pi;
using i64 = int64_t;
constexpr char nl = '\n';
auto yesno(bool b) { return b ? "Yes" : "No"; }

template<class T> istream& operator>>(istream& in, vector<T>& vs) { for (T& v :vs) in >> v; return in; }
template<class T> ostream& operator<<(ostream& out, const vector<T>& vs) { for (size_t i = 0; i < vs.size(); ++i) { if(i) { out << ' '; } out << vs[i]; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const T& v) { cout << v; }
template<class T> void trace_(const vector<vector<T>>& m) { cout << nl; for (const auto& v : m) { trace_(v); cout << nl; } }
template<class T> void trace_(const char* s, const T& v) { cout << s << "="; trace_(v); cout << nl; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cout << *s; } cout << "="; trace_(v); cout << ","; trace_(++s, vs...); }
#define TRACE(...) trace_(#__VA_ARGS__, __VA_ARGS__)
#else
#define TRACE(...)
#endif

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;

    vector<int> right_r(N), right_g(N), right_b(N);
    for (int i : irange(N-1)) {
        for (int j : irange(i+1, N)) {
            if (S[j] == 'R') right_r[i]++;
            if (S[j] == 'G') right_g[i]++;
            if (S[j] == 'B') right_b[i]++;
        }
    }

    string rgb = "RGB";
    rng::sort(rgb);
    i64 count = 0;
    do {
        for (auto i : irange(0ul, S.size()-2)) {
            if (S[i] == rgb[0]) {
                for (auto j : irange(i+1, S.size()-1)) {
                    if (S[j] == rgb[1]) {
                        if (rgb[2] == 'R') count += right_r[j];
                        if (rgb[2] == 'G') count += right_g[j];
                        if (rgb[2] == 'B') count += right_b[j];
                        int k = j + (j - i);
                        if (k < N && S[k] == rgb[2]) count--;
                    }
                }
            }
        }
    } while (rng::next_permutation(rgb));
    cout << count << nl;
}


Measured memory_bytes: 3660