This page is still under construction.

Parts of this page are still being built. What you see may change.

Similar Polygons

Time limit1sMemory limit1024 MB

Summary
Decide whether two polygons are similar under rotation, reflection, translation, and scaling, then output the exact squared similarity ratio and the smallest matching vertex index.
Level

Hard8 of 10

Topics
Geometry, String matching, Math, Implementation
Solved
No attempts yet

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 NN of each polygon (3≤N≤200 0003 \le N \le 200\,000).

The second line contains the coordinates of the first polygon's vertices in order as 2⋅N2 \cdot N integers: x1 y1 x2 y2 … xN yNx_1\ y_1\ x_2\ y_2\ \dots\ x_N\ y_N. Each coordinate is an integer between −109-10^9 and 10910^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∘180^\circ) interior angle, and no self-intersection.

Output

If the two polygons are not similar, print −1-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/qp/q, where pp and qq are positive integers with gcd⁡(p,q)=1\gcd(p, q) = 1. This value is always rational, so it is written exactly; if the polygons are congruent it is 1/11/1.
  • On the second line, print the smallest 11-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 11 in input order.

Examples2

  1. Example 1

    Input
    4
    0 0 4 0 4 6 0 2
    -2 5 -2 1 -3 0 -5 2
    
    Expected output
    2/1
    3
    
  2. Example 2

    Input
    3
    0 0 3 0 1 1
    0 0 2 0 1 1
    
    Expected output
    -1