Geometry Enjoyer

시간 제한7초메모리 제한2048 MB

요약
어떤 볼록 다각형의 각 변을 연장한 직선들의 교점들이 주어질 때, 원래 다각형의 꼭짓점을 복원한다.
난이도

어려움10점 중 8점

유형
기하, 조합론, 구현, 수학
정답자
아직 제출이 없습니다

문제

Altair was playing with the points on the plane (as usual). At some point, he discovered a new game that he will play with you.

He made a convex polygon with kk sides on the two-dimensional plane. The polygon had a really nice property: no pair of sides are parallel. Then he extended every side of the polygon to a line, and found the intersection point for every pair of lines.

Now he gives you the points he got. You should find the initial polygon.

입력

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

Each of the next nn lines contains four integers, p_xp\_x, q_xq\_x, p_yp\_y, and q_yq\_y (−106≤p_x,p_y≤106-10^6 \le p\_x, p\_y \le 10^6, 1≤q_x,q_y≤1061 \le q\_x, q\_y \le 10^6): the coordinates of the ii-th point. The XX coordinate equals p_x/q_xp\_x / q\_x, and the YY coordinate equals p_y/q_yp\_y / q\_y. It is guaranteed that the values p_xp\_x and q_xq\_x are coprime, and the values p_yp\_y and q_yq\_y are coprime.

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

출력

The first line of the output should contain one integer kk: the size of the polygon.

You can output the vertices of the polygon in any order.

Each of the next kk lines should contain four integers, p_xp\_x, q_xq\_x, p_yp\_y, and q_yq\_y (−106≤p_x,p_y≤106-10^6 \le p\_x, p\_y \le 10^6, 1≤q_x,q_y≤1061 \le q\_x, q\_y \le 10^6): the coordinates of the polygon vertices. The XX coordinate equals p_x/q_xp\_x / q\_x, and the YY coordinate equals p_y/q_yp\_y / q\_y. The values p_xp\_x and q_xq\_x should be coprime, and the values p_yp\_y and q_yq\_y should be coprime.

예제1

  1. 예제 1

    입력
    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
    
    예상 출력
    4
    0 1 0 1
    1 1 2 1
    3 1 3 1
    4 1 0 1