/*▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ЗАПУСКАЕМ▒▀██████▄
░███▀▒▒▒▒▒ДЯДЮ▒▒▒▒▒▒▀█████
░▐██▒▒▒▒▒БОГДАНА▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄█████████████  █▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐*/
#include <iostream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
// #define endl '\n'
#define all(x) x.begin(), x.end()
#define int long long
#define mk(a, b) make_pair(a, b)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<int, int, int> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector< vector<int> > vvi;
typedef vector<char> vc;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1000000007;
// const int MAXN = 3e5;
const ld eps = 1e-6;
const ld eps2 = 1e-9;
const int MOD2 = 998244353;
const int dosz = 5e5;
const int SZ = (1<<18);
const ld PI = atan2l(0, -1);


void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
        // freopen("a.in", "r",stdin);
#else
       // freopen("mxnl.in", "r", stdin);
       // freopen("mxnl.out", "w", stdout);
#endif
}

void solve(){
    // cout << 1 << endl;
    int n;
    string s;
    cin >> n >> s;
    vvi suff(n, vi(3, 0));
    if(s[n-1]=='R'){
        suff[n-1][0] = 1;
    } else if(s[n-1]=='G'){
        suff[n-1][1] = 1;
    } else{
        suff[n-1][2] = 1;
    }
    for(int i=n-2; i>=0; i--){
        suff[i] = suff[i+1];
        if(s[i]=='R'){
            suff[i][0]++;
        } else if(s[i]=='G'){
            suff[i][1]++;
        } else{
            suff[i][2]++;
        }
    }
    int ans = 0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n-1; j++){
            if(s[i]!=s[j]){
                if(s[i] == 'R' && s[j] == 'G'){
                    ans += suff[j+1][2] - (j+(j-i)<n?(s[j+(j-i)]=='B'?1:0):0);
                } else if(s[i] == 'G' && s[j] == 'R'){
                    ans += suff[j+1][2] - (j+(j-i)<n?(s[j+(j-i)]=='B'?1:0):0);
                } else if(s[i] == 'R' && s[j] == 'B'){
                    ans += suff[j+1][1] - (j+(j-i)<n?(s[j+(j-i)]=='G'?1:0):0);
                }  else if(s[i] == 'B' && s[j] == 'R'){
                    ans += suff[j+1][1] - (j+(j-i)<n?(s[j+(j-i)]=='G'?1:0):0);
                } else if(s[i] == 'G' && s[j] == 'B'){
                    ans += suff[j+1][0] - (j+(j-i)<n?(s[j+(j-i)]=='R'?1:0):0);
                } else if(s[i] == 'B' && s[j] == 'G'){
                    ans += suff[j+1][0] - (j+(j-i)<n?(s[j+(j-i)]=='R'?1:0):0);
                }
            }
        }
    }

    cout << ans << endl;

}

signed main() {
    fast_io();
    int q = 1;
    // cout << fixed << setprecision(6);
    // cin >> q;
    // cout << 1 << endl;
    while(q--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 3764