#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

int main()
{
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    string s;
    cin >> N >> s;

    vector<int> r, g, b;
    rep(i, N)
    {
        if (s[i] == 'R') {
            r.PB(i);
        } else if (s[i] == 'G') {
            g.PB(i);
        } else {
            b.PB(i);
        }
    }

    ll ans = 0;
    //rgb
    rep(i, sz(r))
    {
        rep(j, sz(g))
        {
            if (r[i] < g[j]) {
                int de = g[j] - r[i];
                int dist = distance(lower_bound(ALL(b), g[j]), b.end());
                ans += dist;
                if (g[j] + de < N && s[g[j] + de] == 'B') {
                    ans--;
                }
            }
        }
    }
    //rbg
    rep(i, sz(r))
    {
        rep(j, sz(b))
        {
            if (r[i] < b[j]) {
                int de = b[j] - r[i];
                int dist = distance(lower_bound(ALL(g), b[j]), g.end());
                ans += dist;
                if (b[j] + de < N && s[b[j] + de] == 'G') {
                    ans--;
                }
            }
        }
    }
    //bgr
    rep(i, sz(b))
    {
        rep(j, sz(g))
        {
            if (b[i] < g[j]) {
                int de = g[j] - b[i];
                int dist = distance(lower_bound(ALL(r), g[j]), r.end());
                ans += dist;
                if (g[j] + de < N && s[g[j] + de] == 'R') {
                    ans--;
                }
            }
        }
    }
    //grb
    rep(i, sz(g))
    {
        rep(j, sz(r))
        {
            if (g[i] < r[j]) {
                int de = r[j] - g[i];
                int dist = distance(lower_bound(ALL(b), r[j]), b.end());
                ans += dist;
                if (r[j] + de < N && s[r[j] + de] == 'B') {
                    ans--;
                }
            }
        }
    }
    //brg
    rep(i, sz(b))
    {
        rep(j, sz(r))
        {
            if (b[i] < r[j]) {
                int de = r[j] - b[i];
                int dist = distance(lower_bound(ALL(g), r[j]), g.end());
                ans += dist;
                if (r[j] + de < N && s[r[j] + de] == 'G') {
                    ans--;
                }
            }
        }
    }
    //gbr
    rep(i, sz(g))
    {
        rep(j, sz(b))
        {
            if (g[i] < b[j]) {
                int de = b[j] - g[i];
                int dist = distance(lower_bound(ALL(r), b[j]), r.end());
                ans += dist;
                if (b[j] + de < N && s[b[j] + de] == 'R') {
                    ans--;
                }
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3668