Similar Polygons

No attempts yetTime limit1sMemory limit1024 MB

Problem

Two polygons are similar if all of their corresponding angles are equal and all of their corresponding side lengths are in the same ratio. Two similar polygons may be rotated, reflected (mirrored), and translated relative to each other. The ratio of the lengths of corresponding sides is called their similarity ratio.

Given two polygons, determine whether they are similar. If they are, report how their sizes relate and how their vertices correspond.

Input

The first line contains the number of vertices $N$ of each polygon ($3 \le N \le 200,000$).

The second line contains the coordinates of the first polygon's vertices in order as $2 \cdot N$ integers: $x_1\ y_1\ x_2\ y_2\ \dots\ x_N\ y_N$. Each coordinate is an integer between $-10^9$ and $10^9$.

The third line contains the second polygon's vertex coordinates in the same format.

The vertices of each polygon may be given in either clockwise or counterclockwise order. The given points always form a valid simple polygon with no two coincident vertices, no straight ($180^\circ$) interior angle, and no self-intersection.

Output

If the two polygons are not similar, print $-1$ on a single line.

Otherwise, print two lines.

  • On the first line, print the square of the similarity ratio (how many times larger the first polygon is than the second, squared — equivalently, the ratio of their areas) as an irreducible fraction $p/q$, where $p$ and $q$ are positive integers with $\gcd(p, q) = 1$. This value is always rational, so it is written exactly; if the polygons are congruent it is $1/1$.
  • On the second line, print the smallest $1$-based index of a vertex of the second polygon that can correspond to the first vertex of the first polygon under some valid similarity (rotation, reflection, translation, and uniform scaling). The vertices of each polygon are numbered from $1$ in input order.