#P1889. 士兵站队

士兵站队

Description

On a grid-partitioned playground, nn soldiers are scattered on grid points, each represented by integer coordinates (x,y)(x, y).

A soldier can move one step up, down, left, or right along grid edges, but at any moment, at most one soldier may occupy any grid point.

By order, they must form a neat horizontal lineup, that is, the sequence (x,y),(x+1,y),,(x+n1,y)(x, y), (x+1, y), \ldots, (x+n-1, y). Determine how to choose xx and yy so that the total number of steps taken by all soldiers to line up is minimized.

Input Format

The first line contains an integer nn — the number of soldiers.

Lines 22 to n+1n+1 each contain 22 integers. On line i+1i+1, the integers xi,yix_i, y_i denote the coordinates of the ii-th soldier.

Output Format

Output a single integer on one line — the answer.

5
1 2
2 2
1 3
3 -2
3 3
8

Hint

Constraints: For 100%100\% of the testdata, it is guaranteed that 1n1041 \leq n \leq 10^4, 104x,y104-10^4 \leq x, y \leq 10^4.

Translated by ChatGPT 5