#P9204. 不死「火鸟 −凤翼天翔−」

不死「火鸟 −凤翼天翔−」

Background

Fujiwara no Mokou, who has gained the power of “immortality”, also obtained the ability to control flames, and became the incarnation of a firebird.

Are a firebird and a phoenix the same kind of creature?

Problem Description

Mokou can control a firebird. The firebird can be seen as a piece AA placed on an infinitely large chessboard, with AA located at (x1,y1)(x_1,y_1). AA moves by the following rules:

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

Because the board is infinite, xx and yy may be negative.

In each step, AA cannot stay in place. Now we need to move AA to position BB with coordinates (x2,y2)(x_2,y_2). What is the minimum number of steps? In particular, if no such plan exists, output 1-1.

The figure below shows the case A=(2,7)A=(2,7) and B=(5,2)B=(5,2). One optimal plan is marked in the figure and requires 99 steps. Red segments represent odd-numbered moves, and blue segments represent even-numbered moves.

Input Format

The input consists of one line with four integers x1,y1,x2,y2x_1,y_1,x_2,y_2, describing the coordinates of AA and BB.

Output Format

Output one line with one integer. If there exists a move sequence from AA to BB, output the minimum number of steps; otherwise output 1-1.

2 7 5 2
9
2 2 3 2
-1

0 0 1000000000 1000000000

2000000000

Hint

Constraints and Notes

For all testdata, it is guaranteed that 0x1,y1,x2,y21090\le x_1,y_1,x_2,y_2\le 10^9.

Translated by ChatGPT 5