#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;

    vector<ll> nums(3, 0);
    REP(i, N) {
        if(S[i] == 'R') nums[0]++;
        if(S[i] == 'G') nums[1]++;
        if(S[i] == 'B') nums[2]++;
    }

    ll tmp = nums[0] * nums[1] * nums[2];
    FOR(l, 1, (N+2)/2) {
        REP(i, N) {
            if(i + 2*l > N-1) continue;
            if(S[i] != S[i+l] && S[i+l] != S[i+2*l] && S[i] != S[i+2*l]) tmp--;
        }
    }

    cout << tmp << endl;

    return 0;
}