#t265. 士兵站队
士兵站队
Soldiers in a Line
Problem Description
On a playground divided into a grid, soldiers stand scattered on grid points, represented by integer coordinates .
A soldier can move one step up, down, left, or right along the grid edges, but at any moment at most one soldier may occupy a given grid point.
By the officer's command, they must form a neat horizontal line, that is, stand at . Find the values of and that minimize the total number of steps the soldiers must move to line up.
Input Format
The first line of input is an integer, the number of soldiers .
Lines through each contain two integers; the -th line's are the coordinates of the -th soldier.
Output Format
Output one integer on a line: the answer (the minimum total number of moves).
Sample Input
5
1 2
2 2
1 3
3 -2
3 3
Sample Output
8
Hint
For of the data: , .