Passport
Time limit2sMemory limit1024 MB
Given each country's passport range [L_i, R_i], for each start country X_j, find the fewest passports needed to visit all N countries, or -1 if impossible.
Problem
A passport is a certificate that travelers use to enter foreign countries around the world.
There are countries on a planet, numbered from to . Each country issues its own passport. A traveler holding the passport issued by country can enter countries . It is guaranteed that a traveler can enter the country that issued the passport. That is, .
Your friend likes to travel. At first he has no passport. He wants to visit all countries by repeating the following two actions.
- Get a passport issued by the country where he is currently staying.
- Move to a country he can enter with a passport he currently holds.
You do not know where he lives, so there are candidate countries . For each candidate, determine whether he can visit all countries. If he can, find the minimum number of passports he needs to get.
Input
The first line contains . Each of the next lines contains and . The next line contains . Each of the last lines contains .
Output
Print lines. The -th line is the minimum number of passports needed when he lives in , or if he cannot visit all countries.
Constraints
()
()
()
All given values are integers.