use std::collections::HashMap; fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let mut n: Vec = n.trim().chars().collect(); let mut max_right = vec!['0'; n.len()]; let mut rpos = HashMap::new(); for (i, &c) in n.iter().enumerate().rev() { if i == n.len() - 1 { max_right[i] = c; } else { max_right[i] = c.max(max_right[i + 1]); } rpos.entry(c).or_insert(i); } for i in 0..n.len() { if max_right[i] != n[i] { n.swap(i, rpos[&max_right[i]]); break; } } let n: String = n.iter().collect(); println!("{}", n); }