Under construction

Still being built. Things may change

Convex hull of angles

Time limit2sMemory limit1024 MB

Summary
Given n angles as a vertex and two ray points each, print the boundary of the convex hull of all points on the angles as segments, rays, and lines.
Level

Medium7 of 10

Topics
Geometry, Sorting
Solved
No attempts yet

Statement

A set of points in the plane is convex if it contains the segment joining any two of its points. The convex hull of a set X is the smallest convex set, by inclusion, that contains X. In this problem you find the convex hull of the points that lie on a given collection of angles. An angle is the figure formed by two rays that start from the same point, called the vertex of the angle. The figure on the left shows two angles, and the figure on the right shows their convex hull.

Input

The first line contains the number of angles nn (1≤n≤10001 \le n \le 1000). Each of the next nn lines describes one angle with three points: the vertex, and one point other than the vertex on each of the two rays. All coordinates are integers with absolute value at most 10410^4. The size of each angle is greater than 0 and less than 180 degrees.

Output

Print the boundary of the convex hull as a sequence of rays, lines and segments. No two objects in the output may lie on the same line. Every segment must have positive length. Each object must start where the previous object ends. All numbers in the output are integers with absolute value at most 10510^5. When you walk along the boundary in the listed order, the convex hull of the angles must be on your right.

Print ll, the number of objects, on the first line. The next ll lines describe the objects as follows. segment x1 y1 x2 y2 is a segment directed from (x1,y1)(x_1, y_1) to (x2,y2)(x_2, y_2). outray x1 y1 x2 y2 is a ray starting at (x1,y1)(x_1, y_1) that passes through the point (x2,y2)(x_2, y_2). inray x1 y1 x2 y2 is a ray starting at (x2,y2)(x_2, y_2) that passes through (x1,y1)(x_1, y_1). line x1 y1 x2 y2 is a line through both points, where (x1,y1)(x_1, y_1) comes before (x2,y2)(x_2, y_2) when moving along its direction.

If the convex hull is the whole plane, print l=0l = 0.

Examples3

  1. Example 1

    Input
    2
    3 1 4 1 4 4
    2 2 4 3 3 4
    
    Expected output
    3
    inray 4 1 3 1
    segment 3 1 2 2
    outray 2 2 3 5
    
  2. Example 2

    Input
    2
    0 0 1 0 0 1
    0 0 -1 0 0 1
    
    Expected output
    1
    line 1 0 -1 0
    
  3. Example 3

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