Time

12:50:49
23 May 2012
Version for print

Anfisa’s Holiday

prb53   The rectangular hangars have sizes M and N (at first for horizontal lines, and then for vertical lines). It was cluttering up by three-cornered tiles. These tiles were numbered as shown on the picture.

   Anfisa can move from one tiles to other only through a general side for a one step. What least quantity of steps has to do Anfisa to the piece of cheese which placed on tile with number B if she is being on the tile with number A?


Specifications

   Input

   In the first line is sizes of the hangars M and N. In the second line is number of tile A in which Anfisa is being and number of the tile B with the piece of cheese. 1 ≤ M, N ≤ 30000.

   Output

   A one number is the quantity of steps of K, which Anfisa has to do.


Problem information

Time Limit: 1 seconds
Memory Limit: 64 MB
Balls for the passed test: 10
Complexity: 39% 31/51

Example

Example input

5 4
25 38

Example output

5


← The Cheese for Anfisa Problems Murzyk →