#include <bits/stdc++.h>

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define umax(m, x) (m = max(m, x));
#define umin(m, x) (m = min(m, x));

#define rng(v) v.begin(), v.end()
#define rrng(v) v.rbegin(), v.rend()

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

using ll = long long int;

using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;

using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;

inline void yn(bool f) { cout << (f ? "Yes" : "No") << endl; }


int main() {
    int n;
    cin >> n;

    string s;
    cin >> s;

    ll cnt = 0;

    int i1, i2, i3;
    char c1, c2, c3;

    rep(i, n - 2) {
        i1 = i;
        c1 = s[i];

        rep(j, i + 1, n - 1) {
            if (s[j] != c1) {
                i2 = j;
                c2 = s[j];

                rep(k, j + 1, n) {
                    if (s[k] != c1 && s[k] != c2) {
                        i3 = k;
                        c3 = s[k];

                        if (i2 - i1 != i3 - i2) {
                            cnt++;
                        }
                    }
                }
            }
        }
    }

    cout << cnt << endl;

    return 0;
}
