use std::collections::VecDeque; fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut v: Vec = vec![-1; n + 1]; let mut q: VecDeque = VecDeque::new(); v[1] = 1; q.push_back(1); while !q.is_empty() { let p = q.pop_front().unwrap(); let bp = p.count_ones() as usize; if p - bp > 0 && v[p - bp] == -1 { v[p - bp] = v[p] + 1; q.push_back(p - bp); } if p + bp <= n && v[p + bp] == -1 { v[p + bp] = v[p] + 1; q.push_back(p + bp); } } println!("{}", v[n]); }