#include <iostream>
#include <vector>

using namespace std;
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define reppe(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define repm(i, a, b) for (int i = (int)(a); i > (int)(b); --i)
#define repme(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)

typedef long long ll;

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    return GCD(b, a % b);
}

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<int> cR(N);
    vector<int> cG(N);
    vector<int> cB(N);

    if (S[0] == 'R') cR[0] = 1;
    if (S[0] == 'G') cG[0] = 1;
    if (S[0] == 'B') cB[0] = 1;
    repp(i, 1, N) {
        cR[i] = cR[i - 1];
        cG[i] = cG[i - 1];
        cB[i] = cB[i - 1];
        if (S[i] == 'R') cR[i] += 1;
        if (S[i] == 'G') cG[i] += 1;
        if (S[i] == 'B') cB[i] += 1;
    }

    long long res = 0;
    repp(i, 0, N) {
        repp(j, i + 1, N) {
            if (S[i] == 'R') {
                if (S[j] == 'G') {
                    res += cB[j - 1] - cB[i];
                    if ((i + j) % 2 == 0 && S[(i + j) / 2] == 'B') --res;
                } else if (S[j] == 'B') {
                    res += cG[j - 1] - cG[i];
                    if ((i + j) % 2 == 0 && S[(i + j) / 2] == 'G') --res;
                }
            } else if (S[i] == 'G') {
                if (S[j] == 'B') {
                    res += cR[j - 1] - cR[i];
                    if ((i + j) % 2 == 0 && S[(i + j) / 2] == 'R') --res;
                } else if (S[j] == 'R') {
                    res += cB[j - 1] - cB[i];
                    if ((i + j) % 2 == 0 && S[(i + j) / 2] == 'B') --res;
                }
            } else if (S[i] == 'B') {
                if (S[j] == 'R') {
                    res += cG[j - 1] - cG[i];
                    if ((i + j) % 2 == 0 && S[(i + j) / 2] == 'G') --res;
                } else if (S[j] == 'G') {
                    res += cR[j - 1] - cR[i];
                    if ((i + j) % 2 == 0 && S[(i + j) / 2] == 'R') --res;
                }
            }
        }
    }
    cout << res << endl;
}
