#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<vector<int>> rgb(3);
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') {
            rgb[0].push_back(i);
        } else if (s[i] == 'G') {
            rgb[1].push_back(i);
        } else {
            rgb[2].push_back(i);
        }
    }

    Int ans = 0;
    vector<int> t{0, 1, 2};
    do {
        for (auto e : rgb[t[0]]) {
            auto gitr = upper_bound(rgb[t[1]].begin(), rgb[t[1]].end(), e);
            for (; gitr != rgb[t[1]].end(); ++gitr) {
                auto bitr = upper_bound(rgb[t[2]].begin(), rgb[t[2]].end(), *gitr);
                while (bitr != rgb[t[2]].end()) {
                    if (*gitr - e != *bitr - *gitr) {
                        ans++;
                    }

                    ++bitr;
                }
            }

            auto gitr2 = upper_bound(rgb[t[1]].begin(), rgb[t[1]].end(), e);
            for (; gitr2 != rgb[t[1]].end(); ++gitr2) {
                auto bitr2 = upper_bound(rgb[t[2]].begin(), rgb[t[2]].end(), *gitr2);
                while (bitr2 != rgb[t[2]].end()) {
                    if (*gitr2 - e != *bitr2 - *gitr2) {
                        ans++;
                    }

                    ++bitr2;
                }
            }
        }

    } while (next_permutation(t.begin(), t.end()));

    cout << ans / 2 << endl;

    return 0;
}