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 <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <chrono>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
template<class T, int s>using va = vector<array<T, s>>;
template<class T, class T2> using umap = unordered_map<T, T2>;
template<class T> using uset = unordered_set<T>;
template<class T, class S> void cmin(T &a, const S&b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S&b) { if (a < b)a = b; }
#define ALL(a) a.begin(),a.end()
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a) for(int i=1;i<=a;i++)
#define rrep(i,a) for(int i=a-1;i>=0;i--)
#define rrep1(i,a) for(int i=a;i;i--)
const ll mod = 1000000007;
#ifndef INT_MAX
const int INT_MAX = numeric_limits<signed>().max();
#endif
template<class T>using heap = priority_queue<T, vector<T>, greater<T>>;
template<class T>using pque = priority_queue<T, vector<T>, function<T(T, T)>>;
template <class T>
inline void hash_combine(size_t & seed, const T & v) {
    hash<T> hasher;
    seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}

const ld eps = 1e-11, pi = acos(-1.0);
typedef complex<ld> P;
typedef vector<P> VP;
ld dot(P a, P b) { return real(conj(a) * b); }
ld cross(P a, P b) { return imag(conj(a) * b); }
 
namespace std {
    bool operator<(const P &a, const P &b) {
        return abs(a.real() - b.real()) < eps ? a.imag() < b.imag() : a.real() < b.real();
    }
}
 
struct L { P a, b; };//line->l,segment->s
struct C { P p; ld r; };
 
int ccw(P a, P b, P c) {
    b -= a; c -= a;
    if (cross(b, c) > 0) return 1;   // counter clockwise
else return -1;
    if (cross(b, c) < -eps) return -1; // clockwise
    if (dot(b, c) < 0) return 2;       // c--a--b on line
    if (norm(b) < norm(c)) return -2;  // a--b--c on line
    return 0;                          // a--c--b on line
}
 
int main() {
    int n;
    cin.sync_with_stdio(0);
    while (cin >> n, n) {
        va<int, 3> bl(n);
        rep(i, n)rep(j, 3)cin >> bl[i][j];
        //va<double, 3> h;
        double ans = 1e9;
        int mina = 0;
        rep(i, n)if (ans > bl[i][2])ans = bl[i][2], mina = i;
        ans *= ans;
        rep(i,n){
            rep(j,i){
                double l = sqrt((bl[i][0] - bl[j][0])*(bl[i][0] - bl[j][0]) + (bl[i][1] - bl[j][1])*(bl[i][1] - bl[j][1]));
                double a = ((bl[j][2] * bl[j][2] - bl[i][2] * bl[i][2]) / l + l) / 2;
                double x = (bl[i][0] * a + bl[j][0] * (l - a)) / l, y = (bl[i][1] * a + bl[j][1] * (l - a)) / l, z = bl[j][2] * bl[j][2] - a*a;
                if (z < 0)continue;
                if (z<ans&&a > 0 && a < l)ans = z;
                rep(k, j) {
                    double x[2][3] = { {double(bl[i][0] - bl[j][0]),double(bl[i][1] - bl[j][1]),double(-bl[i][2] * bl[i][2] + bl[j][2] * bl[j][2] + bl[i][0] * bl[i][0] + bl[i][1] * bl[i][1] - bl[j][0] * bl[j][0] - bl[j][1] * bl[j][1])},{ double(bl[i][0] - bl[k][0]),double(bl[i][1] - bl[k][1]),double(-bl[i][2] * bl[i][2] + bl[k][2] * bl[k][2] + bl[i][0] * bl[i][0] + bl[i][1] * bl[i][1] - bl[k][0] * bl[k][0] - bl[k][1] * bl[k][1]) } };
                    double a, b, c;
                    if (x[1][1] == 0) {
                        if (x[0][1] == 0)continue;
                        if (x[1][0]*x[0][1] - (x[1][1] )*x[0][0] == 0)continue;
                        a = 1/ (2*(x[1][0]*x[0][1] - (x[1][1])*x[0][0]))*(x[1][2]*x[0][1] - x[1][1]  * x[0][2]);
                        b = (x[0][2]*0.5 - a*x[0][0])*(1/ x[0][1]);
                    }
                    else {
                        if (x[0][0]*x[1][1] - (x[0][1])*x[1][0] == 0)continue;
                        a = 1/ (2*(x[0][0]*x[1][1] - (x[0][1] )*x[1][0]))*(x[0][2]*x[1][1] - x[0][1]* x[1][2]);
                        b = (x[1][2] *0.5 - a*x[1][0]) *(1 / x[1][1]);
                    }
                    c = bl[i][2] * bl[i][2] - (a - bl[i][0])*(a - bl[i][0]) - (b - bl[i][1])*(b - bl[i][1]);
                    if (c < 0)continue;
                    if (c >= ans)continue;
                    int cc = ccw( P(a, b),P(bl[i][0], bl[i][1]), P(bl[j][0], bl[j][1]));
                    if (cc == ccw(P(a, b),P(bl[j][0], bl[j][1]), P(bl[k][0], bl[k][1])) && cc == ccw(P(a, b),P(bl[k][0], bl[k][1]), P(bl[i][0], bl[i][1])))ans = c;
                }
            }
        }
        cout << fixed << setprecision(7) << sqrt(ans) << endl;
    }
}