Brave Sir Robin has been thrown in the dungeon by the evil king. The dungeon consists of an infinite number of cube-shaped rooms with big stone walls. Rooms are connected by passages so that the entire dungeon, when viewed from above, looks like a spiral. The rooms are numbered as follows:
After a big earthquake some of the walls collapsed, and new passages were formed between adjacent rooms.
Sir Robin is initially in room
Write a program that, given the location of the exit
Input Specification
The first line of input contains an integer
The second line of input contains an integer
Each of the following
Output Specification
Output should consist of a single integer, the smallest number of passages that Sir Robin must go through before he can exit the dungeon.
Scoring
In a number of test cases, worth a total of
Sample Input 1
31
9
15
25
30
6
9
19
24
27
4
Sample Output 1
6
Explanation for Sample Output 1
This is the layout of the dungeon after the earthquake:
Mirko can use the route
Sample Input 2
10000
5
52
4
9
25
27
Sample Output 2
9953
Comments