#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 4005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;

int fact[MAXN];
bool vis[MAXN];
vector<int> primes;
void sieve(int x) {
    for (int i = 2; i * i <= x; i++) {
        if (vis[i]) continue;
        for (int j = i * i; j <= x; j += i) {
            vis[j] = true;
        }
    }
}
void getprimes(int x) {
    sieve(x);
    for (int i = 2; i <= x; i++) {
        if (!vis[i]) primes.push_back(i);
    }
}

int mob[MAXN];
void mobiusWithP(int x) {
    mob[1] = 1;
    for (int i = 2; i <= x; i++) {
        if (!vis[i]) {
            primes.push_back(i);
            mob[i] = -1;
        }
        for (auto p : primes) {
            if (i * p > x) break;
            vis[i * p] = true;
            if (i % p)
                mob[i * p] = -mob[i];
            else {
                mob[i * p] = 0;
                break;
            }
        }
    }
}
ll modmul(ll a, ll b, ll p) {
    a %= p;
    ll ans = 0;
    while (b) {
        if (b & 1) ans = (ans + a) % p;
        b >>= 1;
        a = (a + a) % p;
    }
    return ans;
}

void extgcd(ll a, ll b, ll& d, ll& x, ll& y) {
    if (!b) {
        d = a;
        x = 1;
        y = 0;
    } else {
        extgcd(b, a % b, d, y, x);
        y -= x * (a / b);
    }
}

inline ll getInv(ll x, ll mod) {
    ll g, a, b;
    extgcd(x, mod, g, a, b);
    return (a % mod + mod) % mod;
}

ll choose(int n, int k) {
    return fact[n] * getInv(fact[k] * fact[n - k] % MOD, MOD) % MOD;
}

// Given: A list of reminder equation x = a_i (mod m_i)
ll crt(int len, int* a, int* m) {
    ll M = 1, x = 0;
    for (int i = 0; i < len; i++) M *= m[i];
    for (int i = 0; i < len; i++) {
        ll w = M / m[i];
        x += ((w * a[i]) % M) * getInv(w, m[i]) % M;
        x %= M;
    }
    return (x % M + M) % M;
}
int fastExp(ll x, ll p, int mod) {
    ll ans = 1;
    while (p) {
        if (p & 1) ans = ans * x % mod;
        x = x * x % mod;
        p >>= 1;
    }
    return ans;
}
// Given: a^x = b (mod p)
ll bsgs(int a, int b, int p) {
    if (a % p == 0 && b) return -1;
    ll m = (ll)sqrt(p + 0.5);
    ll invM = getInv(fastExp(a, m, p), p);
    // a^i = e[i] mod p
    map<int, int> x;
    x[1] = 0;
    ll base = 1;
    for (int i = 1; i < m; i++) {
        base = base * a % p;
        if (!x.count(base)) x[base] = i;
    }
    for (ll i = 0; i < p / m; i++) {
        if (x.count(b)) return i * m + x[b];
        b = b * invM % p;
    }
    return -1;
}

int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
bool fermatTest(int p) {
    for (int i = 2; i < p; i++) {
        if (gcd(i, p) == 1 && fastExp(i, p - 1, p) != 1) {
            return false;
        }
    }
    return true;
}
bool isPrime(int x) {
    for (ll i = 2; i * i <= x; i++)
        if (x % i == 0) return false;
    return true;
}
char str[MAXN];
int pref[MAXN][3];
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#else
#endif
    scanf("%d", &n);
    scanf("%s", str + 1);
    for (int i = 1; i <= n; i++) {
        if (str[i] == 'R')
            str[i] = 0;
        else if (str[i] == 'G')
            str[i] = 1;
        else
            str[i] = 2;
    }
    for (int i = n; i >= 1; i--) {
        for (int j = 0; j < 3; j++) {
            if (str[i] == j) {
                pref[i][j] = pref[i + 1][j] + 1;
            } else {
                pref[i][j] = pref[i + 1][j];
            }
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            if (str[i] != str[j]) {
                int r = j + (j - i);
                if (r <= n) pref[j + 1][str[r]]--;
                int c = 3 - str[i] - str[j];
                ans += pref[j + 1][c];
                if (r <= n) pref[j + 1][str[r]]++;
            }
        }
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 3848