시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 512 MB 0 0 0 0.000%

문제

After an exhausting battle, the invading army is finally defeated. The king sends his only surviving knight to the kingdom’s capital to tell the people of your victory. This might be a very (very!) long journey.

The knight moves as on a chessboard: in each move, he travels two squares in one of the four compass directions, and one more square sideways. During his journey, he must remain inside the kingdom to avoid starting any new wars. The kingdom is a NX × NY rectangular grid, which is possibly much (much!) larger than the 8 × 8 board on which the battle was fought. The rows and columns in this kingdom are numbered from 0. The knight starts at square KX, KY, and must travel to the capital at square CX, CY. Output the smallest number of moves in which the knight can reach the capital.

Figure 4: The possible moves for a knight.

입력

The input consists of three lines, each containing two integers:

  • On the first line: NX, NY, the size of the kingdom, with 8 ≤ NX, NY ≤ 109.
  • On the second line: KX, KY, the knight’s starting position, with 0 ≤ KX < NX and 0 ≤ KY < NY.
  • On the third line: CX, CY, the position of the capital, with 0 ≤ CX < NX and 0 ≤ CY < NY.

출력

Output a single line containing a single integer, the number of moves the knight will need to get to the capital.

예제 입력 1

8 8
0 0
7 7

예제 출력 1

6

예제 입력 2

1000 7000
253 6789
253 6789

예제 출력 2

0

예제 입력 3

8 1000000000
3 3
3 999999999

예제 출력 3

499999998

힌트