TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

Two friends, Petey and Patty are locked up in a maze. The maze has an infinite number of circles of the same size, arranged like the figure on the right. Petey and Patty are initially standing on two (not necessarily distinct) circles.


Petey wants to reach her friend Patty. In each step, she can go from the circle she is standing on, to one of the adjacent circles. Two circles are adjacent to each other, if they share a point.


Given the numbers (as shown in the figure) of the two circles Petey and Patty are standing on initially, you’re to find the minimum number of steps Petey needs to reach her friend.


Input Format

The input contains several test cases. Each test case is a line containing two space-separated integers specifying the
initial circles Petey and Patty are standing on. None of these numbers is more than 1018. The last line contains "0 0" which shows the end of the input, and should not be processed.

Output Format

Write the result of the i-th test case, on the i-th line of output. You should just write one integer indicating the minimum number of steps Petey needs to reach her friend.

Sample Input 1

1 3
2 6
23 9
0 0

Sample Output 1

1
2
4

Hints

Problem Source

Migrated from old NTUJ.

2009Tehran

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 65536 8192