#P7885. Moving the Shield Machine

    ID: 21070 Type: Default 1000ms 256MiB

Moving the Shield Machine

Moving the Shield Machine

Bookworm needs to move his shield machine on a 2D plane. The machine is currently located at \((a,b)\), and the goal is to move it to \((c,d)\).

In each move, the shield machine can move one unit in one of the four cardinal directions: north, south, east, or west. However, it cannot move in the same direction in two consecutive moves.

Given the starting point \((a,b)\) and the destination \((c,d)\), compute the minimum number of moves required. It is guaranteed that the destination is always reachable.

Note: If we define \(dx=|c-a|\) and \(dy=|d-b|\), the answer is determined by:

\[ \text{ans} = \begin{cases} dx+dy, &\text{if } dx=dy,\\ 2\cdot\max(dx,dy)-1, &\text{if } dx\neq dy. \end{cases} \]

inputFormat

The input consists of a single line containing four integers \(a\), \(b\), \(c\), and \(d\), representing the starting coordinates and the destination coordinates respectively.

outputFormat

Output a single integer: the minimum number of moves required to reach the destination.

sample

0 0 0 0
0