One knight
Very easy
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
The hungry chess knight stays in the cell (x[1]
, y[1]
) of the chessboard of size n × n. He wants to get into the cell (x[2]
, y[2]
), where delicious chess grass grows. What is the least number of moves he has to do?
Input
Contains five numbers: n, x[1]
, y[1]
, x[2]
, y[2]
(5 ≤ n ≤ 20, 1 ≤ x[1]
, y[1]
, x[2]
, y[2]
≤ n). The upper left cell of the board has coordinates (1, 1), the bottom right - (n, n).
Output
Print the minimum number of moves to go from (x[1]
, y[1]
) to (x[2]
, y[2]
).
Examples
Input #1
Answer #1
Submissions 3K
Acceptance rate 47%