#P12148. 【MX-X11-T2】「蓬莱人形 Round 1」所以我放弃了音乐

【MX-X11-T2】「蓬莱人形 Round 1」所以我放弃了音乐

Description

On an infinite chessboard, there are nn distinct pieces at positions (xi,yi)(x_i, y_i). You must delete all pieces by performing the following operation multiple times:

  1. Choose a grid (x,y)(x, y).
  2. If there is a piece at (x,y)(x, y), delete it. Otherwise, end the current operation.
  3. Sequentially check the grids at (x+1,y+1)(x+1, y+1), (x+1,y)(x+1, y), and (x+1,y1)(x+1, y-1). Upon finding the first grid with a piece, stop checking, update (x,y)(x, y) to this grid's coordinates, and return to Step 2. If none of these grids contain a piece, end the current operation.

Determine the minimum number of operations required to delete all pieces.

Input Format

The first line contains a positive integer nn indicating the number of pieces.

The next nn lines each contain two positive integers xix_i, yiy_i representing the coordinates of a piece. All positions are guaranteed to be distinct.

Output Format

Output a single positive integer representing the minimum number of operations needed.

4
1 3
2 2
3 1
3 3
2
9
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
3

Hint

Explanation #1

For the first sample, the chessboard is shown below:

  • First operation: Choose (1,3)(1, 3). This deletes the pieces at (1,3)(1, 3), (2,2)(2, 2), and (3,3)(3, 3).
  • Second operation: Choose (3,1)(3, 1). This deletes the piece at (3,1)(3, 1).

It can be proven that no better strategy exists.

Constraints

This problem uses subtask scoring.

For all test data: 1n1061 \le n \le 10^6, 1xi,yi1061 \le x_i, y_i \le 10^6.

Subtask nn \le xi,yix_i, y_i \le Special Property Points
1 10610^6 10610^6 A 10
2 88 None 20
3 300300
4 5×1045 \times 10^4
5 10610^6 30
  • Special Property A: All xix_i are equal.

Translated by DeepSeek R1