#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T& a, const T& b)
{
        if (a < b) {
                    a = b;
                            return 1;
                                }
            return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
        if (b < a) {
                    a = b;
                            return 1;
                                }
            return 0;
}

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define F first
//#define S second

typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1000000;
const int minf = -1000000;
const ll lnf = 1e12;
const ll mlnf = -1e12;
const double e = 1e-10;

void debug_vector(vector<int>& v)
{
    int n = v.size();
    for (int i = 0; i < n; i++) {
        cout << v[i] << " ";
    }
    cout << endl;
}


//////////////////////
//// coding start ////
//////////////////////

// global variet


long long cal(long long a, long long b);
long long second_condition(int locate);

void solve();

int N;
string S;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

long long cal(long long a, long long b){
    return a * (a - 1) * b / 2;
}


long long second_condition(int locate){
    int limit = min(locate, N-1 - locate);
    long long res = 0;
    for (int i = 1; i <= limit; i++){
        set<char> tmp;
        tmp.insert(S[locate]);
        tmp.insert(S[locate + i]);
        tmp.insert(S[locate - i]);
        if (tmp.size() == 3) res++;
    }
    return res;
}

void solve(){
    cin >> N;
    cin >> S;
    long long ans = N * (N-1) * (N-2) / 6;
    long long r, g, b;
    r = 0;
    g = 0;
    b = 0;
    for (int i = 0; i < N; i++){
        if (S[i] == 'R'){
            r++;
        }else if(S[i] == 'G'){
            g++;
        }else{
            b++;
        }
    }
    for (int i = 1; i < N - 1; i++){
        ans -= second_condition(i);
    }

    ans -= cal(r, g);
    ans -= cal(g, r);
    ans -= cal(g, b);
    ans -= cal(b, g);
    ans -= cal(r, b);
    ans -= cal(b, r);
    ans -= r * (r-1) * (r-2) / 6;
    ans -= g * (g-1) * (g-2) / 6;
    ans -= b * (b-1) * (b-2) / 6;
    printf("%lld\n", ans);
}

