This page is still under construction.

Parts of this page are still being built. What you see may change.

Distance in Crosses

Time limit2sMemory limit512 MB

Summary
Squares are tiled by crosses whose centers form a lattice; moving to a different cross costs one coin, and we must find the minimum coins between two given squares.
Level

Hard8 of 10

Topics
Math, Geometry, Shortest path, Implementation
Solved
No attempts yet

Problem

The plane is divided into squares with side 11. Choose one square and draw coordinate axes from its center parallel to its sides.

Next, draw a cross made up of the central square and its four neighbors, the squares sharing a side with it. Then pick the square centered at (2,1)(2, 1) and draw another cross made up of this square and its four neighbors. Tile the whole plane with such crosses: their centers lie at the points with coordinates (2i+j,i−2j)(2 i + j, i - 2 j) for all integer ii and jj. The tiling appears in the figure next to the examples.

Emilia stands at the center of some square on the plane. In one step she can move from a square to one of its neighbors. If a step takes her to a different cross of the tiling, she must pay one coin for that step. Steps that keep her in the same cross are free.

Let the distance in crosses between two squares AA and BB be the minimum number of coins Emilia must pay to get from AA to BB. You are given the coordinates of two points on the plane: the center of the starting square and the center of the destination square. Find the distance in crosses between them.

Input

The first line contains two integers x_1x\_1 and y_1y\_1, the coordinates of the starting square. The second line contains two integers x_2x\_2 and y_2y\_2, the coordinates of the destination square. The absolute value of every given coordinate does not exceed 10910^{9}.

Output

Print one integer: the distance in crosses from the starting square to the destination square.

Examples3

  1. Example 1

    Input
    1 1
    2 2
    
    Expected output
    0
    
  2. Example 2

    Input
    3 4
    -2 0
    
    Expected output
    4
    
  3. Example 3

    Input
    4 3
    0 -2
    
    Expected output
    3