#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){}}


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;

    vvi sum(3, vi(N+1, 0));
    for(int i = 0; i < N; i++) {
        if (S[i] == 'R') {
            sum[0][i+1] = sum[0][i] + 1;
            sum[1][i+1] = sum[1][i];
            sum[2][i+1] = sum[2][i];
        }
        else if (S[i] == 'G') {
            sum[0][i+1] = sum[0][i];
            sum[1][i+1] = sum[1][i] + 1;
            sum[2][i+1] = sum[2][i];
        }
        else if (S[i] == 'B'){
            sum[0][i+1] = sum[0][i];
            sum[1][i+1] = sum[1][i];
            sum[2][i+1] = sum[2][i] + 1;
        } else {
            AST(false, "ここには来ない");
        }
    }

    var segsum = [&](int rgb, int l, int r) -> int { // [l, r)
        if (l >= r) return 0;
        AST(l < r, "l < r");
        if (N < r) {
            return sum[rgb][N] - sum[rgb][l];
        } else {
            return sum[rgb][r] - sum[rgb][l];
        }
    };

    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') {
                ans += segsum(2, j+1, j+dist) + segsum(2, j+dist+1, N);
            } else if (S[i] == 'G' && S[j] == 'R') {
                ans += segsum(2, j+1, j+dist) + segsum(2, j+dist+1, N);
            } else if (S[i] == 'R' && S[j] == 'B') {
                ans += segsum(1, j+1, j+dist) + segsum(1, j+dist+1, N);
            } else if (S[i] == 'B' && S[j] == 'R') {
                ans += segsum(1, j+1, j+dist) + segsum(1, j+dist+1, N);
            } else if (S[i] == 'G' && S[j] == 'B') {
                ans += segsum(0, j+1, j+dist) + segsum(0, j+dist+1, N);
            } else if (S[i] == 'B' && S[j] == 'G') {
                ans += segsum(0, j+1, j+dist) + segsum(0, j+dist+1, N);
            } else {
                AST(false, "ここには来ない");
            }
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3720