Beehive

Given two cell indices in an infinite hexagonal beehive numbered by distance from cell 1, find the grid distance between those cells.

Medium5MathGeometryImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

An infinite beehive extends as in the figure. Two cells are adjacent exactly when they share a side. A path of length kk from cell c0c_0 to cell ckc_k is a sequence of cells c0,c1,,ckc_0, c_1, \dots, c_k such that cic_i and ci+1c_{i+1} are adjacent for every ii with 0i<k0 \le i < k. The distance between two cells is the length of a shortest path from one to the other.

Each cell of the beehive carries one positive integer index, as the figure shows. A cell farther from cell 1 gets a larger index, and among the cells at the same distance from cell 1 the index grows from left to right. Some cells at the same distance share a column. In the leftmost such column the lower cell comes first, and in the rightmost such column the upper cell comes first. The cells at one distance are therefore numbered by starting at the bottom left cell, climbing that column, crossing the top, and coming down to the bottom right cell. Every positive integer is the index of exactly one cell.

Given the indices of two cells, compute the distance between them.

Input

The input holds several test cases. Each test case is one line with two cell indices ii and jj separated by a single space (1i,j1041 \le i, j \le 10^4). The last line is 0 0, and that line is not a test case.

Output

For each test case, print the distance between the two given cells on its own line.