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 0 to 109−1 from top to bottom, and a billion columns, numbered 0 to 109−1 from left to right. Every field is either free or blocked.
The field in row X and column Y is free if the bitwise AND of X and Y equals 0, and blocked otherwise. In other words, the field is blocked if, when X and Y are written in binary, there is an integer k such that the k-th digit from the right is 1 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.
The first line contains the integer N, the number of tourists. (1≤N≤100000)
Each of the next N lines contains two integers Ri and Si, the row and the column of the field where the i-th tourist stands. (0≤Ri,Si≤109−1)
Every tourist stands on a free field, so the bitwise AND of Ri and Si is 0. Several tourists can stand on the same field.
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).
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).