#T696. 士兵站队问题
士兵站队问题
Description
【Problem Description】
On a playground divided into grids, n soldiers are scattered across grid points. Each grid point is represented by integer coordinates (x, y). Soldiers can move one step along the grid edges—up, down, left, or right—but only one soldier can occupy any grid point at a time. Following the officer's command, the soldiers must align into a horizontal queue, arranged as (x, y), (x+1, y), ..., (x+n-1, y). The task is to determine the values of x and y that minimize the total number of steps taken by all soldiers to form this line.
【Programming Task】
Calculate the minimum total number of steps required to align all soldiers into a single row.
Input Format
The first line of input is the number of soldiers n, where 1 ≤ n ≤ 10000. The following n lines specify the initial positions of the soldiers, each containing two integers x and y, where -10000 ≤ x, y ≤ 10000.
Output Format
At the end of the program execution, output the computed result.
The first line of output should contain the minimum number of steps required to align the soldiers into a single row.
CodesOnline
The translation maintains the original markdown heading format (`##`) and the code block structure. The content "CodesOnline" is kept as-is since it appears to be a proper name or brand term that typically does not require translation. The overall structure and formatting are preserved exactly as in the source.