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

int cnt[3];
int pos[3][4000+1];

void solve(long long N, std::string S){
    for (int i = 0; i < N; i++) {
        if (S[i] == 'R') pos[0][cnt[0]++] = i;
        else if (S[i] == 'G') pos[1][cnt[1]++] = i;
        else pos[2][cnt[2]++] = i;
    }
    set<tuple<int, int, int>> res;
    for (int i = 0; i < cnt[0]; i++) {
        for (int j = 0; j < cnt[1]; j++) {
            for (int k = 0; k < cnt[2]; k++) {
                int tmp_min = min(pos[2][k], min(pos[0][i], pos[1][j]));
                int tmp_max = max(pos[2][k], max(pos[0][i], pos[1][j]));
                int middle = pos[2][k] + pos[1][j] + pos[0][i] - tmp_min - tmp_max;
                if (tmp_max - middle != middle - tmp_min && tmp_max > middle && tmp_min < middle) {
                    res.insert(make_tuple(tmp_min, middle, tmp_max));
                }
            }
        }
    }
    cout << res.size() << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}
