#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    vv<int> left = vvec(N + 1, 3, 0), right = left;
    rep(i, N) {
        rep(j, 3) left[i + 1][j] = left[i][j];
        if (S[i] == 'R') left[i + 1][0]++;
        else if (S[i] == 'G') left[i + 1][1]++;
        else left[i + 1][2]++;
    }
    for (int i = N - 1; i >= 0; --i) {
        rep(j, 3) right[i][j] = right[i + 1][j];
        if (S[i] == 'R') right[i][0]++;
        else if (S[i] == 'G') right[i][1]++;
        else right[i][2]++;
    }

    ll ans = 0;
    rep(i, 1, N - 1) {
        if (S[i] == 'R') {
            ans += left[i][1] * right[i + 1][2];
            ans += left[i][2] * right[i + 1][1];
            for (int j = i - 1, k = i + 1; j >= 0 && k < N; --j, ++k) {
                if (S[j] == 'G' && S[k] == 'B') ans--;
                else if (S[j] == 'B' && S[k] == 'G') ans--;
            }
        }
        else if (S[i] == 'G') {
            ans += left[i][0] * right[i + 1][2];
            ans += left[i][2] * right[i + 1][0];
            for (int j = i - 1, k = i + 1; j >= 0 && k < N; --j, ++k) {
                if (S[j] == 'R' && S[k] == 'B') ans--;
                else if (S[j] == 'B' && S[k] == 'R') ans--;
            }
        }
        else {
            ans += left[i][0] * right[i + 1][1];
            ans += left[i][1] * right[i + 1][0];
            for (int j = i - 1, k = i + 1; j >= 0 && k < N; --j, ++k) {
                if (S[j] == 'R' && S[k] == 'G') ans--;
                else if (S[j] == 'G' && S[k] == 'R') ans--;
            }
        }
    }
    write(ans);
}