#P2060. [HNOI2006] 马步距离

[HNOI2006] 马步距离

Problem Description

In international chess and Chinese chess (Xiangqi), the horse/knight moves in the same way, following an L shape. We call this movement a knight move.

As shown in the figure below, starting from the point labeled 00, you can reach a point labeled 11 in one knight move, and a point labeled 22 in two knight moves.

Given any two points pp and ss on the plane, with coordinates (xp,yp)(x_p,y_p) and (xs,ys)(x_s,y_s) respectively, from (x,y)(x,y) you can reach (x+1,y+2)(x+1,y+2), (x+2,y+1)(x+2,y+1), (x+1,y2)(x+1,y-2), (x+2,y1)(x+2,y-1), (x1,y+2)(x-1,y+2), (x2,y+1)(x-2,y+1), (x1,y2)(x-1,y-2), (x2,y1)(x-2,y-1) in one knight move.

Assume the board is sufficiently large, and coordinates can be negative. Please compute the minimum number of knight moves needed to get from point pp to point ss.

Input Format

A single line containing four integers separated by spaces, representing xp,yp,xs,ysx_p,y_p,x_s,y_s.

Output Format

Output a single integer, the minimum number of knight moves from point pp to point ss.

1 2 7 9
5

Hint

Constraints

For 100%100\% of the testdata, it is guaranteed that 1xp,yp,xs,ys1071 \leq x_p,y_p,x_s,y_s \leq 10^7.

Translated by ChatGPT 5