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

int64_t solve(const string &S, char a, char b, char c) {
    int N = S.size();
    int64_t A = 0, C = 0;
    int64_t res = 0;
    for(int i = 0; i < N; ++i) C += (S[i] == c);
    for(int i = 0; i < N; ++i) {
        if(S[i] == a) A++;
        if(S[i] == b) res += A * C;
        if(S[i] == c) C--;
    }
    return res;
}

int main() {
    int N; cin >> N;
    string S; cin >> S;
    int64_t ans = 0;
    ans += solve(S, 'R', 'G', 'B');
    ans += solve(S, 'B', 'G', 'R');
    ans += solve(S, 'B', 'R', 'G');
    ans += solve(S, 'G', 'R', 'B');
    ans += solve(S, 'G', 'B', 'R');
    ans += solve(S, 'R', 'B', 'G');
    for(int j = 1; j < N - 1; ++j) {
        for(int d = 0; d < N; ++d) {
            int i = j - d, k = j + d;
            if(i < 0 or k >= N) continue;
            if(S[i] != S[j] and S[i] != S[k] and S[j] != S[k]) ans--;
        }
    }
    cout << ans << '\n';
    return 0;
}
