QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#413. Worst Reporter 2

Statistics

The year is 21XX, and competitive programming is widely recognized as a mind sport, frequently featured in media such as television and newspapers. You are a reporter for the JOI News Agency, in charge of articles about competitive programming. Yesterday, an international competitive programming contest with $N$ participants was held. To write an article about this contest, you have been given the following information:

  • As in the International Olympiad in Informatics and similar events, participants in this contest came from several countries. Countries are numbered from 1 to $N$. Multiple participants may come from the same country. Also, there may be countries from which no participants came.
  • The duration of this contest is 5 hours.
  • The scores obtained by participants during the contest never decrease.
  • Two hours after the start of the contest, there were no participants with the same score. In the leaderboard at that time, the participant in $i$-th place ($1 \le i \le N$) was from country $A_i$ and had a score of $B_i$.
  • At the end of the contest, there were no participants with the same score. In the leaderboard at the end of the contest, the participant in $i$-th place ($1 \le i \le N$) was from country $C_i$ and had a score of $D_i$.

However, at the stage of writing the article, it was discovered that there was a flaw in the display of the countries of origin in the leaderboards. It is possible that the information about the participants' countries of origin was displayed incorrectly. It is known that the displayed scores of the participants are correct.

Therefore, you decided to infer a consistent leaderboard (where the country of origin of the same participant does not change during the contest, and the score obtained by a participant does not decrease during the contest) by making as few corrections as possible to the given information. That is, you want to satisfy the following condition by changing as few as possible of the $2N$ values $A_1, \dots, A_N, C_1, \dots, C_N$:

  • There exists a permutation $x_1, x_2, \dots, x_N$ of $1, 2, \dots, N$ such that for each $i = 1, 2, \dots, N$, $A_i = C_{x_i}$ and $B_i \le D_{x_i}$ hold.

How many corrections, at minimum, do you need to make to the given information?

Input

Read the following data from standard input:

  • The first line contains an integer $N$, representing the number of participants in the contest.
  • The $i$-th line of the following $N$ lines ($1 \le i \le N$) contains integers $A_i$ and $B_i$ separated by a space. This indicates that in the leaderboard 2 hours after the start of the contest, the participant in $i$-th place was from country $A_i$ and had a score of $B_i$.
  • The $i$-th line of the following $N$ lines ($1 \le i \le N$) contains integers $C_i$ and $D_i$ separated by a space. This indicates that in the leaderboard at the end of the contest, the participant in $i$-th place was from country $C_i$ and had a score of $D_i$.

Output

Output the minimum number of corrections to the country of origin information required to make the leaderboard consistent in a single line.

Constraints

All input data satisfies the following conditions:

  • $2 \le N \le 200\,000$.
  • $1 \le A_i \le N$ ($1 \le i \le N$).
  • $0 \le B_i \le 1\,000\,000\,000$ ($1 \le i \le N$).
  • $B_i > B_{i+1}$ ($1 \le i \le N - 1$).
  • $1 \le C_i \le N$ ($1 \le i \le N$).
  • $0 \le D_i \le 1\,000\,000\,000$ ($1 \le i \le N$).
  • $D_i > D_{i+1}$ ($1 \le i \le N - 1$).
  • It is possible to make the leaderboard consistent by changing some values of $A_1, \dots, A_N, C_1, \dots, C_N$.

Subtasks

  1. (15 points) $N \le 16$ is satisfied.
  2. (15 points) $N \le 50$ is satisfied.
  3. (30 points) $N \le 5000$ is satisfied.
  4. (40 points) No additional constraints.

Examples

Input 1

3
3 500
2 200
1 100
1 1000
3 700
3 400

Output 1

1

Note 1

If you change the value of $C_3$ to 2, the leaderboard becomes consistent as follows:

  • The participant from country 3, who was in 1st place with 500 points 2 hours after the start, finished in 2nd place with 700 points.
  • The participant from country 2, who was in 2nd place with 200 points 2 hours after the start, finished in 3rd place with 400 points.
  • The participant from country 1, who was in 3rd place with 100 points 2 hours after the start, finished in 1st place with 1000 points.

Here, if you change the value of $C_2$ to 2, the participant from country 3 has 500 points 2 hours after the start, but has 400 points at the end of the contest, resulting in an inconsistent leaderboard. Since it is impossible to obtain a consistent leaderboard with fewer than 1 correction, output 1.

Input 2

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

Output 2

0

Note 2

In this case, the leaderboard is consistent without modifying the country of origin information. Note that there may be participants who did not increase their score from the score 2 hours after the start of the contest. Also, note that there may be multiple participants from the same country in the leaderboard.

Input 3

6
1 70
4 50
1 30
2 20
1 10
3 0
6 100
2 90
1 80
2 60
4 40
1 10

Output 3

3

Note 3

In this example, if you change the value of $A_1$ to 2, the value of $A_6$ to 4, and the value of $C_1$ to 4, the leaderboard becomes consistent.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.