Time limit
2s
Memory limit
128 MB
Jimin is inside a honeycomb made of connected hexagonal rooms. Each room has one positive integer label, and from any room Jimin can move to one of the six rooms sharing a side with it.
The room labels form an outward spiral around room 1. In coordinates, room 1 is (0, 0). One move adds one of (-1, 0), (0, 1), (1, 1), (1, 0), (0, -1), or (-1, -1) to the current coordinate.
Labels from 2 onward are assigned along the following spiral path. For each layer r (r >= 1), the layer starts at (-r, -r + 1), moves r - 1 times in direction (0, 1), then moves r times in each of (1, 1), (1, 0), (0, -1), (-1, -1), and (-1, 0), assigning labels in order.
Given the current room number a and the exit room number b, output every room number on a shortest path from a to b.
The first line contains two integers a and b, the current room number and the exit room number.
1 <= a, b <= 1,000,000
Print, on one line, the room numbers visited on a shortest path from a to b, in order and separated by spaces.
If several shortest paths exist, you may print any one of them.