|시간 제한||메모리 제한||제출||정답||맞힌 사람||정답 비율|
|1 초 (추가 시간 없음)||128 MB||3||3||3||100.000%|
You are given an $N\times N$ matrix and in exactly $N$ of its cells there is a single coin. You are going to play a game on this matrix where in one turn you can take a coin and move it to any adjacent cell. Two cells are adjacent if they share a side. However, during these moves, no two coins may occupy the same cell at the same time. Your goal is to make every row and column contain exactly one coin in as few moves as possible. Determine the minimum number of moves required.
In the first line of input is the number $N$ ($N\leq 200000$): the number of rows, columns and coins.
In the $(i+1)$-th line are two integers $r_i$ and $c_i$, denoting the initial row and column of the $i$-th coin. It is guaranteed that all pairs $(r_i,c_i)$ are different.
Print a single integer: the minimum number of moves required to win at the game.
3 2 1 2 2 2 3