Олимпиадный тренинг

Задача 23399. Metro


Задача

Темы:

A light metro has been built in a metropolis that is experiencing great transport problems. It consists of 6 radial lines that radiate from the city center and k ring lines in the shape of regular hexagons.  Metro stations are located at the intersection of circular and radial lines. At any station, it is allowed to transfer from circle lines to radial lines and vice versa. Radial lines are sequentially numbered clockwise from 1 to 6. Circle lines are numbered from the city center (the center is considered a zero-numbered circle line, consisting of one station).  ;

The distance between two neighboring stations on the same radial line is 1 km. The distance between neighboring stations on the circle line with the number i is i km. Any station is indicated by a pair of numbers - the number of the radial line r (\(1<=r<=6\)) and circle line number k (\(0< ;=k<=32000\)), at the intersection of which it is located. 

Write a program to determine the length of the shortest path between stations.

 

Input data: Four numbers are entered: r1, k1, < code>r2, k2 - coordinates of the start and end station. 

Output: It is necessary to output the distance (in km) that passenger will need to travel to get from the starting station to the final one.< /p>


Examples
# Input Output
1 1 5 1 4 1
2 1 5 2 4 5
3 2 0 6 3 3