Playing with Geometry

No attempts yetTime limit1sMemory limit256 MB

Problem

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.

  • A rectilinear polygon is a polygon whose edges meet at right angles.
  • In a simple polygon the edges meet only at their endpoints. The vertices are the points where edges meet.
  • The region bounded by a rectilinear polygon embedded on a grid corresponds to a polyomino, a shape made of unit squares.
  • A permutomino is a polyomino that has exactly one edge on every grid line that intersects its minimum bounding rectangle. That rectangle is then a square. For a permutomino with nn vertices, the square intersects n/2n/2 horizontal and n/2n/2 vertical grid lines.

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.

Input

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)(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 44 and 500500. The coordinates (x,y)(x, y) of every vertex satisfy 0x30000 \le x \le 3000 and 0y30000 \le y \le 3000.

Output

Print one line containing the answer, yes or no.