Dynamic geometry software helps students understand transformation geometry because it shows what a transformation does to a shape. Alice is learning the elementary transformations, slides, flips and turns, or more formally translations, reflections and rotations. Today she works on slides and turns.
The shapes Alice works with are simple rectilinear polygons drawn on a regular square grid. Each polygon has at most one edge per grid line, and every vertex is a grid point.
Alice uses these definitions.
Alice is given two simple rectilinear polygons with no collinear edges. She has to decide whether slides and turns can take both of them to the same permutomino under restricted rules. The two polygons are handled as independent instances, as if they were in different grids.
First she removes the empty grid lines of the minimum bounding rectangle to obtain a permutomino. She slides some edges to the left or downwards in such a way that the relative order of the edges is preserved: sweeping the plane with a vertical or a horizontal line meets the edges in the same order as before.
Once she has the permutomino, she can apply a rotation by 90 degrees clockwise around the center of its minimum bounding square, as many times as she wishes.
Given a pair of such polygons, answer Alice's question.
The first line contains the description of the first rectilinear polygon: the number of vertices, followed by their coordinates in a canonical cartesian system. The vertices are given in counterclockwise order and start at the leftmost vertex on the bottom horizontal edge. The last vertical edge is defined by the last vertex and the first one. The bottom-left corner of the minimum bounding rectangle is always (0,0).
The second line contains the description of the other rectilinear polygon in the same format. The two polygons may have different numbers of vertices.
For each polygon the number of vertices is even and between 4 and 500. The coordinates (x,y) of every vertex satisfy 0≤x≤3000 and 0≤y≤3000.
Print one line containing the answer, yes or no.