Coin Collecting
시간 제한1초메모리 제한512 MB
거대한 격자 위의 동전 2N개를 1 이상 N 이하의 x와 1 이상 2 이하의 y마다 한 개씩 놓이도록 옮길 때 필요한 최소 이동 횟수를 구한다.
문제
Mr. JOI has a huge desk in his collection room, and there are a number of rare coins on it. To clean up the desk, he is going to rearrange the coins.
The desk can be regarded as a 2 000 000 001 × 2 000 000 001 grid. The columns are numbered from −1 000 000 000 through 1 000 000 000 from left to right, and the rows are numbered from −1 000 000 000 through 1 000 000 000 from bottom to top. The cell with the column number x and the row number y is denoted by (x, y).
There are 2N coins. Currently, the i-th coin (1 ≤ i ≤ 2N) is placed at the cell (Xi, Yi). Mr. JOI’s goal is to place a coin on each cell (x, y) with 1 ≤ x ≤ N and 1 ≤ y ≤ 2. In order not to hurt the coins, the only operation he can perform is to choose a coin and move it to one of the neighboring cells (a cell neighbors another if and only if they share an edge). It is allowed that multiple coins are placed on a cell at some point. He wants to achieve the goal with as few operations as possible.
Write a program which, given the number of coins and the cells where the coins are currently placed, calculates the minimum number of operations needed to achieve the goal.
입력
Read the following data from the standard input.
N
X1 Y1
.
.
.
X2N Y2N
출력
Write one line to the standard output. The output should contain the minimum number of operations needed to achieve the goal.
제한
- 1 ≤ N ≤ 100 000.
- −1 000 000 000 ≤ Xi ≤ 1 000 000 000 (1 ≤ i ≤ 2N).
- −1 000 000 000 ≤ Yi ≤ 1 000 000 000 (1 ≤ i ≤ 2N).