Under construction

Still being built. Things may change

Anti-Distance

Time limit2sMemory limit256 MB

Summary
Given two free cells on a grid where every fifth cell at (2i+j, i-2j) is blocked, find the fewest side-adjacent steps between them.
Level

Medium7 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

Consider a plane divided into unit squares with side 11. Choose a square and draw coordinate axes from its center, parallel to its sides.

Each fifth square contains an obstacle. The obstacles are placed in every square whose center is at (2i+j,i−2j)(2 i + j, i - 2 j) for all integers ii and jj. All other squares are free.

Amelia stands in a free square AA and wants to move to a free square BB. In one step, she can move from her square to a neighbor that shares a side with it, but only if that neighbor is free. What is the minimum number of steps Amelia must make to reach BB?

Input

The first line contains two integers x1x_1 and y1y_1, the coordinates of the starting square AA. The second line contains two integers x2x_2 and y2y_2, the coordinates of the destination square BB. All coordinates are between 11 and 10910^{9}. Both squares are guaranteed to be free.

Output

Print one integer: the minimum number of steps from square AA to square BB.

Examples2

  1. Example 1

    Input
    1 1
    5 2
    
    Expected output
    7
    
  2. Example 2

    Input
    1 1
    2 5
    
    Expected output
    5