#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
// Welcome to my source code!

int main() {
    int n;
    string s;
    cin >> n >> s;
    int R[n + 1], G[n + 1], B[n + 1];
    R[0] = G[0] = B[0] = 0;
    for (int i = 1; i <= n; i++) {
        R[i] = R[i - 1];
        G[i] = G[i - 1];
        B[i] = B[i - 1];
        if (s[i - 1] == 'R') R[i]++;
        else if (s[i - 1] == 'G') G[i]++;
        else B[i]++;
    }
    ll ans = 0;
    for (int i = 0; i < n - 2; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            if (s[i] == s[j]) continue;
            bool r = false, g = false, b = false;
            if (s[i] == 'R' || s[j] == 'R') r = true;
            if (s[i] == 'G' || s[j] == 'G') g = true;
            if (s[i] == 'B' || s[j] == 'B') b = true;
            if (!r) {
                int t = j - i;
                ans += R[n];
                if (1 <= j + t + 1 && j + t + 1 <= n) {
                    ans -= R[j + t + 1];
                    ans += R[j + t + 1] - (R[j + t + 1] - R[j + t]);
                }
                ans -= R[j + 1];
            } else if (!g) {
                int t = j - i;
                ans += G[n];
                if (1 <= j + t + 1 && j + t + 1 <= n) {
                    ans -= G[j + t + 1];
                    ans += G[j + t + 1] - (G[j + t + 1] - G[j + t]);
                }
                ans -= G[j + 1];
            } else {
                int t = j - i;
                ans += B[n];
                if (1 <= j + t + 1 && j + t + 1 <= n) {
                    ans -= B[j + t + 1];
                    ans += B[j + t + 1] - (B[j + t + 1] - B[j + t]);
                }
                ans -= B[j + 1];
            }
        }
    }
    cout << ans << endl;
}