CSES - Aalto Competitive Programming 2024 - wk11 - Wed - Match polygons
  • Time limit: 1.00 s
  • Memory limit: 512 MB

You are given two polygons that both have nn vertices numbered 1,2,,n1,2,\dots,n. The ii-th vertices of polygons 11 and 22 are at positions (xi1,yi1)(x^1_i, y^1_i) and (xi2,yi2)(x^2_i, y^2_i) respectively. There is a line between all pairs of vertices (i1,i)(i-1, i) for i{2,3,n}i \in \{2,3\dots,n\} and a line between vertices 11 and nn. Check if the polygons have the same shape i.e. check if polygon 1 is a moved, scaled and rotated version of the polygon 22. Mirroring is not an allowed operation. Also note that the edges of a polygon might intersect i.e. the polygons might not be simple.

The polygons are considered the same when there is a sequence of move, scale & rotation operations so that after such a sequence the matching vertices of polygons 11 and 22 all lie within 10610^{-6} distance of each other.

Note that the problem setter of this task avoids self-inflicted torture like any normal person would. Therefore the task does not have tests that are intentionally designed to test the numerical stability of your solution.

Input

The first line contains a single integer nn. The ii-th of next nn lines contains two integer xi1x^1_i and yi1y^1_i, which shows the vertices of first polygon. The ii-th of next nn lines contains two integer xi2x^2_i and yi2y^2_i, which shows the vertices of second polygon.

Output

Print "Yes" if the polygons are the same and "No" otherwise.

Constraints

  • 3n1053 \leq n \leq 10^5
  • 4000xi1,yi1,xi2,yi24000-4000 \leq x^1_i, y^1_i, x^2_i, y^2_i \leq 4000
  • (xi1,yi1)(xj1,yj1)(x^1_i, y^1_i) \neq (x^1_j, y^1_j) if iji \neq j
  • (xi2,yi2)(xj2,yj2)(x^2_i, y^2_i) \neq (x^2_j, y^2_j) if iji \neq j

Example 1

Input:

4
0 0
0 1
1 1
1 0
0 0
1 1
2 0
1 -1

Output:

Yes

Example 2

Input:

3
0 0
0 2
1 2
0 0
0 2
-1 2

Output:

No

Example 3

Input:

5
-366.1704671086 -357.8889078190
1.8745954997 -4.2267016836
-154.5013572565 -333.2236489526
-251.8988265336 -415.9403461640
-281.4413257844 -81.4918140235
356.7482951051 444.6486788624
350.1820621273 423.2288027266
378.7043578765 450.6364738613
366.5857299537 425.1402800961
359.0377427473 418.7300049941

Output:

Yes