Neighbors
Winnie-the-Pooh and Piglet have been friends for a long time, despite living far apart. They cherish their homes and prefer not to move closer, even if it means seeing each other more often. The wise Owl suggested they purchase adjacent summer plots, allowing them to spend more time together during the warm months.
Grateful for Owl's advice, they followed it eagerly. The summer plots they bought are polygons of arbitrary shapes, with edges aligned parallel to the coordinate axes.
Each plot is enclosed by a fence, and unfortunately, there is also a fence along the shared boundary segments. Without much deliberation, Winnie-the-Pooh and Piglet decided to remove this shared fence. Your task is to help them determine the total length of the shared boundary segments they need to remove.
Input
The first line contains a single integer V – the number of vertices in the boundary of Winnie-the-Pooh's plot (4 ≤ V ≤ 1000). The following V lines each contain two integers, separated by a space, representing the coordinates of the vertices of the closed polyline that forms the boundary of this plot.
The next line contains a single integer P – the number of vertices in the boundary of Piglet's plot (4 ≤ P ≤ 1000). The following P lines each contain two integers, separated by a space, representing the coordinates of the vertices of the closed polyline that forms the boundary of this plot.
All coordinates are within the range of -5000 to 5000.
It is guaranteed that the plots do not overlap, meaning the area of intersection is zero.
Output
Output a single non-negative integer representing the length of the common boundary between the two plots.