Moana is the story of a Polynesian girl of the same name who, together with the demigod Maui, defy impossible odds to save her people.
Having done so, she now leads her people to discover new islands in the Pacific to settle, in line with their historical tradition of voyaging. During the expeditions, she discovers ~L~ islands, as well as ~P~ tiles of pirate ship enclaves, within a space of ~X~ by ~Y~. Polynesian islands are generally very small, and as such occupies one tile each. Pirate enclaves occupy a single tile in the sea, but coming closer than ~S~ tiles of any of them (excluding the pirate tile) will put a ship within sight, prompting the pirates to attack. Land and pirate tiles will never coincide, and pirates do not have the military and logistical capability to assault a beachhead assault on islands within their sight.
Having settled all islands, Moana now wants to set up a network of safe sailing routes that connects all the islands to promote trade, visiting, and cultural exchanges. To be safe, the routes must not be under any threat from pirates. Since the Polynesians have perfected the art of wayfinding, being able to read the stars, the sun, and the ocean's swells to navigate, sailing routes can extend infinitely, traversing the deepest oceans and crossing the stormiest seas.
A sailing route consists of an unbroken chain of ocean tiles connected in any of the four cardinal directions. It begins from any point on one island and ends on any point of another. A patrol sailboat will then be dispatched to guard each tile of the routes to protect the vital sea lanes. Intersections between sailing routes will have additional patrol sailboats deployed, equal to the number of routes involved in the intersection, as it is a more likely area of attack. Since resources are limited, help Moana find out what is the minimum number of patrol sailboats that must be built for this purpose!
The first line contains five integers, ~L, P, S, X, Y~.
The next ~L~ lines contain two integers each, the ~x~ and ~y~ coordinates of each island.
Subsequent ~P~ lines contain two integers each, the ~x~ and ~y~ coordinates of the pirate enclaves.
The output should only consist of one integer, the minimum number of patrol sailboats that must be built to connect all islands. If it is impossible to connect all islands, output ~-1~.
For all subtasks:
~1 \le X, Y, x, y \le 100~
~0 \le P \le 2\,317~
~0 \le S \le 100~
Subtask 1 [15%]
~P = S = 0~
Islands are distributed in a checkerboard pattern, with the first grid always being occupied.
Subtask 2 [45%]
~P = S = 0~
Subtask 3 [20%]
~S = 0~
Subtask 4 [20%]
No additional constraints.
4 0 0 4 5 1 2 2 3 3 4 4 1
Explanation for Sample Output
The image above shows a ~4 \times 5~ grid with island tiles denoted in yellow and ocean tiles in blue. A possible deployment that utilizes the minimum number of boats to secure connections between all islands is shown.