One day while grazing in particularly deep hay, Betsy discovered
four magic cow shoes! She donned them and found that they enabled
her to jump around the pasture which, of course, is subdivided into
a convenient grid with R rows (1 <= R <= 50) and C columns (1 <= C
<= 50). The shoes enabled her to jump two different ways: both like
a chess game knight and in another pattern she'd never seen before.
She noticed that she jumped like a knight on her first, third,
fifth, and odd-numbered moves while she jumped in the new way on
the second, fourth, sixth, and even-numbered moves. Here is a map
of the possible move patterns she discovered:
Knight (Odd moves) Other (Even moves) . . K . K . . . . . O . . . . K . . . K . . . . . . . . . . . B . . . . O . B . O . . K . . . K . . . . . . . . . . K . K . . . . . O . . .When Betsy starts at the 'B', depending on whether her next move is an odd or even one, she can jump to any one of the 'K's or 'O's.
The input file contains multiple test cases, for each test case:
* Line 1: Two space-separated integers: respectively R and C.
* Line 2: Two space-separated integers: respectively the row and column of Betsy's starting location.
* Line 3: Two space-separated integers: respectively the row and column of the candy bar.
Process till EOF.
For each test case, output:
* Line 1: A single integer that is the minimum number of jumps using the magic shoes until Betsy lands on the candy bar.
4 5 4 1 4 3
USACO 2006 March