human
Write me a Python program to find how high the balloon can go up with keeping the rope connections given the following:
Anchored Balloon

A balloon placed on the ground is connected to one or more anchors on the ground with ropes. Each rope is long enough to connect the balloon and the anchor. No two ropes cross each other. Figure E-1 shows such a situation.

Figure E-1: A balloon and ropes on the ground

Now the balloon takes off, and your task is to find how high the balloon can go up with keeping the rope connections. The positions of the anchors are fixed. The lengths of the ropes and the positions of the anchors are given. You may assume that these ropes have no weight and thus can be straightened up when pulled to whichever directions. Figure E-2 shows the highest position of the balloon for the situation shown in Figure E-1.

Figure E-2: The highest position of the balloon

Input

The input consists of multiple datasets, each in the following format.

> n
>  x1 y1 l1
>  ...
>  xn yn ln
>

The first line of a dataset contains an integer n (1 ≤ n ≤ 10) representing the number of the ropes. Each of the following n lines contains three integers, xi, yi, and li, separated by a single space. Pi = (xi, yi) represents the position of the anchor connecting the i-th rope, and li represents the length of the rope. You can assume that −100 ≤ xi ≤ 100, −100 ≤ yi ≤ 100, and 1 ≤ li ≤ 300. The balloon is initially placed at (0, 0) on the ground. You can ignore the size of the balloon and the anchors.

You can assume that Pi and Pj represent different positions if i ≠ j. You can also assume that the distance between Pi and (0, 0) is less than or equal to li−1. This means that the balloon can go up at least 1 unit high.

Figures E-1 and E-2 correspond to the first dataset of Sample Input below.

The end of the input is indicated by a line containing a zero.

Output

For each dataset, output a single line containing the maximum height that the balloon can go up. The error of the value should be no greater than 0.00001. No extra characters should appear in the output.

Sample Input

3
10 10 20
10 -10 20
-10 10 120
1
10 10...
assistant
#Here is Python program to find how high the balloon can go up with keeping the rope connections.

#!/usr/bin/python

import os
import sys
import math

def solve(f):
    n = f.read_int()
    if n == 0: raise StopIteration
    ary = [f.read_float_list() for _ in xrange(n)]

    x_min = -100.0
    x_max = 100.0

    for _ in xrange(60):
        c1 = (x_min*2 + x_max) / 3
        c2 = (x_min + x_max*2) / 3
        if search_y(ary, c1) > search_y(ary, c2):
            x_max = c2
        else:
            x_min = c1

    return math.sqrt(search_y(ary, x_max))

def search_y(ary, x):
    y_min = -100.0
    y_max = 100.0

    for _ in xrange(60):
        c1 = (y_min*2 + y_max) / 3
        c2 = (y_min + y_max*2) / 3
        if calc(ary, x, c1) > calc(ary, x, c2):
            y_max = c2
        else:
            y_min = c1

    return calc(ary, x, y_max)

def calc(ary, x, y):
    return min([item[2]**2 - (item[0]-x)**2 - (item[1]-y)**2 for item in ary])

class Reader(object):
    def __init__(self, filename=None):
        self.test_mode = filename is not None
        self.cases = 1
        self.buffer = []
        if self.test_mode:
            with open(filename) as f:
                blank_flg = False
                for line in f:
                    line = line.strip()
                    if line:
                        self.buffer.append(line)
                        blank_flg = False
                    else:
                        if not blank_flg: self.cases += 1
                        blank_flg = True

    def __readline(self):
        return self.buffer.pop(0) if self.test_mode else raw_input()

    def read_int(self):
        return int(self.__readline())
    def read_float(self):
        return float(self.__readline())
    def read_long(self):
        return long(self.__readline())
    def read_str(self):
        return self.__readline()

    def read_int_list(self):
        return [int(item) for item in self.__readline().split()]
    def read_float_list(self):
        return [float(item) for item in self.__readline().split()]
    def read_long_list(self):
        return [long(item) for item in...