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, and if so print the square of the similarity factor as a reduced fraction and the matching vertex index in the second polygon.
Level

Hard8 of 10

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

Problem

Juku is learning about polygon similarity at school. Two polygons are similar if all corresponding angles are equal and all corresponding side lengths are in the same ratio. Similar polygons may be rotated, reflected, and translated relative to one another. The ratio of corresponding side lengths of two similar polygons is called their similarity factor.

For homework Juku receives several pairs of polygons and must decide, for each pair, whether the polygons are similar and, if so, what their similarity factor is. Some polygons have a very large number of vertices, so help Juku finish his homework.

Input

The first line contains the number of polygon vertices NN (3≤N≤200 0003 \le N \le 200\,000). The second line contains 2N2N integers between −109-10^9 and 10910^9: the xx and yy coordinates of the vertices of the first polygon, in order. The third line likewise contains the 2N2N coordinates of the second polygon's vertices.

The vertices may be given in either clockwise or counterclockwise order. The given points always form a polygon with no coinciding points, no straight (180°180°) angles, and no self-intersections. Moreover, within each polygon all side lengths are distinct.

Output

If the two polygons are similar, print two lines.

  • On the first line print the square of the enlargement factor as a reduced fraction p/q. The enlargement factor is how many times larger the first polygon is than the second (if the first is smaller, it is less than 11); pp and qq are positive integers with gcd⁡(p,q)=1\gcd(p,q)=1, and the denominator is always written, even when it is 11 (e.g. 2/1). The factor itself may be irrational and thus cannot be compared exactly, so its square — which is always rational — is printed instead (the factor is k=p/qk=\sqrt{p/q}).
  • On the second line print the index of the vertex of the second polygon that corresponds to the first vertex of the first polygon. Vertices of both polygons are numbered from 11 in the order they appear in the input.

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

Because all side lengths within a polygon are distinct (so the polygon has no symmetry), this correspondence is uniquely determined.

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