#abc359c. C - Tile Distance 2

C - Tile Distance 2

Score : 350350 points

问题陈述

坐标平面上覆盖着 2×12\times1 的瓷砖。这些瓷砖按照以下规则铺设:

  • 对于整数对 (i,j)(i,j),正方形 $A _ {i,j}=\lbrace(x,y)\mid i\leq x\leq i+1 \wedge j\leq y\leq j+1\rbrace$ 包含在一个瓷砖内。
  • i+ji+j 为偶数时,Ai,jA _ {i,j}Ai+1,jA _ {i + 1,j} 包含在同一个瓷砖内。

瓷砖包括它们的边界,并且没有两个不同的瓷砖共享一个正面积。

在原点附近,瓷砖的铺设方式如下:

高桥从坐标平面上的点 (Sx+0.5,Sy+0.5)(S _ x+0.5,S _ y+0.5) 开始。

他可以重复以下移动任意次数:

  • 选择一个方向(上、下、左或右)和一个正整数 nn。在那个方向上移动 nn 个单位。

每次他进入一个瓷砖,他需要支付 1 元的通行费。

找出他到达点 (Tx+0.5,Ty+0.5)(T _ x+0.5,T _ y+0.5) 必须支付的最小通行费。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

The coordinate plane is covered with 2×12\times1 tiles. The tiles are laid out according to the following rules:

  • For an integer pair (i,j)(i,j), the square $A _ {i,j}=\lbrace(x,y)\mid i\leq x\leq i+1\wedge j\leq y\leq j+1\rbrace$ is contained in one tile.
  • When i+ji+j is even, Ai,jA _ {i,j} and Ai+1,jA _ {i + 1,j} are contained in the same tile.

Tiles include their boundaries, and no two different tiles share a positive area.

Near the origin, the tiles are laid out as follows:

Takahashi starts at the point (Sx+0.5,Sy+0.5)(S _ x+0.5,S _ y+0.5) on the coordinate plane.

He can repeat the following move as many times as he likes:

  • Choose a direction (up, down, left, or right) and a positive integer nn. Move nn units in that direction.

Each time he enters a tile, he pays a toll of 11.

Find the minimum toll he must pay to reach the point (Tx+0.5,Ty+0.5)(T _ x+0.5,T _ y+0.5).

Constraints

  • 0Sx2×10160\leq S _ x\leq2\times10 ^ {16}
  • 0Sy2×10160\leq S _ y\leq2\times10 ^ {16}
  • 0Tx2×10160\leq T _ x\leq2\times10 ^ {16}
  • 0Ty2×10160\leq T _ y\leq2\times10 ^ {16}
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

SxS _ x SyS _ y

TxT _ x TyT _ y

Output

Print the minimum toll Takahashi must pay.

Sample Input 1

5 0
2 5

Sample Output 1

5

For example, Takahashi can pay a toll of 55 by moving as follows:

  • Move left by 11. Pay a toll of 00.
  • Move up by 11. Pay a toll of 11.
  • Move left by 11. Pay a toll of 00.
  • Move up by 33. Pay a toll of 33.
  • Move left by 11. Pay a toll of 00.
  • Move up by 11. Pay a toll of 11.

It is impossible to reduce the toll to 44 or less, so print 5.

Sample Input 2

3 1
4 1

Sample Output 2

0

There are cases where no toll needs to be paid.

Sample Input 3

2552608206527595 5411232866732612
771856005518028 7206210729152763

Sample Output 3

1794977862420151

Note that the value to be output may exceed the range of a 3232-bit integer.