#include <iostream>
#include <math.h>
#include <vector>
#include <set>
#include <algorithm>
#include <iomanip>
#include <bitset>
#include <map>
typedef long long ll;
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define all(v) v.begin(), v.end()
#define ss second
#define ff first
#define pb push_back
#pragma GCC optimize("Ofast", "unroll-loops", "fast-math", "no-stack-protector")
#pragma GCC target("avx2")
using namespace std;
/*
string s;
vector < int > skobe;
ll mod = 998244353;
pair < pair < ll, ll >, pair < ll, ll > > ask(int l, int r) {
    if (l == r) return {{2, 2}, {2, 2}};
    int ind = skobe[l + 1] + 1;
    //cout << s[ind] << "- " << endl;
    auto k1 = ask(l + 1, skobe[l + 1]);
    auto k2 = ask(ind + 1, r - 1);
    pair < pair < ll, ll >, pair < ll, ll > > ans;
    if (s[ind] == '&') {
        ans.ff.ff = ((k1.ff.ff * k2.ff.ff) % mod) + ((k1.ff.ff * k2.ff.ss) % mod) + ((k1.ff.ss * k2.ff.ff) % mod);
        ans.ff.ss = ((k1.ff.ss * k2.ff.ss) % mod);
        ans.ss.ff = ((k1.ss.ff * k2.ss.ff) % mod) + ((k1.ss.ff * k2.ss.ss) % mod) + ((k1.ss.ss * k2.ss.ff) % mod);
        ans.ss.ss = ((k1.ss.ss * k2.ss.ss) % mod);
    }
    if (s[ind] == '|') {
        ans.ff.ff = ((k1.ff.ff * k2.ff.ff) % mod);
        ans.ff.ss = ((k1.ff.ff * k2.ff.ss) % mod) + ((k1.ff.ss * k2.ff.ff) % mod) + ((k1.ff.ss * k2.ff.ss) % mod);
        ans.ss.ff = ((k1.ss.ff * k2.ss.ff) % mod);
        ans.ss.ss = ((k1.ss.ff * k2.ss.ss) % mod) + ((k1.ss.ss * k2.ss.ff) % mod) + ((k1.ss.ss * k2.ss.ss) % mod);
    }
    if (s[ind] == '^') {
        ans.ff.ff = ((k1.ff.ff * k2.ff.ff) % mod) + ((k1.ff.ss * k2.ff.ss) % mod);
        ans.ff.ss = ((k1.ff.ff * k2.ff.ss) % mod) + ((k1.ff.ss * k2.ff.ff) % mod);
        ans.ss.ff = ((k1.ss.ff * k2.ss.ff) % mod) + ((k1.ss.ss * k2.ss.ss) % mod);
        ans.ss.ss = ((k1.ss.ff * k2.ss.ss) % mod) + ((k1.ss.ss * k2.ss.ff) % mod);
    }
    ans.ff.ff %= mod;
    ans.ff.ss %= mod;
    ans.ss.ff %= mod;
    ans.ss.ss %= mod;
    return ans;
}
ll step(ll x, ll a) {
    if (a == 0) return 1;
    if (a == 1) return x;
    if (a % 2 == 0) return step((x * x) % mod, a / 2);
    else return (step(x, a - 1) * x) % mod;
}
void solve() {
    cin >> s;
    int n = s.size();
    skobe.clear();
    skobe.resize(n);
    fori(n) skobe[i] = i;
    vector < int > buf;
    for (int i = n - 1; i >= 0; i--) {
        if (s[i] == ')') buf.pb(i);
        else if (s[i] == '(') {
            skobe[i] = buf.back();
            buf.pop_back();
        }
    }
    int cnt = 0;
    fori(n) if (s[i] == '#') cnt++;
    ll bib = step(4, cnt * 2);
    bib = step(bib, mod - 2);
    auto ans = ask(0, n - 1);
    cout << (ans.ff.ff * ans.ss.ff * bib) % mod << " ";
    cout << (ans.ff.ss * ans.ss.ss * bib) % mod << " ";
    cout << (ans.ff.ff * ans.ss.ss * bib) % mod << " ";
    cout << (ans.ff.ss * ans.ss.ff * bib) % mod << " ";
    cout << endl;
}
/// ((#|#)|((#&#)^#))
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--) solve();
}*/
int main() {
    int n;
    string s;
    cin >> n >> s;
    vector < ll > a;
    a.resize(3);
    ll ans = 0;
    for (int i = 1; i < n; i++) {
        if (s[i - 1] == 'R') a[0]++;
        else if (s[i - 1] == 'G') a[1]++;
        else if (s[i - 1] == 'B') a[2]++;
        vector < ll > b;
        b.resize(3);
        for (int j = i + 1; j < n; j++) {
            if (s[j] == 'R') b[0]++;
            else if (s[j] == 'G') b[1]++;
            else if (s[j] == 'B') b[2]++;
        }
        if (s[i] == 'R') ans += a[1] * b[2] + a[2] * b[1];
        if (s[i] == 'G') ans += a[0] * b[2] + a[2] * b[0];
        if (s[i] == 'B') ans += a[0] * b[1] + a[1] * b[0];
        for (int d = 1; d < n; d++) {
            if (i - d < 0) break;
            if (i + d >= n) break;
            if (s[i - d] != s[i] && s[i - d] != s[i + d] && s[i] != s[i + d]) ans--;
        }
    }
    cout << ans;
}


Measured memory_bytes: 3192