#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    string s;
    cin >> n >> s;
    vi r(n + 1);
    vi g(n + 1);
    vi b(n + 1);
    REP(i, n) {
        r[i + 1] = r[i] + (s[i] == 'R' ? 1 : 0);
        g[i + 1] = g[i] + (s[i] == 'G' ? 1 : 0);
        b[i + 1] = b[i] + (s[i] == 'B' ? 1 : 0);
    }

    ll t = 0;
    REP(i, n) {
        if (i == 0 or i == n - 1) continue;
        if (s[i] == 'R') {
            t += g[i] * (b[n] - b[i + 1]);
            int l = i - 1;
            int f = i + 1;
            while (l >= 0 and f < n) {
                if (s[l] == 'G' and s[f] == 'B') t--;
                l--;
                f++;
            }
            t += b[i] * (g[n] - g[i + 1]);
            l = i - 1;
            f = i + 1;
            while (l >= 0 and f < n) {
                if (s[l] == 'B' and s[f] == 'G') t--;
                l--;
                f++;
            }
        } else if (s[i] == 'G') {
            t += r[i] * (b[n] - b[i + 1]);
            int l = i - 1;
            int f = i + 1;
            while (l >= 0 and f < n) {
                if (s[l] == 'R' and s[f] == 'B') t--;
                l--;
                f++;
            }
            t += b[i] * (r[n] - r[i + 1]);
            l = i - 1;
            f = i + 1;
            while (l >= 0 and f < n) {
                if (s[l] == 'B' and s[f] == 'R') t--;
                l--;
                f++;
            }
        } else if (s[i] == 'B') {
            t += r[i] * (g[n] - g[i + 1]);
            int l = i - 1;
            int f = i + 1;
            while (l >= 0 and f < n) {
                if (s[l] == 'R' and s[f] == 'G') t--;
                l--;
                f++;
            }
            t += g[i] * (r[n] - r[i + 1]);
            l = i - 1;
            f = i + 1;
            while (l >= 0 and f < n) {
                if (s[l] == 'G' and s[f] == 'R') t--;
                l--;
                f++;
            }
        }
    }
    cout << t << endl;
}


Measured memory_bytes: 3660