#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N;
    string S;
    cin >> N >> S;

    vector<int> G;
    vector<int> R;
    vector<int> B;

    for (int i = 0; i < N; i++)
    {
        if (S.at(i) == 'R')
        {
            R.push_back(i + 1);
        }
        else if (S.at(i) == 'G')
        {
            G.push_back(i + 1);
        }
        else if (S.at(i) == 'B')
        {
            B.push_back(i + 1);
        }
    }

    /*int tmp = 0;
    int x1, x2, x3, x4,x5,x6;
    ll ans = 0;
    for (int i = 0; i < R.size(); i++)
    {
        for (int j = 0; j < G.size(); j++)
        {
            for (int k = 0; k < B.size(); k++)
            {
                tmp = max(R.at(i), G.at(j)) - min(R.at(i), G.at(j));
                //cout << tmp << endl;
                x1 = R.at(i) + tmp;
                x2 = R.at(i) - tmp;
                x3 = G.at(j) + tmp;
                x4 = G.at(j) - tmp;
                if (!(B.at(k) == x1) && !(B.at(k) == x2) && !(B.at(k) == x3) && !(B.at(k) == x4))
                {
                    if(R.at(i)<G.at(j)){
                        x5 = G.at(j) - B.at(k);
                        x6 = B.at(k) - R.at(i);
                        if(!(x5==x6)){
                            ans++;
                        }
                    }
                    if (G.at(j) < R.at(i))
                    {
                        x5 = R.at(i) - B.at(k);
                        x6 = B.at(k) - G.at(j);
                        if ( !(x5 == x6))
                        {
                            ans++;
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;*/

    int tmp1, tmp2, tmp3;
    ll ans = 0;
    for (ll i = 0; i < N; i++)
    {
        for (ll j = 1; i + 2 * j < N; j++)
        {
            if(i+2*j<N){
                if(S.at(i)=='R'){
                    tmp1 = 1;
                }
                else if(S.at(i)=='G'){
                    tmp1 = 2;
                }
                else if(S.at(i)=='B'){
                    tmp1 = 4;
                }
                if (S.at(i+j) == 'R')
                {
                    tmp2 = 1;
                }
                else if (S.at(i+j) == 'G')
                {
                    tmp2 = 2;
                }
                else if (S.at(i+j) == 'B')
                {
                    tmp2 = 4;
                }
                if (S.at(i + 2*j) == 'R')
                {
                    tmp3 = 1;
                }
                else if (S.at(i + 2*j) == 'G')
                {
                    tmp3 = 2;
                }
                else if (S.at(i + 2*j) == 'B')
                {
                    tmp3 = 4;
                }
                if(tmp1+tmp2+tmp3==7){
                    ans++;
                }
            }
        }
    }

    cout << R.size()*G.size()*B.size()-ans << endl;
}


Measured memory_bytes: 3676