spoj#PLONK. Where to Drink the Plonk?
Where to Drink the Plonk?
Consider a city bounded by a square, whose n horizontal and n vertical streets divide it into (n+1)2 square blocks. However, in tribute to the ancient traditions of the first dwellers (who tended to overindulge in alcohol), all the inhabitants live at crossroads. A group of friends would like to meet for an evening of merriment at the place of residence of one of them. With a good deal of foresight, anticipating the difficulties they might have getting back to their respective homes, they would like to meet in the house of the friend which minimises the total walking distance for all of them. Assume that everybody walks along the streets, turning only at crossroads, and the distance between any pair of adjacent crossroads is 1.
Input
The input begins with the integer t, the number of test cases. Then t test cases follow.
For each test case the first line of input contains the integer n - the number of friends who want to meet (1<=n<=10000). The next n lines contain two integers each, the i-th being xi yi, standing for the x and y coordinates of the crossroads at which the i-th friend lives (0<=xi,yi<=100000).
Output
For each test case output the total distance covered by all friends when walking to the meeting place.
Example
Sample input: 1 7 1 3 3 2 3 5 6 9 10 1 12 4 5 7Warning: large Input/Output data, be careful with certain languages</p>Sample output: 39