Bananas

Place a spiral-walking monkey on an infinite grid so every banana cell lies on its path, minimizing total steps walked.

Medium7GeometryImplementationSortingPrefix sumNo attempts yetTime limit1sMemory limit128 MB

Problem

Bananas are scattered over a grid of square cells that reaches without end in every direction. A monkey is dropped from a helicopter to pick them up. You put the monkey on one cell and point it in one of the four cardinal directions. It walks one cell forward, turns right, and then keeps moving so that its path forms a spiral.

The number of cells the monkey walks in a straight line grows as 1,1,2,2,3,3,4,4,1, 1, 2, 2, 3, 3, 4, 4, \dots, and the monkey turns 90 degrees to the right after each straight stretch. The xx coordinate grows to the right and the yy coordinate grows upward. A monkey that starts facing up walks one cell up, turns right and walks one cell right, turns again and walks two cells down, turns again and walks two cells left, and so on.

The picture below shows the first part of the path when the monkey starts facing up.

The first part of the spiral path of a monkey that starts facing up

The monkey picks up every banana on the cells it walks through. You cannot put it on a cell that holds a banana, because it would slip and crush the banana. You choose the starting cell and the starting direction. Find the smallest number of steps the monkey needs to pick up all bananas.

Input

The first line holds the number of bananas NN (1N1000001 \le N \le 100000).

Each of the next NN lines holds the coordinates xx and yy of one banana, separated by a space. The coordinates are natural numbers smaller than 10810^8. A cell holds at most one banana.

Output

Print one natural number, the smallest number of steps needed to pick up all bananas.