#include using namespace std; #define For(i, a, b) for(int i = (a); i < (b); i++) #define rep(i, n) For(i, 0, n) #define rFor(i, a, b) for(int i = (a); i >= (b); i--) #define ALL(v) (v).begin(), (v).end() #define rALL(v) (v).rbegin(), (v).rend() #define SZ(v) ((int)(v).size()) using lint = long long; using ld = long double; int INF = 2000000000; lint LINF = 1000000000000000000; struct SetupIo { SetupIo() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); } } setupio; int main() { int n; string s; cin >> n >> s; vector> v(26); rep(i, n) { v[s[i] - 'A'].emplace_back(i); } int ans = 0; rep(A, 26) { rep(i, SZ(v[A])) { For(j, i + 1, SZ(v[A])) { int a1 = v[A][i], a2 = v[A][j]; int cur = 1; rep(B, 26) { if (A == B) { continue; } rep(ii, SZ(v[B])) { int b = v[B][ii]; if (!(a1 < b && b < a2)) { continue; } rep(C, 26) { if (A == C || B == C) { continue; } rep(iii, SZ(v[C])) { int c = v[C][iii]; if (!(a2 < c)) { continue; } rep(D, 26) { if (A == D || B == D || C == D) { continue; } int l = upper_bound(ALL(v[D]), c) - v[D].begin(); int r = SZ(v[D]); ans += r - l; } } } } } } } } cout << ans << "\n"; }