#include <bits/stdc++.h>
#include <regex>
#ifdef _DEBUG
#include "debug.h"
#endif
#define int ll
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define mkpr make_pair
#define mktp make_tuple
#define tv(tp, i) get<(i)>(tp)
#define CLEAR(obj) obj = decltype(obj)()
#define var auto
#define OUT(type) type &
#define IN(type) const type &
#define self (*this)
#define in :
#define True true
#define False false
using namespace std; using str = string; using cstr = const str;
using ll = long long; using ull = unsigned long long; using cint = const int; using cll = const ll;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>;
using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>;
static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7;
static const ll LINF = LLONG_MAX/2;
#ifdef int
static const int INF = LINF;
#else
static const int INF = INT_MAX/2;
#endif
static double EPS = 1e-9;
static inline bool DBLEQ(double a, double b) {return abs(a - b) < EPS;}
static inline void EPR(str msg) {cerr << msg << endl;}
static inline void AST(bool exp, str msg) {if(!exp){EPR(msg);} assert(exp);}
static inline void TAST(bool exp, str msg) {if(!exp){EPR(msg);} while(!exp){}}


struct CumSum {
    vi csum;
    int N;
    CumSum(IN(vi) A) {
        self.N = A.size();
        self.csum = vi(self.N+1, 0);
        FOR(i, 1, N+1)
            self.csum[i] = self.csum[i-1] + A[i-1];
    }
    int sum(int l, int r) {
        r = min(r, self.N);
        l = max(l, (int)0);
        if (l >= r) return 0;
        return csum[r] - csum[l];
    }
};


int32_t main(int32_t argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef IMPORT_SAMPLE
    vs args(argv, argv+argc);
    string sample = make_sample(args, "sample-1");
    ifstream ifs(sample); cin.rdbuf(ifs.rdbuf());
#endif


    int N; cin >> N;
    string S; cin>>S;

    vi R(N, 0), G(N, 0), B(N, 0);
    REP(i, N) {
        if (S[i] == 'R') R[i] = 1;
        else if (S[i] == 'G') G[i] = 1;
        else if (S[i] == 'B') B[i] = 1;
        else AST(false, "RGB 以外は無い");
    }

    var rsum = CumSum(R);
    var gsum = CumSum(G);
    var bsum = CumSum(B);

    int ans = 0;
    REP(i, N-2) {
        FOR(j, i+1, N-1) {
            if (S[j] == S[i]) continue;

            int dist = j - i;
            AST(0 < dist, "0 < dist");
            if ((S[i] == 'R' && S[j] == 'G')
                or (S[i] == 'G' && S[j] == 'R')) {
                ans += bsum.sum(j+1, j+dist) + bsum.sum(j+dist+1, N);
            } else if ((S[i] == 'R' && S[j] == 'B')
                or (S[i] == 'B' && S[j] == 'R')){
                ans += gsum.sum(j+1, j+dist) + gsum.sum(j+dist+1, N);
            } else if ((S[i] == 'G' && S[j] == 'B')
                or (S[i] == 'B' && S[j] == 'G')) {
                ans += rsum.sum(j+1, j+dist) + rsum.sum(j+dist+1, N);
            } else {
                AST(false, "ここには来ない");
            }
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3740