/**
 * @author: Mackenzie
**/
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n;
    string s;
    cin >> n >> s;
    ll r = 0, g = 0, b = 0;
    forn(i, n) {
        r += s[i] == 'R', g += s[i] == 'G', b += s[i] == 'B';
    }
    ll ans = r * g * b;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int k = 2 * j - i;
            if (k < n && s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) ans--;
        }
    }
    cout << ans << endl;

    return 0;
}