#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    string S;
    cin >> N >> S;
    vector<int> r(N + 1, 0), g(N + 1, 0), b(N + 1, 0);
    rep(i, N) {
        r[i + 1] = r[i];
        g[i + 1] = g[i];
        b[i + 1] = b[i];
        if (S[i] == 'R') r[i + 1]++;
        if (S[i] == 'G') g[i + 1]++;
        if (S[i] == 'B') b[i + 1]++;
    }
    ll ans = 0;
    rep(i, N - 2) {
        for (int j = i + 2; j < N; j++) {
            if (S[i] == S[j]) continue;
            if ((S[i] == 'R' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'R')) {
                ans += b[j] - b[i];
                if ((i + j) % 2 == 0 && S[(i + j) / 2] == 'B') ans--;
            }
            if ((S[i] == 'R' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'R')) {
                ans += g[j] - g[i];
                if ((i + j) % 2 == 0 && S[(i + j) / 2] == 'G') ans--;
            }
            if ((S[i] == 'G' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'G')) {
                ans += r[j] - r[i];
                if ((i + j) % 2 == 0 && S[(i + j) / 2] == 'R') ans--;
            }
        }
    }
    cout << ans << "\n";
}