#P2060. Minimum Knight Moves

    ID: 15342 Type: Default 1000ms 256MiB

Minimum Knight Moves

Minimum Knight Moves

Given two points on an infinite chessboard with coordinates \(p=(x_p, y_p)\) and \(s=(x_s, y_s)\), a knight can move from an arbitrary point \((x,y)\) to any of the following eight positions:

\[ (x+1, y+2),\quad (x+2, y+1),\quad (x+1, y-2),\quad (x+2, y-1),\quad (x-1, y+2),\quad (x-2, y+1),\quad (x-1, y-2),\quad (x-2, y-1) \]

Your task is to compute the minimum number of knight moves (also known as "马步移动") required to get from \(p\) to \(s\). For example, starting from the point labelled \(0\), one knight move can reach the point labelled \(1\) and two moves can reach the point labelled \(2\).

inputFormat

The input consists of a single line containing four integers \(x_p\), \(y_p\), \(x_s\), \(y_s\) representing the coordinates of the starting point \(p\) and the target point \(s\) respectively. The coordinates may be negative.

outputFormat

Output a single integer: the minimum number of knight moves required to move from \(p\) to \(s\).

sample

0 0 1 2
1