Problem: 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.

<image>
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.

<image>
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 16
2
10 10 20
10 -10 20
2
100 0 101
-90 0 91
2
0 0 53
30 40 102
3
10 10 20
10 -10 20
-10 -10 20
3
1 5 13
5 -3 13
-3 -3 13
3
98 97 168
-82 -80 193
-99 -96 211
4
90 -100 160
-80 -80 150
90 80 150
80 80 245
4
85 -90 290
-80 -80 220
-85 90 145
85 90 170
5
0 0 4
3 0 5
-3 0 5
0 3 5
0 -3 5
10
95 -93 260
-86 96 211
91 90 177
-81 -80 124
-91 91 144
97 94 165
-90 -86 194
89 85 167
-93 -80 222
92 -84 218
0


Output for the Sample Input


17.3205081
16.0000000
17.3205081
13.8011200
53.0000000
14.1421356
12.0000000
128.3928757
94.1879092
131.1240816
4.0000000
72.2251798






Example

Input

3
10 10 20
10 -10 20
-10 10 120
1
10 10 16
2
10 10 20
10 -10 20
2
100 0 101
-90 0 91
2
0 0 53
30 40 102
3
10 10 20
10 -10 20
-10 -10 20
3
1 5 13
5 -3 13
-3 -3 13
3
98 97 168
-82 -80 193
-99 -96 211
4
90 -100 160
-80 -80 150
90 80 150
80 80 245
4
85 -90 290
-80 -80 220
-85 90 145
85 90 170
5
0 0 4
3 0 5
-3 0 5
0 3 5
0 -3 5
10
95 -93 260
-86 96 211
91 90 177
-81 -80 124
-91 91 144
97 94 165
-90 -86 194
89 85 167
-93 -80 222
92 -84 218
0


Output

17.3205081
16.0000000
17.3205081
13.8011200
53.0000000
14.1421356
12.0000000
128.3928757
94.1879092
131.1240816
4.0000000
72.2251798

Solution (in CPP):

Solution:
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include <set>
constexpr double EPSILON = 1e-9;
struct Coordinate {
	double x, y;
	double distance(const Coordinate that) const;
};
struct Angle {
	double sin, cos;
	Angle operator-() const;
	static Angle from_cos(const double cos);
};
struct Vector {
	double dx, dy;
	Vector rotate(const Angle angle) const;
	double length() const;
};
Vector operator*(const Vector vec, const double scala);
Vector operator*(const double scala, const Vector vec);
Vector operator-(const Coordinate to, const Coordinate from);
Coordinate operator+(const Coordinate coord, const Vector vec);
Coordinate operator+(const Vector vec, const Coordinate coord);
struct Circle {
	Coordinate center;
	double radius;
	bool contains(const Coordinate that) const;
	std::vector<Coordinate> cross_points(const Circle that) const;
};
struct Anchor {
	double x, y, length;
	Circle slice(double height) const;
};
int main() {
	while (true) {
		int n; std::cin >> n; if (n == 0) break;
		std::vector<Anchor> anchors(n); for (auto& a : anchors) std::cin >> a.x >> a.y >> a.length;
		if (n == 1) {
			std::cout << std::setprecision(15) << std::fixed << anchors.front().length << std::endl;
			continue;
		}
		double min = 0;
		double max = std::min_element(anchors.begin(), anchors.end(), [](const Anchor a, const Anchor b) {return a.length < b.length; })->length;
		std::vector<Circle> circles(n);
		for (auto i = 0; i < 60; ++i) {
			const auto mid = (min + max) / 2;
			std::transform(anchors.begin(), anchors.end(), circles.begin(), [mid](const Anchor a) {return a.slice(mid); });
			bool has_intersection = false;
			for (auto i = 0; i < n && !has_intersection; ++i) {
				for (auto j = 0; j < i && !has_intersection; ++j) {
					for (const auto coordinate : circles[i].cross_points(circles[j])) {
						has_intersection = true;
						for (auto k = 0; k < n; ++k) if (i != k && j != k) {
							if (!circles[k].contains(coordinate)) {
								has_intersection = false;
								break;
							}
						}
						if (has_intersection) break;
					}
				}
				if (has_intersection) continue;
				has_intersection = true;
				for (auto j = 0; j < n && has_intersection; ++j) {
					has_intersection = i == j || circles[j].contains(circles[i].center);
				}
			}
			if (has_intersection) min = mid;
			else max = mid;
		}
		std::cout << std::setprecision(15) << std::fixed << max << std::endl;
	}
}


bool Circle::contains(const Coordinate that) const
{
	return center.distance(that) <= radius + EPSILON;
}

std::vector<Coordinate> Circle::cross_points(const Circle that) const
{
	const auto dist = center.distance(that.center);
	if (dist > radius + that.radius + EPSILON) return std::vector<Coordinate>{};
	const auto cos = (radius * radius + dist * dist - that.radius * that.radius) / (2 * radius * dist);
	const auto angle = Angle::from_cos(cos);
	const auto vec = (that.center - center) * (radius / dist);
	return std::vector<Coordinate>{vec.rotate(angle) + center, vec.rotate(-angle) + center};
}

Vector Vector::rotate(const Angle angle) const
{
	return Vector{ dx * angle.cos - dy * angle.sin, dy * angle.cos + dx * angle.sin };
}

double Vector::length() const
{
	return std::sqrt(dx * dx + dy * dy);
}

Angle Angle::operator-() const
{
	return Angle{ -sin, cos };
}

Angle Angle::from_cos(const double cos)
{
	return Angle{ std::sqrt(1 - cos * cos), cos };
}

Vector operator*(const Vector vec, const double scala)
{
	return Vector{ vec.dx * scala, vec.dy * scala };
}

Vector operator*(const double scala, const Vector vec)
{
	return Vector{ scala * vec.dx, scala * vec.dy };
}

Vector operator-(const Coordinate to, const Coordinate from)
{
	return Vector{ to.x - from.x, to.y - from.y };
}
Coordinate operator+(const Coordinate coord, const Vector vec)
{
	return Coordinate{ coord.x + vec.dx, coord.y + vec.dy };
}

Coordinate operator+(const Vector vec, const Coordinate coord)
{
	return Coordinate{ vec.dx + coord.x, vec.dy + coord.y };
}

double Coordinate::distance(const Coordinate that) const
{
	return (*this - that).length();
}

Circle Anchor::slice(double height) const
{
	const auto radius = std::sqrt(length * length - height * height);
	return Circle{ Coordinate{x, y}, radius };
}