#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // Atcoder
    // template: cpp
    ll n;
    string s;
    cin >> n >> s;

    ll r = 0, g = 0, b = 0;
    for(auto &&i : s) {
        if(i == 'R')
            r++;
        else if(i == 'G')
            g++;
        else
            b++;
    }
    ll all = r * g * b;

    ll cnt = 0;

    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            if(s[i] == s[j])
                continue;
            ll k = 2 * j - i;
            if(k >= n || s[k] == s[i] || s[k] == s[j])
                continue;
            ++cnt;
        }
    }
    cout << all - cnt << endl;
}
