Under construction

Still being built. Things may change

Geometry Enjoyer

Time limit7sMemory limit2048 MB

Summary
Given the pairwise intersection points of the extended sides of a convex polygon with no parallel sides, recover the polygon's vertices as exact rational coordinates.
Level

Hard9 of 10

Topics
Geometry, Math, Implementation
Solved
No attempts yet

Problem

Altair was playing with the points on the plane, as usual. One day he found a new game and asked you to play it with him.

He drew a convex polygon with kk sides on the plane. No two sides of the polygon are parallel. Then he extended every side to a line and found the intersection point of every pair of lines.

He now gives you the points he got. Find the original polygon from these points.

Input

The first line contains one integer nn (1≤n≤2001 \le n \le 200), the number of points.

Each of the next nn lines contains four integers pxp_x, qxq_x, pyp_y, and qyq_y (−106≤px,py≤106-10^6 \le p_x, p_y \le 10^6, 1≤qx,qy≤1061 \le q_x, q_y \le 10^6). The X coordinate of the ii-th point is px/qxp_x / q_x, and the Y coordinate is py/qyp_y / q_y. pxp_x and qxq_x are coprime, and pyp_y and qyq_y are coprime.

It is guaranteed that the polygon is uniquely determined by the given points.

Output

Print the number of vertices kk on the first line.

Each of the next kk lines contains the coordinates of one vertex in the form pxp_x, qxq_x, pyp_y, qyq_y. The vertices may be printed in any order. Each pxp_x and qxq_x must be coprime, and each pyp_y and qyq_y must be coprime.

Examples1

  1. Example 1

    Input
    6
    1 1 2 1
    12 5 24 5
    0 1 0 1
    3 1 3 1
    -3 1 0 1
    4 1 0 1
    
    Expected output
    4
    0 1 0 1
    1 1 2 1
    3 1 3 1
    4 1 0 1