Rotating Cutter Bits

The program counts interior lattice points of a polygonal workpiece that survive one full rotation against a second rotating polygonal cutter.

Hard9GeometrySimulationIntervalsNo attempts yetTime limit3sMemory limit256 MB

Problem

Machine tool technology keeps advancing. One recent proposal is a more flexible lathe in which the cutter bit rotates together with the workpiece, around two parallel axles, in synchronization. When the lathe is switched on, the workpiece and the cutter bit start rotating at the same angular velocity, that is, in the same direction and at the same rotational speed. Wherever the cutter bit meets the workpiece, the overlapping part of the workpiece is cut away.

To show that the mechanism is useful, simulate the cutting process of such a lathe.

The workpiece and the cutter bit may have complicated shapes, but looking at their cross sections on a plane perpendicular to the two axles is enough. Put an xyxy coordinate system on that plane, with the center of rotation of the workpiece at the origin (0,0)(0, 0) and the center of rotation of the cutter bit at (L,0)(L, 0). Both cross sections are polygons, not necessarily convex.

Even when the cross section of the workpiece is split into two or more parts, the workpiece stays connected on other cross sections, so no piece falls off.

A lattice point, a point whose xx and yy coordinates are both integers, that lies strictly inside the workpiece before the rotation, that is, inside it and not on an edge, is called a point of interest, or POI for short.

Count how many POI remain after the workpiece and the cutter bit each complete one full rotation of 360 degrees. A POI remains if it lies strictly inside the resulting workpiece. Write a program that counts them for the given workpiece and cutter bit configuration.

Figure 1. The workpiece and the cutter bit in the first example

Figure 1(a) shows the workpiece (black line) and the cutter bit (blue line) of the first example input. The two circles mark the two centers of rotation, and the red cross marks are the POI. Figure 1(b) shows the two shapes partway through a clockwise rotation, with the light blue area already cut off. Figure 1(c) shows the result. One POI lies on an edge of the resulting shape, and that point is not counted. Eight POI remain.

Input

The input consists of a single test case in the following format.

M N L
xw1 yw1
.
.
.
xwM ywM
xc1 yc1
.
.
.
xcN ycN

The first line contains three integers. MM is the number of vertices of the workpiece, with 4M204 \le M \le 20. NN is the number of vertices of the cutter bit, with 4N204 \le N \le 20. LL specifies the position of the center of rotation of the cutter bit, with 1L100001 \le L \le 10000.

Each of the following MM lines contains two integers. The ii-th line holds xwixw_i and ywiyw_i, telling that the ii-th vertex of the workpiece is at (xwi,ywi)(xw_i, yw_i). The vertices are given in counter-clockwise order.

The next NN lines give the vertices of the cutter bit in the same manner, except that the coordinates are offsets from its center of rotation (L,0)(L, 0). That is, the jj-th vertex of the cutter bit is at (L+xcj,ycj)(L + xc_j, yc_j).

For 1iM1 \le i \le M and 1jN1 \le j \le N, 10000xwi,ywi,xcj,ycj10000-10000 \le xw_i, yw_i, xc_j, yc_j \le 10000.

Before the rotation starts, every edge of the workpiece and of the cutter bit is parallel to the xx-axis or to the yy-axis. That is, with i=(imodM)+1i' = (i \bmod M) + 1, every ii with 1iM1 \le i \le M satisfies xwi=xwixw_i = xw_{i'} or ywi=ywiyw_i = yw_{i'}. Edges parallel to the xx-axis and edges parallel to the yy-axis alternate. The same holds for the cutter bit.

The cross section of the workpiece is a simple polygon, that is, no two edges have a common point except for adjacent edges. The same holds for the cutter bit. The workpiece and the cutter bit neither touch nor overlap before the rotation starts.

(0,0)(0, 0) is not always inside the workpiece, and (L,0)(L, 0) is not always inside the cutter bit.

Output

Print the number of POI that remain strictly inside the workpiece.