1268 - LL’s bees

Time Limit : 1 Second

Memory Limit : 128 MB

Submission: 25

Solved: 14

Description
LL is conducting experiments with bees. Unfortunately, the bees do not breed well in captivity. LL thinks the reason is that the placement of the different maggots (for workers, queens, etc.) within the honeycomb depends on environmental conditions, which are different in his laboratory and the rain forest.
As a first step to validate his conjecture, LL wants to quantify the difference in maggot placement. For this he measures the distance between the cells of the comb into which the maggots are placed. To this end, LL has labeled the cells by marking an arbitrary cell as number 1, and then labeling the remaining cells in a clockwise fashion, as shown in the following figure.

For example, two maggots in cells 19 and 30 are 5 cells apart. One of the shortest paths connecting the two cells is via the cells 19 - 7 - 6 - 5 - 15 - 30, so you must move five times to adjacent cells to get from 19 to 30.
LL needs your help to write a program that computes the distance, defined as the number of cells in a shortest path, between any pair of cells.
Input
The input consists of several lines, each containing two integers a and b (1 <= a,b <= 10000), denoting numbers of cells. The integers are always positive, except in the last line where a=b=0 holds. This last line terminates the input and should not be processed.
Output
For each pair of numbers (a,b) in the input file, output the distance between the cells labeled a and b. The distance is the minimum number of moves to get from a to b.
sample input
19 30
0 0
sample output
The distance between cells 19 and 30 is 5.
hint
source
World Finals 1999 (Modified)
© 2015 HUST ACMICPC TEAM. All Right Reserved.