// g++ -std=c++14

/*
     
    Today might be the chance to grasp the chance to let your talent bloom.
    May be tomorrow, the day after, or next year...
    May be even when you are 30. I'm not sure if physique has anything to do with it
    but if you think that it will never come, it probably never will.
     
    - Tooru Oikawa.
     
    */

#include <bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define MEMS(a, b) memset(a, b, sizeof(a))
#define _                             \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define __                            \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define all(c) c.begin(), c.end()
#define inf 1000000000000000001
#define pii pair<int, int>
#define tr(...)                                       \
    cout << __FUNCTION__ << ' ' << __LINE__ << " = "; \
    trace(#__VA_ARGS__, __VA_ARGS__)

template <typename S, typename T>
ostream &operator<<(ostream &out, pair<S, T> const &p)
{
    out << '(' << p.fi << ", " << p.se << ')';
    return out;
}

template <typename T>
ostream &operator<<(ostream &out, vector<T> const &v)
{
    ll l = v.size();
    for (ll i = 0; i < l - 1; i++)
        out << v[i] << ' ';
    if (l > 0)
        out << v[l - 1];
    return out;
}

template <typename T>
void trace(const char *name, T &&arg1) { cout << name << " : " << arg1 << endl; }

template <typename T, typename... Args>
void trace(const char *names, T &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | ";
    trace(comma + 1, args...);
}

#define int ll
const int N = 4000 + 5;

int b[N], r[N], g[N];
int pref(int i, int j, int* arr) {
    if(i < 0 or j < 0) return 0;
    if(j < i) return 0;
    int ans = arr[j];
    if(i) ans -= arr[i-1];
    return ans;
}
void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    for(int i = 0 ; i < n ; i++) {
        if(i == 0) {
            if(s[i] == 'R') r[i]++;
            else if(s[i] == 'G') g[i]++;
            else b[i]++;
        }
        else {
            b[i] = b[i-1];
            r[i] = r[i-1];
            g[i] = g[i-1];
            if(s[i] == 'R') r[i]++;
            else if(s[i] == 'G') g[i]++;
            else b[i]++;
        }
    }
    int ans = 0;

    for(int i = 0 ; i < n ; i++) {
        if(s[i] == 'R') {
            ans += pref(0,i-1,g) * pref(i+1,n-1,b);
            ans += pref(0,i-1,b) * pref(i+1,n-1,g);
        }
        if(s[i] == 'G') {
            ans += pref(0,i-1,r) * pref(i+1,n-1,b);
            ans += pref(0,i-1,b) * pref(i+1,n-1,r);
        }
        if(s[i] == 'B') {
            ans += pref(0,i-1,g) * pref(i+1,n-1,r);
            ans += pref(0,i-1,r) * pref(i+1,n-1,g);
        }
        // tr(i,ans);
        for(int j = 1 ; ; j++) {
            int l = i - j;
            int r = i + j;
            if(l < 0 or r > n-1) break;
            if(s[l] != s[r] and s[l] != s[i] and s[i] != s[r]) ans--;
        }
        // tr(i,ans);
    }
    cout << ans << endl;
}
int32_t main()
{
    _
        ll t;
    // cin >> t;
    t = 1;
    while (t--)
        solve();
}

Measured memory_bytes: 3752