시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 128 MB32212064.516%

문제

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.

예제 입력 1

3
2 1
2 2
2 3

예제 출력 1

2