/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 4010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, a[MAXN];
vector<int> f[3];
string s;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> s;
    s = " " + s;
    FOR(i,1,n)
        if (s[i] == 'R') a[i] = 0;
        else if (s[i] == 'G') a[i] = 1;
        else a[i] = 2;
    FOR(i,1,n) f[a[i]].push_back(i);
    ll res = 0;
    FOR(i,1,n)
        FOR(j,i+1,n) {
            if (a[i] == a[j]) continue;
            int l = j+1, val = 3 - a[i] - a[j], diff = j - i;
            int dau = 0, cuoi = SZ(f[val])-1;
            while (dau <= cuoi) {
                int mid = (dau + cuoi) >> 1;
                if (f[val][mid] >= l) cuoi = mid-1;
                else dau = mid+1;
            }
            if (dau >= 0 && dau < SZ(f[val])) {
                int num = SZ(f[val]) - dau;
                if (j + diff <= n && a[j + diff] == val) num--;
                res += num;
            }
        }
    cout << res;
    return 0;
}
