#D9819. Road Construction
Road Construction
Road Construction
The Zuia Kingdom has finally emerged through annexation of cities, which are identified by index from to . 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 -th city can be represented by an coordinate ().
The cost of road construction connecting -th and -th cities is equal to the distance or , whichever the larger. The notation represents the absolute value of . 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.
...
The first line provides the number of cities (). Each of the subsequent lines provides the coordinate of the -th city () as integers. Note that none of these coordinates coincides if: , then or .
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.
...
The first line provides the number of cities (). Each of the subsequent lines provides the coordinate of the -th city () as integers. Note that none of these coordinates coincides if: , then or .
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