QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 10

#10642. Scissors [B]

Statistics

Bajtazar has bought a pair of scissors. Now he wants to test them, so he grabbed a polygon lying nearby and decided to cut it into rectangles. He wants to do this using the minimum number of cuts. Help Bajtazar and calculate how many cuts he will need to make.

The polygon consists only of vertical and horizontal segments. Before taking the scissors, Bajtazar draws a number of vertical and horizontal segments on the polygon. The start and end of each segment lie on the boundary of the polygon, and the interior of the segment is contained within the interior of the polygon. Then, Bajtazar cuts the polygon along all the drawn segments. The number of cuts made is the number of drawn segments. After all cuts are made, all resulting pieces must be rectangles.

Note that after making a certain number of cuts, some of the drawn segments might have been intersected; however, making cuts along all pieces resulting from one drawn segment is considered a single cut. In particular, this means that a $2 \times 2$ square can be divided into four $1 \times 1$ squares using only two cuts (although, of course, from the point of view of Bajtazar's goal, such cutting makes no sense).

Input

The first line of input contains a single integer $n$ ($4 \le n \le 100\,000$) representing the number of vertices of the polygon. The next $n$ lines describe the consecutive vertices of the polygon. The description of the $i$-th vertex consists of a pair of integers $x_{i}, y_{i}$ ($-10^{9} \le x_{i}, y_{i} \le 10^{9}$), which describe the coordinates of that vertex.

All sides of the polygon are vertical or horizontal. Two sides of the polygon intersect only if they are consecutive sides on the boundary of the polygon. In such a case, their only intersection point is the common vertex. In particular, the coordinates of all vertices are pairwise distinct.

Output

Your program should output the minimum number of cuts needed to divide the polygon into rectangles.

Examples

Input 1

8
0 0
6 0
6 7
4 7
4 3
2 3
2 5
0 5

Output 1

2

Note 1

The drawing shows several possible ways to divide the polygon described in the example into rectangles using two cuts.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.