#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")
#pragma optimize("fast-math")

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
#define endl '\n'
#define ull unsigned long long
#define si short int
#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define piii pair<pair<int, int>, int>
#define all(vec) (vec).begin(), (vec).end()
#define piiii pair<pair<int, int>, pair<int, int>>

void solve() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<int> G(n);
    vector<int> R(n);
    vector<int> B(n);
    for(int i=0;i<n;i++){
        if(s[i]=='G') G[i]=1;
        if(s[i]=='B') B[i]=1;
        if(s[i]=='R') R[i]=1;
    }
    ll ans=0;
    for(int i=1;i<n-1;i++){
        if(s[i]=='G'){
            ll le=0, re=0;
            for(int j=0;j<i;j++){
                if(s[j]=='B') le++;
            }
            for(int j=i+1;j<n;j++){
                if(s[j]=='R') re++;
            }
            le*=re;
            ans+=le;
            le=re=0;
            for(int j=0;j<i;j++){
                if(s[j]=='R') le++;
            }
            for(int j=i+1;j<n;j++){
                if(s[j]=='B') re++;
            }
            le*=re;
            ans+=le;
            for(int j=1;j+i<n && i-j>=0;j++){
                if(s[j+i]!=s[i-j] && s[j+i]!='G' && s[i-j]!='G'){
                    ans--;
                }
            }
        }
        else if(s[i]=='B'){

            ll le=0, re=0;
            for(int j=0;j<i;j++){
                if(s[j]=='G') le++;
            }
            for(int j=i+1;j<n;j++){
                if(s[j]=='R') re++;
            }
            le*=re;
            ans+=le;
            le=re=0;
            for(int j=0;j<i;j++){
                if(s[j]=='R') le++;
            }
            for(int j=i+1;j<n;j++){
                if(s[j]=='G') re++;
            }
            le*=re;
            ans+=le;
            for(int j=1;j+i<n && i-j>=0;j++){

                if(s[j+i]!=s[i-j] && s[j+i]!='B' && s[i-j]!='B'){
                    ans--;
                }
            }
        }
        else{

            ll le=0, re=0;
            for(int j=0;j<i;j++){
                if(s[j]=='B') le++;
            }
            for(int j=i+1;j<n;j++){
                if(s[j]=='G') re++;
            }
            le*=re;
            ans+=le;
            le=re=0;
            for(int j=0;j<i;j++){
                if(s[j]=='G') le++;
            }
            for(int j=i+1;j<n;j++){
                if(s[j]=='B') re++;
            }
            le*=re;
            ans+=le;
            for(int j=1;j+i<n && i-j>=0;j++){
                if(s[j+i]!=s[i-j] && s[j+i]!='R' && s[i-j]!='R'){
                    ans--;
                }
            }
        }
    }
    cout<<ans;

}

void testcases(int n) {
    n = 1 - n;
    if (!n) cin >> n;
    for (int i = 0; i < n; i++) {
        solve();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "r", stdin);
    //f=fopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "w");
    //freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "w", stdout);

    unsigned int beg_time = clock();
    testcases(0);
    // 0 - no t, 1 - with t

    unsigned int end_time = clock();
    //cout << endl << endl << end_time - beg_time;
    return 0;
}