fn main() { let mut buf = String::new(); let mut input = { use std::io::Read; std::io::stdin().read_to_string(&mut buf).unwrap(); buf.split_whitespace() }; let n: String = input.next().unwrap().parse().unwrap(); let n_2: String = n .chars() .map(|c| match c { 'A' => String::from("1010"), 'B' => String::from("1011"), 'C' => String::from("1100"), 'D' => String::from("1101"), 'E' => String::from("1110"), 'F' => String::from("1111"), _ => unreachable!(), }) .collect(); let n_8: String = n_2 .chars() .rev() .enumerate() .fold(String::new(), |acc, (i, c)| { if i % 3 == 0 && i != 0 { String::from(c) + "," + acc.as_str() } else { String::from(c) + acc.as_str() } }) .split(",") .map(String::from) .map(|s| match s.len() { 1 => String::from("00") + s.as_str(), 2 => String::from("0") + s.as_str(), _ => s, }) .map(|s| match s.as_str() { "000" => String::from("0"), "001" => String::from("1"), "010" => String::from("2"), "011" => String::from("3"), "100" => String::from("4"), "101" => String::from("5"), "110" => String::from("6"), "111" => String::from("7"), _ => unreachable!(), }) .collect(); let mut count = vec![0; 8]; for c in n_8.chars() { let i = c.to_digit(8).unwrap() as usize; count[i] += 1; } let max = count.iter().fold(0, |acc, &k| acc.max(k)); let output = count .iter() .enumerate() .filter(|(_, k)| **k == max) .map(|(i, _)| format!("{}", i)) .collect::>() .join(" "); println!("{}", output); }