#include<bits/stdc++.h>
#define int int64_t
using namespace std;

const int M = 1e9+7;

int bs(vector<int> &v , int idx , int rest) {
    int n = v.size();
    int l = 0 , r = n-1 , ans = -1;
    while(l <= r) {
        int mid = l + (r-l)/2;
        if(v[mid] >= idx) {
            ans = mid;
            r = mid-1;
        }
        else l = mid+1;
    }
    int num = 0;
    if(ans != -1) num = n - ans;
    bool found = false;
    l = 0 , r = n-1;
    while(l <= r) {
        int mid = l + (r-l)/2;
        if(v[mid] > rest) r = mid-1;
        else if(v[mid] < rest) l = mid+1;
        else {
            found = true;
            break;
        }
    }
    if(found) num--;
    return num;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    string s;
    cin >> s;
    unordered_map<char , vector<int>> map;
    for(int i = 0; i < n; i++) {
        map[s[i]].push_back(i);
    }
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            if(s[i] != s[j]) {
                int d = j-i;
                int num = 0;
                for(auto p : map) {
                    if(p.first != s[i] && p.first != s[j]) {
                        num = bs(p.second , j+1 , j+d);
                        break;
                    }
                }
                cnt += num;
            }
        }
    }
    cout << cnt << "\n";
    return 0;
}
