#include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; string S; cin >> N >> S; if(N < 5){ cout << 0 << "\n"; return 0; } long long ans = 0; // p1 < p2 < p3 < p4 < p5 を全列挙 // かつ S[p1] == S[p3](かつその文字を a とする) // 他の3文字はすべて a と異なり、互いにも重複しない for(int p1 = 0; p1 < N; ++p1){ for(int p3 = p1 + 1; p3 < N; ++p3){ if(S[p3] != S[p1]) continue; // S[p1] (= a) と S[p3] (= a) が等しいペア for(int p2 = p1 + 1; p2 < p3; ++p2){ char b = S[p2]; if(b == S[p1]) continue; for(int p4 = p3 + 1; p4 < N; ++p4){ char c = S[p4]; if(c == S[p1] || c == b) continue; for(int p5 = p4 + 1; p5 < N; ++p5){ char d = S[p5]; if(d == S[p1] || d == b || d == c) continue; // (a, b, a, c, d) は条件を満たす ++ans; } } } } } cout << ans << "\n"; return 0; }