#include<bits/stdc++.h>

using namespace std;

int suff[4][4005];

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, ans = 0;
    cin >> n;
    string s;
    cin >> s;
    for (int i = n - 1; i >= 0; --i) {
        for (int j = 0; j <= 2; ++j) suff[j][i] = suff[j][i + 1];
        if (s[i] == 'R') suff[0][i]++;
        else if (s[i] == 'G') suff[1][i]++;
        else suff[2][i]++;
    }
    for (int i = 0; i < (int)s.size(); ++i) {
        for (int j = i + 1; j < (int)s.size() - 1; ++j) {
            int T = 2;
            if (s[i] == s[j]) continue;
            if ('R' != s[i] && s[j] != 'R') T = 0;
            else if ('G' != s[i] && s[j] != 'G') T = 1;
            ans += suff[T][j];
            int k = 2 * j - i;
            if (k < n && s[k] != s[i] && s[k] != s[j]) ans--;
        }
    }
    cout << ans << '\n';
    return 0;
}

