https://www.acmicpc.net/problem/1697
시간 제한 : 2초
메모리 제한 : 128MB
from collections import deque
MAX = 100001
n, k = map(int, input().split())
array = [0] * MAX
def bfs():
q = deque([n])
while q:
now_pos = q.popleft()
if now_pos == k:
return array[now_pos]
for next_pos in (now_pos - 1, now_pos + 1, now_pos * 2):
if 0 <= next_pos < MAX and not array[next_pos]:
array[next_pos] = array[now_pos] + 1
q.append(next_pos)
print(bfs())