#include <bits/stdc++.h> 

using namespace std;

typedef long long ll;

#define rep(i,p,q) for(ll i = p; i < q; i++)
#define repD(i,p,q) for(ll i = p; i > q; i--)

int main(void){
    ll n;
    string s;
    cin >> n >> s;
    vector<ll> r = vector<ll>(n,0);
    vector<ll> g = vector<ll>(n,0);
    vector<ll> b = vector<ll>(n,0);
    repD(i,n-1,-1){
        if(i == n - 1){
             if(s[i] == 'R') r[i] = 1;
        }
        else {
            if(s[i] == 'R') r[i] = r[i+1] + 1;
            else r[i] = r[i+1];
        }
    }
    repD(i,n-1,-1){
        if(i == n - 1){
             if(s[i] == 'G') g[i] = 1;
        }
        else {
            if(s[i] == 'G') g[i] = g[i+1] + 1;
            else g[i] = g[i+1];
        }
    }
    repD(i,n-1,-1){
        if(i == n - 1){
             if(s[i] == 'B') b[i] = 1;
        }
        else {
            if(s[i] == 'B') b[i] = b[i+1] + 1;
            else b[i] = b[i+1];
        }
    }
    ll ans = 0;
    rep(i,0,n - 2){
        switch(s[i]){
            case 'R':
                rep(j,i+1,n-1){
                    if(s[j] == 'G'){
                        ans += b[j+1];
                        if(2 * j - i < n && s[2 * j - i] == 'B') ans--;
                    }
                    else if(s[j] == 'B'){
                        ans += g[j+1];
                        if(2 * j - i < n && s[2 * j - i] == 'G') ans--;
                    }
                }
            break;
            case 'G':
                rep(j,i+1,n-1){
                    if(s[j] == 'R'){
                        ans += b[j+1];
                        if(2 * j - i < n && s[2 * j - i] == 'B') ans--;
                    }
                    else if(s[j] == 'B'){
                        ans += r[j+1];
                        if(2 * j - i < n && s[2 * j - i] == 'R') ans--;
                    }
                }
            break;
            case 'B':
                rep(j,i+1,n-1){
                    if(s[j] == 'G'){
                        ans += r[j+1];
                        if(2 * j - i < n && s[2 * j - i] == 'R') ans--;
                    }
                    else if(s[j] == 'R'){
                        ans += g[j+1];
                        if(2 * j - i < n && s[2 * j - i] == 'G') ans--;
                    }
                }
            break;
        }
    }
    cout << ans << endl;
}