#pragma GCC optimize("Ofast,fast-math,unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)v.size()
#define fi first
#define se second
#define sqrt(x) sqrt(abs(x))
#define sqr(x) ((x) * (x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define fill(x, y) memset(x, y, sizeof(x))
#define mp make_pair
#define pb emplace_back
#define popcnt __builtin_popcount
#define ctz __builtin_ctz

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;

template <class T> using indexed_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

template <class T, class U>
istream& operator >> (istream &in, pair <T, U> &p) {
    in >> p.first >> p.second;
    return in;
}

template <class T, class U>
ostream& operator << (ostream &out, pair <T, U> &p) {
    out << p.first << ' ' << p.second;
    return out;
}

template <class T>
istream& operator >> (istream &in, vector <T> &a) {
    for (T &i: a) in >> i;
    return in;
}

template <class T>
ostream& operator << (ostream &out, vector <T> &a) {
    for (T i: a) out << i << ' ';
    out << '\n';
    return out;
}

template <class T>
ostream& operator << (ostream &out, set <T> &a) {
    for (T i: a) out << i << ' ';
    out << '\n';
    return out;
}

void fastIO() {
    ios_base:: sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
}

int n;
string s;

struct node {
    int r, g, b;
    node(){};
    node(int r, int g, int b): r(r), g(g), b(b){};
};

signed main() {
    fastIO();

    cin >> n >> s;
    s = '.' + s;

    vector <node> v(n + 1, node(0, 0, 0));
    for (int i = 1; i <= n; ++i) {
        if (s[i] == 'R') v[i] = node(v[i - 1].r + 1, v[i - 1].g, v[i - 1].b);

        if (s[i] == 'G') v[i] = node(v[i - 1].r, v[i - 1].g + 1, v[i - 1].b);

        if (s[i] == 'B') v[i] = node(v[i - 1].r, v[i - 1].g, v[i - 1].b + 1);
    }

    ll ans = 0;
    for (int i = 1; i <= n - 2; ++i) {
        for (int k = i + 2; k <= n; ++k) {
            if (s[i] != s[k]) {
                if (i % 2 == k % 2) {
                    if (s[i] == 'R' && s[k] == 'G') {
                        ans += v[k].b - v[i].b - (s[(i + k) / 2] == 'B');
                    }

                    else if (s[i] == 'R' && s[k] == 'B') {
                        ans += v[k].g - v[i].g - (s[(i + k) / 2] == 'G');
                    }

                    else if (s[i] == 'G' && s[k] == 'R') {
                        ans += v[k].b - v[i].b - (s[(i + k) / 2] == 'B');
                    }

                    else if (s[i] == 'G' && s[k] == 'B') {
                        ans += v[k].r - v[i].r - (s[(i + k) / 2] == 'R');
                    }

                    else if (s[i] == 'B' && s[k] == 'R') {
                        ans += v[k].g - v[i].g - (s[(i + k) / 2] == 'G');
                    }

                    else if (s[i] == 'B' && s[k] == 'G') {
                        ans += v[k].r - v[i].r - (s[(i + k) / 2] == 'R');
                    }
                }

                else {
                    if (s[i] == 'R' && s[k] == 'G') {
                        ans += v[k].b - v[i].b;
                    }

                    else if (s[i] == 'R' && s[k] == 'B') {
                         ans += v[k].g - v[i].g;
                    }

                    else if (s[i] == 'G' && s[k] == 'R') {
                         ans += v[k].b - v[i].b;
                    }

                    else if (s[i] == 'G' && s[k] == 'B') {
                         ans += v[k].r - v[i].r;
                    }

                    else if (s[i] == 'B' && s[k] == 'R') {
                         ans += v[k].g - v[i].g;
                    }

                    else if (s[i] == 'B' && s[k] == 'G') {
                         ans += v[k].r - v[i].r;
                    }
                }
            }
        }
    }

    cout << ans;

    return 0;
}

/// ЗАПУСКАЕМ ГУСЯ:
/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */


Measured memory_bytes: 3736