/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define SZ(x)                       ll(x.size())

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e4 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n , ans , cnt[3] , A[MAXN] , C[MAXN][3][3];
string s;

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

    cin >> n >> s;
    for(ll i = 0 ; i < n ; i++){
        if(s[i] == 'R') A[i] = 0;
        if(s[i] == 'G') A[i] = 1;
        if(s[i] == 'B') A[i] = 2;
        cnt[A[i]]++;
    }

    ans = cnt[0] * cnt[1] * cnt[2];
    for(ll i = 0 ; i < n ; i++){
        for(ll j = i + 1 ; j < n ; j++){
            ll k = j + (j - i);
            if(k >= n)  continue;
            if(A[i] != A[j] && A[j] != A[k] && A[i] != A[k])    ans--;
        }
    }
    cout << ans << endl;

    return 0;
}
/*

*/
