Crash and Go(relians)#3112

Crash and Go(relians)

1 second
64 megabytes
Medium

The Gorelians are a warlike race who travel the universe, conquering new worlds for entertainment. Usually, their space battles are one-sided, but sometimes, even the Gorelians experience defeat. In one such battle, their spaceship was so badly damaged that they had to evacuate to the planet below. Due to the chaos (and the inaccuracy of escape pods), the Gorelians ended up scattered across a large area of the planet (but still small enough that its surface can be modeled as a plane, not a sphere). Your task is to track their efforts to regroup. Fortunately, each escape pod is equipped with a locator, informing its Gorelian of their current coordinates on the planet, and a radio for communicating with other Gorelians. Unfortunately, the radio's range is limited by the available power supply.

When a Gorelian lands on an alien planet, the first thing they do is check their radio to see if they can contact any other Gorelians. If so, they arrange a rendezvous point and gather at that spot. Once together, they pool the power supplies of their radios, increasing their range. Then they repeat the process—checking whom they can reach, arranging to meet, pooling their radios—until they can no longer contact any other Gorelians.

Gorelian technology allows two-way communication if at least one has a radio with sufficient range to cover the distance between them. For example, if Alice has a radio with range km and Bob has one with km, but they are km apart (Figure ), they cannot communicate. However, if the distance between them is km (Figure ), Alice's radio can reach Bob, and they can communicate.

If a Gorelian successfully connects with others, they meet at a location which is the average of their positions. In the case of Alice and Bob, this is the midpoint between and (Figure ). Gorelians switch off their radios while traveling; they will not attempt to communicate with others until everyone is assembled at the meeting spot. When Gorelians gather, they combine their radios, creating a new one with greater range. In particular, the area covered by the new radio equals the sum of the areas covered by the old radios. For example, if Alice's range is km, her radio covers an area of km^2. Bob's radio covers km^2. By merging them, they cover km^2, i.e., they have a range of km. They then attempt to reach other Gorelians again.

This process continues until no further contacts can be made. As an example, suppose the following Gorelians have landed, each with a radio radius of km: Alice , Bob , Cathy , and Dave . None of them can communicate with another (Figure ). Then Eddie lands at (Figure ). Eddie can contact Alice and Cathy, so they arrange to meet at , the average of their locations. Combining their radios gives them a range of \sqrt{2700} \approx 51.96 km (Figure ).

Now, with their new range, they check again and find they can reach Bob. They meet Bob at and combine radios, obtaining a radius of (Figure ). Unfortunately, this is still not enough to reach Dave, so Dave remains isolated.

Input

The input will consist of one or more datasets. Each dataset will begin with an integer , representing the number of Gorelians in this set (1 \le N \le 100). A value of N = 0 will indicate the end of input.

Each dataset is followed by lines, each containing three integers , , and , representing the and coordinates where a Gorelian lands, and the range of their radio (0 \le X, Y \le 1000, 1 \le R \le 1000). Note that only initial coordinates/ranges are integers; after merging with other Gorelians, they may no longer be integers. You must use double-precision arithmetic for all computations.

Gorelians land in the order they appear in the input file. When a Gorelian lands, they merge with any Gorelians they can contact, and the process continues until no further mergers are possible. The next Gorelian does not land until all previous merging has completed.

Output

The output will contain a single line per dataset, reporting the number of independent groups of Gorelians remaining at the end of the process.

Examples

Example 1

Loading
Loading