Meeting in the Sierpinski Labyrinth

No attempts yetTime limit3sMemory limit512 MB

Problem

A group of Czech tourists is walking through a labyrinth of a strange self-similar shape. The ground plan of the labyrinth is a Sierpinski triangle, a fractal named after the Polish mathematician Wacław Sierpiński.

The labyrinth has a billion rows, numbered 00 to 109110^9 - 1 from top to bottom, and a billion columns, numbered 00 to 109110^9 - 1 from left to right. Every field is either free or blocked.

The field in row XX and column YY is free if the bitwise AND of XX and YY equals 00, and blocked otherwise. In other words, the field is blocked if, when XX and YY are written in binary, there is an integer kk such that the kk-th digit from the right is 11 in both numbers.

The tourists are tired after a long day of wandering and want to gather in one free field to exchange experiences. In one step, a tourist jumps to one of the adjacent free fields, up, down, left or right.

Given the current positions of the tourists, write a program that determines the minimum total number of steps needed for all of them to meet in the same field.

Input

The first line contains the integer NN, the number of tourists. (1N1000001 \le N \le 100000)

Each of the next NN lines contains two integers RiR_i and SiS_i, the row and the column of the field where the ii-th tourist stands. (0Ri,Si10910 \le R_i, S_i \le 10^9 - 1)

Every tourist stands on a free field, so the bitwise AND of RiR_i and SiS_i is 00. Several tourists can stand on the same field.

Output

Print the minimum number of steps on the first and only line.

The answer can exceed the range of a 32-bit integer, so use a 64-bit integer type (long long in C or C++, int64 in Pascal).

Hint

In the first example, one of the fields where the tourists can meet is (2, 0).

In the second example, one of the fields where the tourists can meet is (8, 4).