// Template //
#include<bits/stdc++.h>
using namespace std;

// マクロ //
#define rep(i,N) for(int i = 0; i < (int)(N); i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
template<class T> lint gcd(T a, T b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T> lint lcm(T a, T b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

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

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

// 定数 //
#define pi acos(-1)
#define mod 1000000007
#define MOD 998244353
#define inf ((1LL << 62) - 1 + (1LL << 62))

// キーワード //
#define elif else if

// End of Template //


    

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
        
    int N;
    cin >> N;
    string S;
    cin >> S;
    int R_, G_, B_;

    vi isR;
    vi isG;
    vi isB;
    lint tori = 0;
    lint r = 0, g = 0, b = 0;
    rep(i, N) {
        if (S[i] == 'R') { 
            r++; 
            isR.push_back(i);
        }
        if (S[i] == 'G') { 
            g++;
            isG.push_back(i);
        }
        if (S[i] == 'B') { 
            b++; 
            isB.push_back(i);
        }
    }
    tori += r * g * b;
    lint cnt = 0;
    rep(i, isR.size()) {
        R_ = isR[i];
        rep(j, isG.size()) {
            G_ = isG[j];
            if (isG[j] * 2 - isR[i] > 4010) break;
            if (isG[j] * 2 - isR[i] < -10) continue;
            if (binary_search(all(isB), isG[j] * 2 - isR[i])) cnt++;
        }
    }
    
    rep(i, isG.size()) {
        G_ = isG[i];
        rep(j, isB.size()) {
            B_ = isB[j];
            if (isB[j] * 2 - isG[i] > 4010) break;
            if (isB[j] * 2 - isG[i] < -10) continue;
            if (binary_search(all(isR), isB[j] * 2 - isG[i])) cnt++;
        }
    }
    
    rep(i, isB.size()) {
        B_ = isB[i];
        rep(j, isR.size()) {
            R_ = isR[j];
            if (isR[j] * 2 - isB[i] > 4010) break;
            if (isR[j] * 2 - isB[i] < -10) continue;
            if (binary_search(all(isG), isR[j] * 2 - isB[i])) cnt++;
        }
    }
    
   /*rep(i, isG.size()) {
        G_ = isG[i];
        rep(j, isR.size()) {
            R_ = isR[j];
            if (isR[j] * 2 - isG[i] > 4010) break;
            if (isR[j] * 2 - isG[i] < -10) continue;
            if (binary_search(all(isB), isR[j] * 2 - isG[i])) cnt++;
        }
    }
    
    rep(i, isB.size()) {
        B_ = isB[i];
        rep(j, isG.size()) {
            G_ = isG[j];
            if (isG[j] * 2 - isB[i] > 4010) break;
            if (isG[j] * 2 - isB[i] < -10) continue;
            if (binary_search(all(isR), isG[j] * 2 - isB[i])) cnt++;
        }
    }
    
    rep(i, isG.size()) {
        G_ = isG[i];
        rep(j, isB.size()) {
            B_ = isB[j];
            if (isB[j] * 2 - isG[i] > 4010) break;
            if (isB[j] * 2 - isG[i] < -10) continue;
            if (binary_search(all(isR), isB[j] * 2 - isG[i])) cnt++;
        }
    }*/

    tori -= cnt;
    cou(tori);
}


Measured memory_bytes: 3724