#C348. Minimum Knight Moves on a Chessboard

    ID: 46911 Type: Default 1000ms 256MiB

Minimum Knight Moves on a Chessboard

Minimum Knight Moves on a Chessboard

Given the starting and ending positions of a knight on a standard 8×88\times8 chessboard, compute the minimum number of moves required for the knight to travel from the starting position to the destination. The knight moves in an L-shape: two steps in one direction (horizontal or vertical) and then one step perpendicular to that direction. It is guaranteed that both positions are valid on the chessboard.

inputFormat

The input consists of two lines:

  • The first line contains two integers x1x_1 and y1y_1, representing the starting coordinates of the knight.
  • The second line contains two integers x2x_2 and y2y_2, representing the destination coordinates. All coordinates satisfy 1x,y81 \leq x, y \leq 8.

outputFormat

Output a single integer representing the minimum number of moves required for the knight to reach the destination from the start.## sample

3 4
3 4
0