#D9819. Road Construction

    ID: 8161 Type: Default 3000ms 268MiB

Road Construction

Road Construction

The Zuia Kingdom has finally emerged through annexation of NN cities, which are identified by index from 11 to NN. You are appointed the Minister of Transport of the newly born kingdom to construct the inter-city road network.

To simplify the conceptual design planning, you opted to consider each city as a point on the map, so that the ii-th city can be represented by an coordinate (xi,yix_i, y_i).

The cost of road construction connecting uu-th and vv-th cities is equal to the distance xuxv|x_u - x_v| or yuyv|y_u - y_v|, whichever the larger. The notation A|A| represents the absolute value of AA. The object here is to explore the minimum cost required to construct the road network in such a way that people can move between different cities along one or more roads.

Make a program to calculate the minimum of total road construction cost from the number of cities and their coordinates.

Input

The input is given in the following format.

NN x1x_1 y1y_1 x2x_2 y2y_2 ... xNx_N yNy_N

The first line provides the number of cities NN (2N1052 \leq N \leq 10^5). Each of the subsequent NN lines provides the coordinate of the ii-th city xi,yix_i, y_i (0xi,yi1090 \leq x_i, y_i \leq 10^9) as integers. Note that none of these coordinates coincides if: iji \ne j, then xixjx_i \ne x_j or yiyjy_i \ne y_j.

Output

Output the minimum road construction cost.

Examples

Input

3 1 2 3 4 10 1

Output

9

Input

3 1 2 3 4 3 2

Output

4

Input

5 7 41 10 0 99 27 71 87 14 25

Output

163

inputFormat

Input

The input is given in the following format.

NN x1x_1 y1y_1 x2x_2 y2y_2 ... xNx_N yNy_N

The first line provides the number of cities NN (2N1052 \leq N \leq 10^5). Each of the subsequent NN lines provides the coordinate of the ii-th city xi,yix_i, y_i (0xi,yi1090 \leq x_i, y_i \leq 10^9) as integers. Note that none of these coordinates coincides if: iji \ne j, then xixjx_i \ne x_j or yiyjy_i \ne y_j.

outputFormat

Output

Output the minimum road construction cost.

Examples

Input

3 1 2 3 4 10 1

Output

9

Input

3 1 2 3 4 3 2

Output

4

Input

5 7 41 10 0 99 27 71 87 14 25

Output

163

样例

3
1 2
3 4
3 2
4