Under construction

Still being built. Things may change

Rescue Beacon

Time limit3sMemory limit128 MB

Summary
For each convex triangulated polyhedron, find the maximum number of facets visible from any single viewing direction, where visible means the facet normal has positive dot product with the direction.
Level

Medium7 of 10

Topics
Geometry, Sorting, Brute force, Implementation
Solved
No attempts yet

Problem

While fleeing some old and rather unhappy creditors, Han Solo crash-landed the Millennium Falcon on the ice world of Hoth. Now he must get some kind of emergency signal working before his Wookiee friend Chewbacca freezes solid or gets hungry enough to eat a Han-kabob. Can you help him?

Han salvaged a very bright laser that can be seen from light-years away and figured it would make a good signal. The trouble is that if he simply shines it straight up into the sky, there is almost no chance that someone happens to be in the path of the beam to see it. Meanwhile, Chewbacca was playing with a bunch of highly reflective, many-faceted crystals he found in a nearby cave. In a flash of inspiration, Han realized he could build a rescue beacon by shining the laser down onto a crystal, whose facets would in turn reflect the light back up into the sky in many directions at once!

Figure 1: A simplified, two-dimensional illustration of Han's rescue beacon.

The only thing left is to decide which crystal to use as the reflector. Each crystal is a convex polyhedron whose surface consists solely of perfectly triangular facets, and it can be placed in the beacon in any orientation. The best crystal is the one that reflects the laser beam (parallel rays coming from a single direction) back in the greatest number of directions. In other words, the reflective merit of a crystal is simply the number of facets you can see from a single viewing direction, since those are exactly the facets the laser can hit at the same time. Given the geometry of each crystal, compute the greatest number of directions in which the crystal can reflect the laser.

Input

The input consists of geometric descriptions of the crystals in Chewbacca's collection. Each crystal's description begins with a single line containing an integer nn (4≤n≤20004 \le n \le 2000), the number of facets of the crystal, followed by nn lines describing the facets. Each facet is given by 9 integers x1 y1 z1 x2 y2 z2 x3 y3 z3x_1\ y_1\ z_1\ x_2\ y_2\ z_2\ x_3\ y_3\ z_3, where the points (x1,y1,z1)(x_1, y_1, z_1), (x2,y2,z2)(x_2, y_2, z_2), and (x3,y3,z3)(x_3, y_3, z_3) are the vertices of the triangular facet, listed in counter-clockwise order as seen from the outside (in a right-handed coordinate frame). All coordinates satisfy −2000≤xi,yi,zi≤2000-2000 \le x_i, y_i, z_i \le 2000, no single facet has area greater than 200,000, and no two facets face the same direction. When all facets of a crystal are assembled they always form a closed convex polyhedron. Moreover, no crystal has any degeneracy that would make the number of facets the laser can hit ambiguous; that is, the data is built so that whether or not you count facets exactly parallel to the beam does not change the answer. The input ends with a line containing a single 00, which must not be processed as a crystal.

Output

For each crystal, output a single line containing one integer mm: the greatest number of directions (facets) in which the crystal can reflect the laser beam at the same time.

Examples4

  1. Example 1

    Input
    4
    0 1 1 -2 0 0 2 0 0
    0 1 1 2 0 0 0 3 0
    0 1 1 0 3 0 -2 0 0
    -2 0 0 0 3 0 2 0 0
    6
    0 1 1 -2 0 0 2 0 0
    0 1 1 2 0 0 0 3 0
    0 1 1 0 3 0 -2 0 0
    -2 0 0 0 1 -1 2 0 0
    2 0 0 0 1 -1 0 3 0
    0 3 0 0 1 -1 -2 0 0
    0
    
    Expected output
    3
    4
    
  2. Example 2

    Input
    4
    1 1 1 1 -1 -1 -1 1 -1
    1 1 1 -1 -1 1 1 -1 -1
    1 1 1 -1 1 -1 -1 -1 1
    1 -1 -1 -1 -1 1 -1 1 -1
    0
    
    Expected output
    3
    
  3. Example 3

    Input
    6
    0 0 4 3 0 0 -1 3 0
    1 -1 -3 -1 3 0 3 0 0
    0 0 4 -1 3 0 -2 -2 0
    1 -1 -3 -2 -2 0 -1 3 0
    0 0 4 -2 -2 0 3 0 0
    1 -1 -3 3 0 0 -2 -2 0
    0
    
    Expected output
    5
    
  4. Example 4

    Input
    8
    1 0 5 4 1 0 0 4 0
    -1 1 -4 0 4 0 4 1 0
    1 0 5 0 4 0 -3 0 0
    -1 1 -4 -3 0 0 0 4 0
    1 0 5 -3 0 0 0 -3 0
    -1 1 -4 0 -3 0 -3 0 0
    1 0 5 0 -3 0 4 1 0
    -1 1 -4 4 1 0 0 -3 0
    0
    
    Expected output
    6