#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
#include <queue>
#include <functional>
#include <iterator>
#include <list>
#include <unordered_map>
#include <deque>
#include <math.h>
#include <tgmath.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int
#define pint pair<int, int>

#define M_DEBUG 1
#define PI 3.141592653589793

#define E '\n'

#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << "\n";}
#define INF (1e18)

const ll MAX = 1000000000;
const ll MOD = 1e9 + 7;

ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll aabs(ll a) {
    if (a < 0) return -a;
    return a;
}

//fast power
ll calc(ll a, ll b) {
    if (b == 0) return 1;
    else if (b % 2 == 0) {
        ll d = calc(a, b / 2);
        return (d * d) % MOD;
    }
    else return (a * calc(a, b - 1)) % MOD;
}

//fast combination
ll comb(ll n, ll a) {
    ll b = 1, c = 1;
    for (ll i = 1; i <= a; ++i) {
        b = b * i % MOD;
        c = c * (n - i + 1) % MOD;
    }

    return c * calc(b, MOD - 2) % MOD;
}

ll comb2(ll a) {
    ll b = a / 2;
    if (a % 2) {
        b = (a - 1) / 2;
        return (b * a);
    }
    return (b * (a - 1));
}

int dfs(int x, int y, int z) {
    if (x == a && y == b && z == c) return 1;
    
    int ans = 0;
    if (x != a) ans += dfs(x + 1, y, z);
    if (x >= y + 1/* && y != b*/) ans += dfs(x, y + 1, z);
    if (y >= z + 1/* && z != c*/) ans += dfs(x, y, z + 1); 

    return ans;
}

uint64_t gcd_impl( uint64_t n, uint64_t m ) {
        for( int i = 0; i < 10; ++i ) {
                uint64_t t = n - m;
                bool q = m > t;
                n = q ? m : t;
                m = q ? t : m;
                if( m == 0 ) { return n; }
        }
        return gcd_impl( m, n % m );
}

uint64_t gcd( uint64_t n, uint64_t m ) {
        return n > m ? gcd_impl( n, m ) : gcd_impl( m, n );
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string ss;
    cin >> n >> ss;
    vector<vector<int>> rgb(n, vector<int>(3, 0));

    if (ss[0] == 'R') rgb[0][0] = 1;
    else if (ss[0] == 'G') rgb[0][1] = 1;
    else if (ss[0] == 'B') rgb[0][2] = 1;

    rep (i, 1, n) {
        rgb[i][0] = rgb[i - 1][0];
        rgb[i][1] = rgb[i - 1][1];
        rgb[i][2] = rgb[i - 1][2];
        if (ss[i] == 'R') rgb[i][0] = rgb[i - 1][0] + 1;
        else if (ss[i] == 'G') rgb[i][1] = rgb[i - 1][1] + 1;
        else if (ss[i] == 'B') rgb[i][2] = rgb[i - 1][2] + 1;
    }

    unsigned long long int aa = 0;
    rep(i, 0, n) {
        rep (j, i + 1, n) {
            if (ss[i] == ss[j]) continue;
            if (ss[i] == 'R' && ss[j] == 'B')
                aa += rgb[n - 1][1] - rgb[j][1];
            else if (ss[i] == 'R' && ss[j] == 'G')
                aa += rgb[n - 1][2] - rgb[j][2];
            else if (ss[i] == 'G' && ss[j] == 'R')
                aa += rgb[n - 1][2] - rgb[j][2];
            else if (ss[i] == 'G' && ss[j] == 'B')
                aa += rgb[n - 1][0] - rgb[j][0];
            else if (ss[i] == 'B' && ss[j] == 'R')
                aa += rgb[n - 1][1] - rgb[j][1];
            else if (ss[i] == 'B' && ss[j] == 'G')
                aa += rgb[n - 1][0] - rgb[j][0];
            k = j + j - i;
            if (k >= n) continue;
            if (ss[i] != ss[j] && ss[j] != ss[k] && ss[i] != ss[k]) aa--;
        }
        
    }

    cout << aa << endl;


    return 0;
}



Measured memory_bytes: 3848