# Problem 3 - ビットすごろく from collections import deque def calc_bin(num): return bin(num).count("1") # input N = int(input()) # initialization masu = [-1]*(N+1) masu[1] = 1 queue = deque([1]) # bfs search while len(queue)>0: cur_pos = queue.popleft() cur_nxt = calc_bin(cur_pos) # left move if cur_pos-cur_nxt>0 and masu[cur_pos-cur_nxt]==-1: masu[cur_pos-cur_nxt] = masu[cur_pos] + 1 queue.append(cur_pos-cur_nxt) # right move if cur_pos+cur_nxt