#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 500100, MAXK = 30;
const ll MOD = 998244353;
const int INF = 1e8;
const ld PI = asin(1) * 2;

void setIO () {
    FAST_IO;
}

void setIO (string s) {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

int n;
string s;
int a[MAXN];

ll pref[MAXN][3];

int main() {
	setIO();

    cin >> n >> s;
    ll ans = 0;
    FOR(i, 1, n) {
        if (s[i-1] == 'R') a[i] = 0;
        else if (s[i-1] == 'G') a[i] = 1;
        else a[i] = 2;
    }

    FOR(i, 1, n) {
        FOR(k, 0, 2) pref[i][k] = pref[i-1][k];
        pref[i][a[i]]++;
    }

    FOR(i, 1, n) FOR(k, i+2, n) {
        if (a[i] == a[k]) continue;
        int j = 0;
        while (a[i] == j || a[k] == j) {j++;}
        ans += pref[k-1][j]-pref[i][j];
        int mid = (k+i)/2;
        if ((k+i)%2 == 1) continue;
        if (a[mid] == j) ans--;
    }

    cout << ans;

	return 0;
}


