use std::collections::BTreeSet; use proconio::{fastout, input, marker::Chars}; const DIRS: [(isize, isize); 4] = [(0, 1), (1, 0), (0, -1), (-1, 0)]; trait OrdExt { fn chmax(&mut self, other: Self) -> bool; fn chmin(&mut self, other: Self) -> bool; } impl OrdExt for T { fn chmax(&mut self, other: Self) -> bool { if *self < other { *self = other; true } else { false } } fn chmin(&mut self, other: Self) -> bool { if *self > other { *self = other; true } else { false } } } #[fastout] fn main() { input! { n: usize, s: Chars } let mut ans = 0; for a in 0..n { for b in a + 1..n { for c in b + 1..n { for d in c + 1..n { for e in d + 1..n { let t = [s[a], s[b], s[c], s[d], s[e]]; if is_cpctf_like(t) { ans += 1; } } } } } } println!("{}", ans); } fn is_cpctf_like(s: [char; 5]) -> bool { s[0] == s[2] && BTreeSet::from(s).len() == 4 }