#T493. 士兵站队问题

士兵站队问题

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 contains the number of soldiers, n (1 ≤ n ≤ 10000). The next n lines each contain two integers, x and y, representing the initial position of a soldier (-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.

```input1 5 1 2 2 2 1 3 3 -2 3 3 ``` ```output1 8 ``` ## Source

CodesOnline