/**
* Copyright(c)
* All rights reserved.
* Author : zzy
* Date : 2020-04-12-20.11.57
*/
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 4000+200;
int n;
char s[maxn];
vi r;
vi g;
vi b;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> n;
    cin >> (s+1);
    for1(i, n) {
        if (s[i] == 'R') r.eb(i);
        else if (s[i] == 'G') g.eb(i);
        else if (s[i] == 'B') b.eb(i);
    }
    i64 ans = 0;
    for (int ri : r) {
        auto it = upper_bound(all(g), ri);
        for (it; it != g.end(); ++it) {
            int gi = *it;
            ans += b.end()-upper_bound(all(b), gi);
            if (gi+(gi-ri) <= n && s[gi+(gi-ri)] == 'B') --ans;
        }
    }
    for (int ri : r) {
        auto it = upper_bound(all(b), ri);
        for (it; it != b.end(); ++it) {
            int bi = *it;
            ans += g.end()-upper_bound(all(g), bi);
            int idx = bi+(bi-ri);
            if (idx <= n && s[idx] == 'G') --ans;
        }
    }
    for (int gi : g) {
        auto it = upper_bound(all(r), gi);
        for (it; it != r.end(); ++it) {
            int ri = *it;
            ans += b.end()-upper_bound(all(b), ri);
            int idx = ri+(ri-gi);
            if (idx <= n && s[idx] == 'B') --ans;
        }
    }
    for (int gi : g) {
        auto it = upper_bound(all(b), gi);
        for (it; it != b.end(); ++it) {
            int bi = *it;
            ans += r.end()-upper_bound(all(r), bi);
            int idx = bi+(bi-gi);
            if (idx <= n && s[idx] == 'R') --ans;
        }
    }
    for (int bi : b) {
        auto it = upper_bound(all(g), bi);
        for (it; it != g.end(); ++it) {
            int gi = *it;
            ans += r.end()-upper_bound(all(r), gi);
            int idx = gi+(gi-bi);
            if (idx <= n && s[idx] == 'R') --ans;
        }
    }
    for (int bi : b) {
        auto it = upper_bound(all(r), bi);
        for (it; it != r.end(); ++it) {
            int ri = *it;
            ans += g.end()-upper_bound(all(g), ri);
            int idx = ri+(ri-bi);
            if (idx <= n && s[idx] == 'G') --ans;
        }
    }
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3660