P29942 [洛谷] Undying「Firebird - Phoenix Winged Strike」
普及
题目描述

Background

Having acquired the ability of「Undying」, Fujiwara no Mokou has also gained the power to manipulate fire, becoming the embodiment of the phoenix.

Is the phoenix the same as the firebird?

Problem Description

Mokou can control a firebird. The firebird can be considered as a piece $A$ placed on an infinitely large chessboard at position $(x_1, y_1)$. The piece $A$ moves according to the following rules:

  • On odd-numbered moves, $A$ can only move one square to the upper right or lower left, as shown by the red arrows in the diagram;
  • On even-numbered moves, $A$ can only move one square to the lower right or upper left, as shown by the blue arrows in the diagram.

Since the chessboard is infinitely large, the values of $x$ and $y$ can be negative.

$A$ cannot stay in place during any move. Now, we need to move $A$ to position $B$ at coordinates $(x_2, y_2)$. What is the minimum number of steps required? Specifically, if no such solution exists, output $-1$.

The diagram below shows the case where $A = (2, 7)$ and $B = (5, 2)$. A minimum number of moves solution is indicated in the diagram, requiring 9 steps. Red lines represent odd-numbered moves, and blue lines represent even-numbered moves.

Input Format

The input consists of a single line with four integers $x_1, y_1, x_2, y_2$, describing the coordinates of $A$ and $B$.

Output Format

The output consists of a single line with one integer. If there is a way to move from $A$ to $B$, output the minimum number of moves; otherwise, output $-1$.

Sample Input and Output

Sample Input #1

2 7 5 2

Sample Output #1

9

Sample Input #2

2 2 3 2

Sample Output #2

-1

Sample Input #3

0 0 1000000000 1000000000

Sample Output #3

2000000000

Notes

Data Range and Constraints

For all data, it is guaranteed that $0 \le x_1, y_1, x_2, y_2 \le 10^9$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 7 5 2
样例输出
9