Under construction

Still being built. Things may change

Anticlockwise Motion

Time limit1sMemory limit512 MB

Summary
Given two cells of an anticlockwise spiral numbered from the center, find the Manhattan distance between them.
Level

Medium4 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

You have an idea for a board game. The board is a grid of 32001×3200132001 \times 32001 numbered squares. The centre square holds the number 1, and every other number sits on an anticlockwise spiral that grows outwards. The spiral first moves downwards, then to the right, then upwards, then to the left, then downwards again, and so on. The figure below shows the middle 25 squares, and the figure in the hint shows the middle 441 squares.

Figure A.1: the middle 25 squares.

A player moves one square at a time, up, down, left, or right. Given the numbers of two squares, find the smallest number of moves needed to get from one to the other.

Input

The first and only line contains the number aa of the starting square and the number bb of the ending square, separated by a space. (1≤a≤1091 \le a \le 10^9, 1≤b≤1091 \le b \le 10^9)

Output

Print the shortest distance between square aa and square bb, that is the minimum number of moves.

Hint

Figure A.2: the middle 441 squares.

Examples2

  1. Example 1

    Input
    12 2
    
    Expected output
    2
    
  2. Example 2

    Input
    16 24
    
    Expected output
    6