func main() var N: int :: cui@input().toInt(&) var dp: []int :: #[N + 1]int do dp.fill(10000000) do dp[1] :: 1 var st: queue :: #queue do st.add(1) while(^st <> 0) var n: int :: st.get() var b: int :: bitNum(n) var nextStep: int :: dp[n] + 1 if(n + b <= N & dp[n + b] > nextStep) do dp[n + b] :: nextStep do st.add(n + b) end if if(n - b > 0 & dp[n - b] > nextStep) do dp[n - b] :: nextStep do st.add(n - b) end if end while var ans: int :: dp[N] = 10000000 ?(-1, dp[N]) do cui@print("\{ans}\n") func bitNum(n: int): int var res: int while(n <> 0) do res :+ n % 2 do n :/ 2 end while ret res end func end func