use std::collections::{HashMap, HashSet}; fn main() { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s: Vec = s.trim().chars().collect(); let mut strings = HashMap::new(); strings.insert(s.clone(), HashSet::>::new()); strings.entry(s).or_default().insert(vec![]); while !strings.keys().next().unwrap().is_empty() { let mut new_strings: HashMap, HashSet>> = HashMap::new(); for (rem, gen) in &strings { for s in gen { let mut new_s_left = s.clone(); new_s_left.push(rem[0]); new_strings .entry(rem[1..].to_vec()) .or_default() .insert(new_s_left); let mut new_s_right = s.clone(); new_s_right.push(rem[rem.len() - 1]); new_strings .entry(rem[..rem.len() - 1].to_vec()) .or_default() .insert(new_s_right); } } strings = new_strings; } println!("{}", strings.values().next().unwrap().len()); }