Count boats reachable within one relay hop from boat 1, where visibility means the connecting segment never enters the convex island interior; every coordinate is a lattice point.
Hard8GeometrySortingBinary searchTwo pointersNo attempts yetTime limit2sMemory limit512 MBPeople live on an island. Most of them fish for a living, so N households on the island own a fishing boat. In the afternoon, when everyone heads out to work, all N boats leave the island and float on the sea, and each boat can be drawn as a single point on the coordinate plane. The island is a convex polygon with M vertices. Every boat and every vertex of the island sits on a lattice point. The picture below is one example of an island and its boats.

(The orange convex polygon in the middle is the island, and the numbered blue points are the fishing boats.)
Every boat carries a radio, and two boats exchange messages when nothing blocks the way between them. To be exact, two boats exchange messages when the segment joining them does not meet the interior of the island. A segment that only touches a vertex or an edge of the convex polygon does not count as meeting the interior.
When boat 1 runs into trouble, it sends a rescue signal to every boat its signal reaches. Each boat that receives the rescue signal then sends a relay signal to every boat its own signal reaches, telling them that boat 1 is in trouble. A boat that receives a relay signal does not pass the signal on.
You know the M vertices of the island and the positions of the N boats numbered 1 to N. Boat 1 is in trouble. Count the boats that receive at least one of the rescue signal sent by boat 1 and the relay signals sent by the boats that received it. Boat 1 is not counted.
The first line contains the number of boats N (1≤N≤100000).
Each of the next N lines describes one boat. The i-th of these lines contains the x coordinate and the y coordinate of boat i, separated by a space.
The next line contains the number of vertices of the island M (3≤M≤100000).
Each of the next M lines describes one vertex. The i-th of these lines contains the x coordinate and the y coordinate of the i-th vertex of the island, separated by a space.
The island is a convex polygon and its vertices are given in counter-clockwise order. Two adjacent edges never have the same slope.
Every coordinate is an integer between −109 and 109.
All boats have distinct coordinates, and no boat lies inside the island or on its boundary.
Print the number of boats that receive the rescue signal or a relay signal when boat 1 is in trouble.