#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
//#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}
int judge(char a) {
    if(a == 'R') return 1;
    if(a == 'G') return 2;
    if(a == 'B') return 3;
}
signed main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    //j,k決め打ち
    vector<vector<int>> V(3, vector<int>(N + 1, 0));
    rep(i, N) {
        if(S[i] == 'R') V[0][i + 1]++;
        if(S[i] == 'G') V[1][i + 1]++;
        if(S[i] == 'B') V[2][i + 1]++;
        rep(j, 3) V[j][i + 1] += V[j][i];
    }
    int ans = 0;
    for(int k = N - 1; k >= 2; k--) {
        for(int j = k - 1; j > 0; j--) {
            int a = judge(S[k]), b = judge(S[j]);
            if(a == b) continue;
            int c = 6 / a / b;
            ans += V[c - 1][j];
            if(j - (k - j) >= 0 && judge(S[j - (k - j)]) == c) ans--;
        }
    }
    cout << ans << endl;
}
