Champagne Tower

Given up to 20 glasses with rim circles in 3D, pour champagne into the highest one at 100 ml/s and find when the whole tower fills, or report Invalid.

Medium7GeometrySimulationImplementationGreedyNo attempts yetTime limit2sMemory limit512 MB

Problem

You may have seen a champagne tower at a wedding or a party. In a typical three level tower, the lowest level holds 9 glasses touching in a square pattern, the second level holds 4 glasses touching in a square pattern centered above the first level, and the third level holds 1 glass centered above the two levels. Figure 1 shows a top down view of that tower.

Top down view of a three level champagne tower

Figure 1

Champagne is always poured directly into the top glass. In this example, once the top glass fills and starts to overflow, the 4 glasses below it immediately start filling. Overflowing champagne reaches the glasses below in zero time. Once the 4 glasses on the second level fill, they overflow onto the 9 glasses on the bottom level. The 4 glasses on the second level finish filling at the same moment, but the 9 glasses on the lowest level finish at different moments, so some champagne spills on the floor before the tower is done. That loss is an acceptable price for such a beautiful sight.

The new fad is to lay glasses out into a pattern or an image. These towers do not need to be structurally sound. A support system designed so as not to interfere with the overflowing champagne holds the glasses in place. Every such tower has exactly one highest glass, and all champagne is poured directly into it.

Seen from above, the rim of a glass is a circle. Overflow follows these rules.

  • Once a glass is full, every further drop that arrives spills over its rim, spread evenly along the whole circle, and falls straight down.
  • A falling drop lands in a glass when its landing point is inside that glass's rim circle. Only a glass whose zz is smaller than the zz of the overflowing glass can receive it. When several such glasses contain the landing point, the one with the largest zz receives it.
  • If two glass rims coincide vertically, that is, they have the same center and the same radius, then no champagne accumulates in the lower glass from the upper one. Champagne overflowing the upper glass can still be collected by other lower glasses.
  • A single point of overflow causes no measurable accumulation. Champagne accumulates only when an arc of positive length overflows into the interior of a glass.

Determine whether a proposed champagne tower fills to completion, and if it does, how long that takes.

Input

The first line contains one integer nn, the number of glasses in the tower (1n201 \le n \le 20). Each of the next nn lines describes one glass with five integers xx yy zz rr vv. The point (x,y,z)(x, y, z) is the center of the glass's rim (0x,y10000 \le x, y \le 1000, 1z10001 \le z \le 1000), rr is the radius of the rim (1r10001 \le r \le 1000), and vv is the volume of the glass in milliliters (1v10001 \le v \le 1000). All input values are integers. Exactly one glass has the largest zz, and champagne is poured into that glass at a constant 100 milliliters per second.

Output

Print the number of seconds after which the tower is completely filled, or Invalid if the tower never fills completely. Round the answer to the hundredths place, always print two decimal places, and include the leading 0 for an answer between 0 and 1. Output values are always at most 10610^6 seconds.