#P5816. [CQOI2010] 内部白点

[CQOI2010] 内部白点

Description

On an infinite square grid, there are nn black vertices, and all other vertices are white (grid vertices are points with integer coordinates, also called lattice points). Every second, all internal white points turn black simultaneously, until there are no internal white points left. Your task is to count the number of black points in the grid at the end.

Definition of an internal white point: a white lattice point P(x,y)P(x,y) is an internal white point if and only if there is at least one black point to the left and to the right of PP on the same horizontal line (i.e., there exist x1<x<x2x_1 < x < x_2 such that (x1,y)(x_1,y) and (x2,y)(x_2,y) are both black), and at least one black point above and below PP on the same vertical line (i.e., there exist y1<y<y2y_1 < y < y_2 such that (x,y1)(x,y_1) and (x,y2)(x,y_2) are both black).

Input Format

The first line contains an integer nn, the number of initial black points.

The next nn lines each contain two integers xx, yy, the coordinates of a black point. No two black points have the same coordinates, and the absolute value of each coordinate does not exceed 10910^9.

Output Format

Output one line containing the final number of black points.

If the recoloring process never terminates, output -1.

4
0 2
2 0
-2 0
0 -2

5

Hint

Constraints

For 36%36\% of the testdata, n500n \le 500.

For 64%64\% of the testdata, n3×104n \le 3 \times 10^4.

For 100%100\% of the testdata, n105n \le 10^5.

Translated by ChatGPT 5