// https://atcoder.jp/contests/abc162/tasks/abc162_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    string s;
    cin >> s;
    set<int> tr, tg, tb;
    REP(i, N) {
        if (s[i] == 'R') {
            tr.insert(i);
        } else if (s[i] == 'G') {
            tg.insert(i);
        } else {
            tb.insert(i);
        }
    }
    int sum = 0;
    REP(i, N - 2) {
        FOR(j, i + 1, N - 1) {
            if (s[i] == s[j])
                continue;
            set<char> st;
            st.insert(s[i]);
            st.insert(s[j]);
            int t = 0;
            if (st.count('R') == 0) {
                t = distance(lower_bound(ALL(tr), j + 1), tr.end());
                if (tr.count(2 * j - i) > 0)
                    t--;
            } else if (st.count('G') == 0) {
                t = distance(lower_bound(ALL(tg), j + 1), tg.end());
                if (tg.count(2 * j - i) > 0)
                    t--;
            } else {
                t = distance(lower_bound(ALL(tb), j + 1), tb.end());
                if (tb.count(2 * j - i) > 0)
                    t--;
            }
            sum += t;
        }
    }

    cout << sum << endl;

    return 0;
}
