Problem:
Problem Statement
Circles Island is known for its mysterious shape:
it is a completely flat island with its shape being a union of circles whose centers are on the $x$-axis and their inside regions.
The King of Circles Island plans to build a large square on Circles Island in order to celebrate the fiftieth anniversary of his accession.
The King wants to make the square as large as possible.
The whole area of the square must be on the surface of Circles Island, but any area of Circles Island can be used for the square.
He also requires that the shape of the square is square (of course!) and at least one side of the square is parallel to the $x$-axis.
You, a minister of Circles Island, are now ordered to build the square.
First, the King wants to know how large the square can be.
You are given the positions and radii of the circles that constitute Circles Island.
Answer the side length of the largest possible square.
$N$ circles are given in an ascending order of their centers' $x$-coordinates.
You can assume that for all $i$ ($1 \le i \le N-1$), the $i$-th and $(i+1)$-st circles overlap each other.
You can also assume that no circles are completely overlapped by other circles.
[fig.1 : Shape of Circles Island and one of the largest possible squares for test case #1 of sample input]
Input
The input consists of multiple datasets. The number of datasets does not exceed $30$.
Each dataset is formatted as follows.
$N$
$X_1$ $R_1$
:
:
$X_N$ $R_N$
The first line of a dataset contains a single integer $N$ ($1 \le N \le 50{,}000$), the number of circles that constitute Circles Island.
Each of the following $N$ lines describes a circle.
The $(i+1)$-st line contains two integers $X_i$ ($-100{,}000 \le X_i \le 100{,}000$) and $R_i$ ($1 \le R_i \le  100{,}000$).
$X_i$ denotes the $x$-coordinate of the center of the $i$-th circle and $R_i$ denotes the radius of the $i$-th circle.
The $y$-coordinate of every circle is $0$, that is, the center of the $i$-th circle is at ($X_i$, $0$).
You can assume the followings.
For all $i$ ($1 \le i \le N-1$), $X_i$ is strictly less than $X_{i+1}$.
For all $i$ ($1 \le i \le N-1$), the $i$-th circle and the $(i+1)$-st circle have at least one common point ($X_{i+1} - X_i \le R_i + R_{i+1}$).
Every circle has at least one point that is not inside or on the boundary of any other circles.
The end of the input is indicated by a line containing a zero.
Output
For each dataset, output a line containing the side length of the square with the largest area.
The output must have an absolute or relative error at most $10^{-4}$.
Sample Input
2
0 8
10 8
2
0 7
10 7
0
Output for the Sample Input
12.489995996796796
9.899494936611665

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
#define N 55555
#define M 133333
#define eps 1e-8
using namespace std;
int n,i,ll,rr;double an,l,r,md,xx,yy,X[N],R[N],XX[N],YY[N],V[M];
double sqr(double x){return x*x;}
void bd(int k,int l,int r){
	if(l==r){
		V[k]=YY[l];
		return;
	}
	int md=l+r>>1;
	bd(k<<1,l,md);bd(k<<1|1,md+1,r);
	V[k]=min(V[k<<1],V[k<<1|1]);
}
double qu(int k,int l,int r,int x,int y){
	if(x>y)return 1e18;
	if(x<=l&&r<=y)return V[k];
	int md=l+r>>1;double w=1e18;
	if(x<=md)w=min(w,qu(k<<1,l,md,x,y));
	if(y>md)w=min(w,qu(k<<1|1,md+1,r,x,y));
	return w;
}
int main(){
	for(;scanf("%d",&n),n;){
		an=0;
		for(i=1;i<=n;i++)scanf("%lf%lf",&X[i],&R[i]);
		for(i=1;i<n;i++){
			XX[i]=X[i]+(sqr(R[i])-sqr(R[i+1])+sqr(X[i+1]-X[i]))/(X[i+1]-X[i])/2;
			YY[i]=sqrt(sqr(R[i])-sqr(XX[i]-X[i]));
//			printf("%.4f %.4f\n",XX[i],YY[i]);
		}
		XX[n]=X[n]+R[n];YY[n]=0;
		bd(1,1,n);
		for(i=1;i<=n;i++){
			for(l=0,r=R[i]*2;r-l>eps;){
				md=(l+r)*.5;
				xx=sqrt(sqr(R[i])-sqr(md/2));
			//	printf("%.4f %.4f\n",X[i]-xx,X[i]+xx);
				ll=lower_bound(XX+1,XX+n+1,X[i]-xx)-XX;
				rr=upper_bound(XX+1,XX+n+1,X[i]-xx+md)-XX-1;
				if(sqrt(sqr(R[rr+1])-sqr(X[rr+1]-(X[i]-xx+md)))*2>=md&&qu(1,1,n,ll,rr)*2>=md)l=md;else r=md;
			//	printf("%.4f %d %d\n",md,ll,rr);
//				if(qu(1,1,n,ll,rr)*2>=md)l=md;else r=md;
			}
			an=max(an,l);
		}
		printf("%.12f\n",an);
	}
}
accuracy: 1
time_ms: 3480
memory_kb: 6168
final_rank: 16

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

void Solve(int N) {
    vector<double> X(N), R(N);
    rep(i,0,N) cin >> X[i] >> R[i];
    auto Judge = [&](double M) -> bool {
        vector<pair<double,double>> V;
        rep(i,0,N) {
            if (R[i] <= M/2.0) continue;
            double D = sqrt(R[i]*R[i]-(M/2.0)*(M/2.0));
            V.push_back({X[i]-D,X[i]+D});
        }
        if (V.empty()) return false;
        sort(ALL(V));
        double CurL = V[0].first, CurR = V[0].second;
        if (CurR-CurL >= M) return true;
        rep(i,1,V.size()) {
            if (CurR < V[i].first) CurL = V[i].first, CurR = V[i].second;
            else chmax(CurR,V[i].second);
            if (CurR-CurL >= M) return true;
        }
        return false;
    };
    double OK = 0.0, NG = 200001.0;
    rep(_,0,100) {
        double MID = (OK+NG)/2.0;
        if (Judge(MID)) OK = MID;
        else NG = MID;
    }
    printf("%.12f\n", (OK+NG)/2.0);
}

int main() {
while(1) {
    int N;
    cin >> N;
    if (N == 0) return 0;
    Solve(N);
}
}
accuracy: 1
time_ms: 1310
memory_kb: 5768
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define revrep(i, t, s) for (int i = (int)(t)-1; i >= (int)(s); --i)
#define all(x) begin(x), end(x)
template <typename T> bool chmax(T& a, const T& b) { return a < b ? (a = b, 1) : 0; }
template <typename T> bool chmin(T& a, const T& b) { return a > b ? (a = b, 1) : 0; }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    while (true) {
        int N;
        cin >> N;
        if (N == 0) break;
        vector<double> X(N), R(N);
        rep(i,0,N) cin >> X[i] >> R[i];
        double lb = 0, ub = 1e7;
        rep(_,0,50) {
            double m = (lb + ub) / 2;
            vector<pair<double, double>> intervals;
            rep(i,0,N) {
                if (m/2 < R[i]) {
                    double d = sqrt(R[i]*R[i]-m*m/4);
                    intervals.push_back({X[i]-d, X[i]+d});
                }
            }
            sort(all(intervals), [&](auto& p1, auto& p2) {
                return p1.second < p2.second;
            });
            vector<pair<double, double>> st;
            for (auto [l, r] : intervals) {
                while (!st.empty() && l < st.back().second) {
                    auto [l0, r0] = st.back();
                    st.pop_back();
                    l = min(l, l0);
                }
                st.push_back({l, r});
            }
            bool ok = false;
            for (auto [l, r] : st) {
                if (r-l > m) {
                    ok = true;
                    break;
                }
            }
            if (ok) lb = m;
            else ub = m;
        }
        cout << lb << endl;
    }
}
accuracy: 1
time_ms: 620
memory_kb: 6700
final_rank: 4

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define eps 1e-9
#define INF 2000000000              // 2e9
#define LLINF 2000000000000000000ll // 2e18 (llmax:9e18)
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define drep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)

#define popcount __builtin_popcount
#define next __next
#define prev __prev

#ifndef LOCAL
#define dmp(...) ;
#else
#define dmp(...)                                                               \
  cerr << "[ " << #__VA_ARGS__ << " ] : " << dump_str(__VA_ARGS__) << endl
#endif

// ---------------- Utility ------------------

template <class T>
bool chmin(T &a, const T &b) {
  if (a <= b) return false;
  a = b;
  return true;
}

template <class T>
bool chmax(T &a, const T &b) {
  if (a >= b) return false;
  a = b;
  return true;
}

template <class T>
using MaxHeap = priority_queue<T>;

template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;

template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

// ----------------- Input -------------------

template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  return is >> p.first >> p.second;
}

template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}

// ----------------- Output ------------------

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << p.first << ',' << p.second;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (const T &e : v) os << e << " ";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const deque<T> &d) {
  for (const T &e : d) os << e << " ";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const set<T> &s) {
  os << "{ ";
  for (const T &e : s) os << e << " ";
  return os << "}";
}

template <class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &m) {
  os << "{ ";
  for (const auto &[key, val] : m) os << "( " << key << " -> " << val << " ) ";
  return os << "}";
}

template <class TupleTy, size_t... I>
void dump_tuple(ostream &os, const TupleTy t, std::index_sequence<I...>) {
  (..., (os << (I == 0 ? "" : ",") << std::get<I>(t)));
}

template <class... Args>
ostream &operator<<(ostream &os, const tuple<Args...> &t) {
  os << "(";
  dump_tuple(os, t, std::make_index_sequence<sizeof...(Args)>());
  return os << ")";
}

void dump_str_rec(ostringstream &) {}

template <class Head, class... Tail>
void dump_str_rec(ostringstream &oss, Head &&head, Tail &&... tail) {
  oss << ", " << head;
  dump_str_rec(oss, forward<Tail>(tail)...);
}

template <class T, class... U>
string dump_str(T &&arg, U &&... args) {
  ostringstream oss;
  oss << arg;
  dump_str_rec(oss, forward<U>(args)...);
  return oss.str();
}

// --------------- Fast I/O ------------------

void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

// ------------------ ACL --------------------

// #include <atcoder/modint>
// constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
// using mint = atcoder::static_modint<MOD>;
// ostream &operator<<(ostream &os, const mint &v) {
//   return os << v.val();
// }

// ------------ End of template --------------

#define endl "\n"
using ll = long long;
using pii = pair<int, int>;

const bool multitest = false;

bool solve() {
  int N;
  cin >> N;
  if (N == 0) return false;

  vector<double> X(N), R(N);
  for (int i = 0; i < N; i++) cin >> X[i] >> R[i];

  auto check = [&](double k) {
    vector<double> l, r;
    for (int i = 0; i < N; i++) {
      if (R[i] < k) continue;
      double w = sqrt(R[i] * R[i] - k * k);
      l.push_back(X[i] - w);
      r.push_back(X[i] + w);
    }
    vector<double> zip;
    zip.insert(zip.end(), l.begin(), l.end());
    zip.insert(zip.end(), r.begin(), r.end());
    sort(all(zip));
    zip.erase(unique(all(zip)), zip.end());
    vector<int> cnt(zip.size() + 1, 0);
    for (int i = 0; i < l.size(); i++) {
      int idx = lower_bound(all(zip), l[i]) - zip.begin();
      int jdx = lower_bound(all(zip), r[i]) - zip.begin();
      cnt[idx]++;
      cnt[jdx]--;
    }
    dmp(k);
    dmp(zip);
    dmp(l, r);
    double cur = 0.0;
    double mx_len = 0.0;
    for (int i = 0; i < zip.size(); i++) {
      if (i > 0) cnt[i] += cnt[i - 1];
      if (cnt[i] > 0 && i + 1 < zip.size())
        cur += zip[i + 1] - zip[i];
      else
        cur = 0.0;
      chmax(mx_len, cur);
    }
    dmp(mx_len);
    return mx_len >= 2.0 * k;
  };

  double l = 0.0, r = 1000000.0;
  for (int i = 0; i < 50; i++) {
    double mid = (l + r) / 2.0;
    if (check(mid))
      l = mid;
    else
      r = mid;
  }
  cout << l * 2.0 << endl;
  return true;
}

int main() {
  fastio();
  if (!multitest) {
    while (solve()) {}
  } else {
    cerr << "[Warning] Multi testcase mode on" << endl;
    int t;
    cin >> t;
    while (t--) solve();
  }
  return 0;
}
accuracy: 1
time_ms: 3410
memory_kb: 6420
final_rank: 15

code_snippet: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;
using ldouble = long double;

constexpr ldouble INF = 1e10;

bool solve() {
    int n;
    cin >> n;
    if (n == 0) return false;

    vector<pair<ldouble, ldouble>> cs(n);
    for (auto& [x, r] : cs) cin >> x >> r;

    ldouble ok = 0, ng = INF;
    for (int q = 0; q < 100; ++q) {
        ldouble mid = (ok + ng) / 2;

        vector<pair<ldouble, ldouble>> segs;
        for (auto [x, r] : cs) {
            if (r < mid) continue;
            ldouble rad = sqrt(r * r - mid * mid);
            segs.emplace_back(x - rad, x + rad);
        }

        sort(segs.begin(), segs.end(),
             [](auto a, auto b) { return a.second < b.second; });

        bool valid = false;
        ldouble pl = -INF, pr = -INF;
        for (auto [l, r] : segs) {
            if (l < pl || pr < l) pl = l;
            pr = r;
            if (pr - pl >= mid * 2) valid = true;
        }

        if (valid) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    cout << ok * 2 << "\n";
    return true;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    while (solve()) {}

    return 0;
}
accuracy: 1
time_ms: 2050
memory_kb: 8504
final_rank: 13

code_snippet: #pragma GCC ta g("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
//#include <atcoder/maxflow>
//using namespace atcoder;
const int inf = (1<<30)-1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-9;
//const int mod = 1e9 + 7;
const int mod = 998244353;

int main(){
	while(1){
		int n; cin >> n;
		if(!n) break; 
		vl x(n),r(n);
		rep(i,n) cin >> x[i] >> r[i];
		long double ok = 0, ng = 200000;
		rep(z,50){
			long double mid = (ok+ng) / 2;
			vector<pair<long double, long double>> seg,seg2;
			rep(i,n){
				if(mid >= r[i]) continue;
				long double L = (long double)x[i] - sqrtl(r[i]*r[i]-mid*mid);
				long double R = (long double)x[i] + sqrtl(r[i]*r[i]-mid*mid);
				seg.emplace_back(L,R);
			}
			sort(all(seg));
			for(auto p : seg){
				if(!seg2.empty() && seg2.back().second >= p.first - eps){
					chmax(seg2.back().second, p.second);
				}else{
					seg2.emplace_back(p);
				}
			}
			bool f = false;
			for(auto p : seg2){
				if(p.second - p.first >= mid*2 - eps) f = true;
			}
			if(f) ok = mid;
			else ng = mid;
		}
		printf("%.10Lf\n",ok*2);
	}
}
accuracy: 1
time_ms: 1470
memory_kb: 9224
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;


#include <algorithm>
#include <cassert>
#include <vector>


#ifdef _MSC_VER
#include <intrin.h>
#endif

namespace atcoder {

namespace internal {

int ceil_pow2(int n) {
    int x = 0;
    while ((1U << x) < (unsigned int)(n)) x++;
    return x;
}

constexpr int bsf_constexpr(unsigned int n) {
    int x = 0;
    while (!(n & (1 << x))) x++;
    return x;
}

int bsf(unsigned int n) {
#ifdef _MSC_VER
    unsigned long index;
    _BitScanForward(&index, n);
    return index;
#else
    return __builtin_ctz(n);
#endif
}

}  // namespace internal

}  // namespace atcoder


namespace atcoder {

template <class S, S (*op)(S, S), S (*e)()> struct segtree {
  public:
    segtree() : segtree(0) {}
    explicit segtree(int n) : segtree(std::vector<S>(n, e())) {}
    explicit segtree(const std::vector<S>& v) : _n(int(v.size())) {
        log = internal::ceil_pow2(_n);
        size = 1 << log;
        d = std::vector<S>(2 * size, e());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) {
            update(i);
        }
    }

    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        d[p] = x;
        for (int i = 1; i <= log; i++) update(p >> i);
    }

    S get(int p) const {
        assert(0 <= p && p < _n);
        return d[p + size];
    }

    S prod(int l, int r) const {
        assert(0 <= l && l <= r && r <= _n);
        S sml = e(), smr = e();
        l += size;
        r += size;

        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return op(sml, smr);
    }

    S all_prod() const { return d[1]; }

    template <bool (*f)(S)> int max_right(int l) const {
        return max_right(l, [](S x) { return f(x); });
    }
    template <class F> int max_right(int l, F f) const {
        assert(0 <= l && l <= _n);
        assert(f(e()));
        if (l == _n) return _n;
        l += size;
        S sm = e();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!f(op(sm, d[l]))) {
                while (l < size) {
                    l = (2 * l);
                    if (f(op(sm, d[l]))) {
                        sm = op(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = op(sm, d[l]);
            l++;
        } while ((l & -l) != l);
        return _n;
    }

    template <bool (*f)(S)> int min_left(int r) const {
        return min_left(r, [](S x) { return f(x); });
    }
    template <class F> int min_left(int r, F f) const {
        assert(0 <= r && r <= _n);
        assert(f(e()));
        if (r == 0) return 0;
        r += size;
        S sm = e();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!f(op(d[r], sm))) {
                while (r < size) {
                    r = (2 * r + 1);
                    if (f(op(d[r], sm))) {
                        sm = op(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = op(d[r], sm);
        } while ((r & -r) != r);
        return 0;
    }

  private:
    int _n, size, log;
    std::vector<S> d;

    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};

}  // namespace atcoder

using namespace atcoder;

//geometry library by maine

//basic
using Real = double;
using Point = complex<Real>;
#define x real()
#define y imag()
const Real EPS = 1e-8, PI = acos(-1), INF = 1e8;

istream& operator>>(istream& is, Point& p) {
    Real a, b;
    is >> a >> b;
    p = Point(a, b);
    return is;
}
ostream& operator<<(ostream& os, Point p) {
    return os << fixed << setprecision(10) << p.x << " " << p.y;
}

Point operator*(const Point& p, const Real& d) { return Point(p.x * d, p.y * d); }

bool eq(const Real& r, const Real& s) { return abs(r - s) < EPS; }
bool eq(const Point& p, const Point& q) { return abs(p - q) < EPS; }

namespace std {
bool operator<(const Point& a, const Point& b) {
    return !eq(a.x, b.x) ? a.x < b.x : a.y < b.y;
}
}  // namespace std

Real get_angle(const Point& a, const Point& b, const Point& c) {
    return arg((c - a) / (b - a));
}

inline int inc(int i, int N) {
    return (i == N - 1 ? 0 : i + 1);
}
inline int dec(int i, int N) {
    return (i == 0 ? N - 1 : i - 1);
}

//unit vector
Point e(const Point& p) { return p / abs(p); }

//angle transformation
Real radian_to_degree(Real r) { return r * 180.0 / PI; }
Real degree_to_radian(Real d) { return d * PI / 180.0; }

//basic functions
Real dot(const Point& p, const Point& q) { return p.x * q.x + p.y * q.y; }
Real cross(const Point& p, const Point& q) { return p.x * q.y - p.y * q.x; }
Point rotate(const Real& theta, const Point& p) {
    return {cos(theta) * p.x - sin(theta) * p.y, sin(theta) * p.x + cos(theta) * p.y};
}
Point rotate90(const Point& p) {
    return {-p.y, p.x};
}

//structs : Line, Segment, Circle
struct Line {
    Point a, b;
    Line() = default;
    Line(Point a, Point b) : a(a), b(b) {}
    Point d() const { return e(b - a); }  //direction vector
    Point n() const {
        Point dd = d();
        return {dd.y, -dd.x};
    }  //normal vector
};
struct Segment : Line {
    Segment() = default;
    Segment(Point a, Point b) : Line(a, b) {}
};
struct Circle {
    Point p;
    Real r;
    Circle() = default;
    Circle(Point p, Real r) : p(p), r(r){};
};
using Points = vector<Point>;
using Polygon = vector<Point>;
using Polygons = vector<Polygon>;
using Lines = vector<Line>;
using Segments = vector<Segment>;
using Circles = vector<Circle>;

//happy functions
//https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C
int ccw(const Point& a, const Point& bb, const Point& cc) {
    Point b = bb - a, c = cc - a;
    if (cross(b, c) > EPS)
        return 1;  //COUNTER_CLOCKWISE
    if (cross(b, c) < -EPS)
        return -1;  //CLOCKWISE
    if (dot(b, c) < 0)
        return 2;  //ONLINE_BACK  c-a-b
    if (norm(b) < norm(c))
        return -2;  //ONLINE_FRONT a-b-c
    return 0;       //ON_SEGMENT   a-c-b
}

bool parallel(const Line& l, const Line& m) { return eq(cross(l.d(), m.d()), 0.0); }
bool orthogonal(const Line& l, const Line& m) { return eq(dot(l.d(), m.d()), 0.0); }
Point projection(const Line& l, const Point& p) { return l.a + (l.a - l.b) * (dot(p - l.a, l.a - l.b) / norm(l.a - l.b)); }
Point reflection(const Line& l, const Point& p) { return p + (projection(l, p) - p) * 2.0; }

//intersect
bool intersect(const Line& l, const Point& p) { return abs(ccw(l.a, l.b, p)) != 1; }
bool intersect(const Line& l, const Line& m) { return !parallel(l, m) || (parallel(l, m) && intersect(l, m.a)); }
bool intersect(const Segment& s, const Point& p) { return ccw(s.a, s.b, p) == 0; }
bool intersect(const Line& l, const Segment& s) { return cross(l.d(), s.a - l.a) * cross(l.d(), s.b - l.a) < EPS; }
bool intersect(const Segment& s, const Segment& t) {
    return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}
bool intersect_onsegment(const Segment& s, const Point& p) { return intersect(s, p) && !eq(s.a, p) && !eq(s.b, p); }

//distance
Real distance(const Point& p, const Point& q) { return abs(p - q); }
Real distance(const Line& l, const Point& p) { return distance(p, projection(l, p)); }
Real distance(const Line& l, const Line& m) { return intersect(l, m) ? 0 : distance(l, m.a); }
Real distance(const Segment& s, const Point& p) {
    Point q = projection(s, p);
    return intersect(s, q) ? distance(p, q) : min(distance(s.a, p), distance(s.b, p));
}
Real distance(const Segment& s, const Segment& t) { return intersect(s, t) ? 0 : min({distance(s, t.a), distance(s, t.b), distance(t, s.a), distance(t, s.b)}); }
Real distance(const Line& l, const Segment& s) { return intersect(l, s) ? 0 : min(distance(l, s.a), distance(l, s.b)); }

//intersect circle
bool intersect(const Circle& c, const Point& p) { return eq(distance(c.p, p), c.r); }
bool intersect(const Circle& c, const Line& l) { return distance(l, c.p) <= c.r + EPS; }
int intersect(const Circle& c, const Segment& s) {
    if (!intersect(c, Line(s)))
        return 0;
    Real da = distance(c.p, s.a), db = distance(c.p, s.b);
    if (da < c.r + EPS && db < c.r + EPS)
        return 0;
    if (da > db)
        swap(da, db);
    if (da < c.r - EPS && db > c.r + EPS)
        return 1;
    if (intersect(s, projection(s, c.p)))
        return 2;
    return 0;
}
int intersect(Circle c1, Circle c2) {
    if (c1.r < c2.r)
        swap(c1, c2);
    Real d = distance(c1.p, c2.p);
    if (c1.r + c2.r < d)
        return 4;
    if (eq(c1.r + c2.r, d))
        return 3;
    if (c1.r - c2.r < d)
        return 2;
    if (eq(c1.r - c2.r, d))
        return 1;
    return 0;
}

//crosspoint
Point crosspoint(const Line& l, const Line& m) {
    Real A = cross(l.b - l.a, m.b - m.a);
    Real B = cross(l.b - l.a, l.b - m.a);
    if (eq(abs(A), 0.0) && eq(abs(B), 0.0))
        return m.a;
    return m.a + (m.b - m.a) * B / A;
}
Point crosspoint(const Segment& s, const Segment& t) { return crosspoint(Line(s), Line(t)); }
pair<Point, Point> crosspoint(const Circle& c, const Line& l) {
    Point p = projection(l, c.p);
    if (eq(distance(l, c.p), c.r))
        return {p, p};
    Real len = sqrt(c.r * c.r - norm(p - c.p));
    return {p - len * l.d(), p + len * l.d()};
}
pair<Point, Point> crosspoint(const Circle& c, const Segment& s) {
    Line l(s);
    if (intersect(c, s) == 2)
        return crosspoint(c, l);
    auto ret = crosspoint(c, l);
    if (dot(s.a - ret.first, s.b - ret.first) < 0)
        ret.second = ret.first;
    else
        ret.first = ret.second;
    return ret;
}
pair<Point, Point> crosspoint(const Circle& c1, const Circle& c2) {
    Real d = distance(c1.p, c2.p);
    Real a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
    Real t = atan2(c2.p.y - c1.p.y, c2.p.x - c1.p.x);
    Point p1 = c1.p + Point(cos(t + a) * c1.r, sin(t + a) * c1.r);
    Point p2 = c1.p + Point(cos(t - a) * c1.r, sin(t - a) * c1.r);
    return {p1, p2};
}

//tangent
pair<Point, Point> tangent(const Circle& c, const Point& p) {
    return crosspoint(c, Circle(p, sqrt(norm(c.p - p) - c.r * c.r)));
}
Lines tangent(Circle c1, Circle c2) {
    Lines ret;
    if (c1.r < c2.r)
        swap(c1, c2);
    if (eq(c1.p, c2.p))
        return ret;
    Real g = norm(c1.p - c2.p);
    Point u = (c2.p - c1.p) / sqrt(g);
    Point v = rotate(PI / 2, u);
    for (int s : {-1, 1}) {
        Real h = (c1.r + s * c2.r) / sqrt(g);
        if (eq(1 - h * h, 0)) {
            ret.emplace_back(c1.p + u * c1.r, c1.p + (u + v) * c1.r);
        } else if (1 - h * h > 0) {
            Point uu = u * h, vv = v * sqrt(1 - h * h);
            ret.emplace_back(c1.p + (uu + vv) * c1.r, c2.p - (uu + vv) * c2.r * s);
            ret.emplace_back(c1.p + (uu - vv) * c1.r, c2.p - (uu - vv) * c2.r * s);
        }
    }
    return ret;
}

//convex
//https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/3/CGL_3_B
bool is_convex(const Polygon& P) {
    int N = (int)P.size();
    for (int i = 0; i < N; i++) {
        if (ccw(P[i], P[(i + 1) % N], P[(i + 2) % N]) == -1)
            return false;
    }
    return true;
}
//https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/4/CGL_4_A
Polygon convex_hull(Points P) {
    int N = (int)P.size(), k = 0;
    if (N <= 2)
        return P;
    sort(begin(P), end(P));
    Points ret(2 * N);
    for (int i = 0; i < N; ret[k++] = P[i++]) {
        while (k >= 2 && cross(ret[k - 1] - ret[k - 2], P[i] - ret[k - 1]) < EPS)
            --k;
    }
    for (int i = N - 2, t = k + 1; i >= 0; ret[k++] = P[i--]) {
        while (k >= t && cross(ret[k - 1] - ret[k - 2], P[i] - ret[k - 1]) < EPS)
            --k;
    }
    ret.resize(k - 1);
    return ret;
}
//https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/4/CGL_4_B
Real convex_diameter(const Polygon& P) {
    int N = (int)P.size();
    int is = 0, js = 0;
    for (int i = 1; i < N; i++) {
        if (P[i].y < P[is].y)
            is = i;
        if (P[i].y > P[js].y)
            js = i;
    }
    Real maxdist = norm(P[is] - P[js]);
    int maxi, maxj, i, j;
    maxi = i = is;
    maxj = j = js;
    do {
        if (cross(P[inc(i, N)] - P[i], P[inc(j, N)] - P[j]) >= 0)
            j = inc(j, N);
        else
            i = inc(i, N);
        if (norm(P[i] - P[j]) > maxdist) {
            maxdist = norm(P[i] - P[j]);
            maxi = i;
            maxj = j;
        }
    } while (i != is || j != js);
    maxi = maxi;
    maxj = maxj;
    return sqrt(maxdist);
}
//https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/4/CGL_4_C
Polygon convex_cut(const Polygon& P, const Line& l) {
    Polygon ret;
    int N = (int)P.size();
    for (int i = 0; i < N; i++) {
        Point now = P[i], nxt = P[(inc(i, N))];
        if (ccw(l.a, l.b, now) != -1)
            ret.emplace_back(now);
        if (ccw(l.a, l.b, now) * ccw(l.a, l.b, nxt) == -1)
            ret.emplace_back(crosspoint(Line(now, nxt), l));
    }
    return ret;
}

//other
enum
{
    OUT,
    ON,
    IN
};

//https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/3/CGL_3_C
int contains(const Polygon& Q, const Point& p) {
    bool in = false;
    int N = (int)Q.size();
    for (int i = 0; i < N; i++) {
        Point a = Q[i] - p, b = Q[(i + 1) % N] - p;
        if (a.y > b.y)
            swap(a, b);
        if (a.y <= 0 && 0 < b.y && cross(a, b) < 0)
            in = !in;
        if (cross(a, b) == 0 && dot(a, b) <= 0)
            return ON;
    }
    return in ? IN : OUT;
}

//https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/3/CGL_3_A
Real area(const Polygon& P) {
    Real A = 0;
    for (int i = 0; i < (int)P.size(); i++) {
        A += cross(P[i], P[(i + 1) % P.size()]);
    }
    return A * 0.5;
}

//https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/7/CGL_7_H
Real cross_area(const Circle& c, const Point& a, const Point& b) {
    Point va = c.p - a, vb = c.p - b;
    Real f = cross(va, vb), ret = 0.0;
    if (eq(f, 0.0))
        return ret;
    if (max(abs(va), abs(vb)) < c.r + EPS)
        return f;
    if (distance(Segment(a, b), c.p) > c.r - EPS)
        return c.r * c.r * arg(vb * conj(va));
    auto u = crosspoint(c, Segment(a, b));
    vector<Point> V{a, u.first, u.second, b};
    for (int i = 0; i < (int)V.size() - 1; i++) {
        ret += cross_area(c, V[i], V[i + 1]);
    }
    return ret;
}
Real area(const Polygon& p, const Circle& c) {
    int N = (int)p.size();
    if (N < 3)
        return 0.0;
    Real ret = 0;
    for (int i = 0; i < N; i++) {
        ret += cross_area(c, p[i], p[inc(i, N)]);
    }
    return ret / 2.0;
}

//https://onlinejudge.u-aizu.ac.jp/problems/CGL_5_A
Real closest_pair(Points& P, int left, int right) {
    if (right - left <= 1)
        return 1e18;
    int mid = (left + right) / 2;
    Real xx = P[mid].x;
    Real dist = min(closest_pair(P, left, mid), closest_pair(P, mid, right));
    inplace_merge(P.begin() + left, P.begin() + mid, P.begin() + right, [&](const Point& a, const Point& b) { return a.y < b.y; });
    Points memo;
    memo.reserve(right - left);
    for (int i = left; i < right; i++) {
        if (abs(P[i].x - xx) >= dist)
            continue;
        for (int j = (int)memo.size() - 1; j >= 0; j--) {
            if (P[i].y - memo[j].y >= dist)
                break;
            dist = min(dist, distance(P[i], memo[j]));
        }
        memo.emplace_back(P[i]);
    }
    return dist;
}
Real closest_pair(Points P) {
    sort(begin(P), end(P));
    return closest_pair(P, 0, (int)P.size());
}

//https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/7/CGL_7_B
Circle incircle(Polygon P) {
    assert((int)P.size() == 3);
    Real l0 = distance(P[1], P[2]), l1 = distance(P[0], P[2]), l2 = distance(P[0], P[1]);
    Circle c;
    c.p = crosspoint(Line(P[0], (P[1] * l1 + P[2] * l2) / (l1 + l2)), Line(P[1], (P[0] * l0 + P[2] * l2) / (l0 + l2)));
    c.r = distance(Line(P[0], P[1]), c.p);
    return c;
}

//https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/7/CGL_7_C
Circle circumcircle(Polygon P) {
    assert((int)P.size() == 3);
    Circle c;
    c.p = crosspoint(Line((P[0] + P[1]) / 2.0, (P[0] + P[1]) / 2.0 + rotate90(P[0] - P[1])),
        Line((P[0] + P[2]) / 2.0, (P[0] + P[2]) / 2.0 + rotate90(P[0] - P[2])));
    c.r = distance(c.p, P[0]);
    return c;
}

#undef x
#undef y

double op(double a, double b) { return min(a, b); }
double e() { return INF; }

int main() {
    int N;
    while (cin >> N, N) {
        double ans = 0;
        Circles C(N);
        for (auto&& c : C) {
            double x;
            cin >> x >> c.r;
            c.p = {x, 0};
        }
        Points P(N - 1);
        vector<double> H(N - 1), X(N - 1);
        for (int i = 0; i < N - 1; i++) {
            auto [p, q] = crosspoint(C[i], C[i + 1]);
            P[i] = p.imag() > 0 ? p : q;
            H[i] = P[i].imag();
            X[i] = P[i].real();
        }

        segtree<double, op, e> seg(H);

        for (int i = 0; i < N; i++) {
            auto c = C[i];

            auto check = [&](double len) {
                double h = len / 2;
                Line L{{0, h}, {1e5, h}};
                double xl = crosspoint(c, L).first.real();
                int r = seg.max_right(i, [&](double a) { return a > h - EPS; });
                double xr = crosspoint(C[r], L).second.real();
                return xr - xl >= len;
            };

            double ok = c.r * sqrt(2);
            double ng = c.r * 2;
            while (abs(ok - ng) > EPS) {
                double mid = (ok + ng) / 2;
                if (check(mid)) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            ans = max(ans, ok);
        }
        cout << fixed << setprecision(15) << ans << endl;
    }
}
accuracy: 1
time_ms: 3610
memory_kb: 7712
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=155;
const ll INF=1LL<<60;
//幾何ライブラリ

const double eps=1e-8;
const double pi=acos((double)-1.0L);
#define equals(a,b) (fabs((a)-(b))<eps)

double torad(double deg) {return (double)(deg)*pi/180.0;}
double todeg(double ang) {return ang*180.0/pi;}

class Point{
public:
    double x,y;
    
    Point(double x=0,double y=0):x(x),y(y){}
    
    Point operator + (Point p){return Point(x+p.x,y+p.y);}
    Point operator - (Point p){return Point(x-p.x,y-p.y);}
    Point operator * (double a){return Point(a*x,a*y);}
    Point operator / (double a){return Point(x/a,y/a);}
    
    double abs(){return sqrt(norm());}
    double norm(){return x*x+y*y;}
    
    bool operator < (const Point &p)const{
        return x+eps<p.x||(equals(x,p.x)&&y+eps<p.y);
    }
    
    bool operator == (const Point &p)const{
        return fabs(x-p.x)<eps/100000&&fabs(y-p.y)<eps/100000;
    }
};

typedef Point Vector;

double norm(Vector a){
    return a.x*a.x+a.y*a.y;
}

double abs(Vector a){
    return sqrt(norm(a));
}

double dot(Vector a,Vector b){
    return a.x*b.x+a.y*b.y;
}

double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

struct Segment{
    Point p1,p2;
};

bool isOrthogonal(Vector a,Vector b){
    return equals(dot(a,b),0.0);
}

bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){
    return isOrthogonal(a1-a2,b1-b2);
}

bool isOrthogonal(Segment s1,Segment s2){
    return equals(dot(s1.p2-s1.p1,s2.p2-s2.p1),0.0);
}

bool isParallel(Vector a,Vector b){
    return equals(cross(a,b),0.0);
}

bool isParallel(Point a1,Point a2,Point b1,Point b2){
    return isParallel(a1-a2,b1-b2);
}

bool isParallel(Segment s1,Segment s2){
    return equals(cross(s1.p2-s1.p1,s2.p2-s2.p1),0.0);
}

Point project(Segment s,Point p){
    Vector base=s.p2-s.p1;
    double r=dot(p-s.p1,base)/norm(base);
    return s.p1+base*r;
}

Point reflect(Segment s,Point p){
    return p+(project(s,p)-p)*2.0;
}

Point turn(Point p,Point c,double pi){
    double q=atan2(p.y-c.y,p.x-c.x);
    q+=pi;
    p=c+Point{cos(q)*abs(p-c),sin(q)*abs(p-c)};
    
    return p;
}
//pをcを中心としてpi回転させる(1周で2π)
//p=cのときnan

//p0,p1,p2の順に見たときどうなるか？

static const int counter_clockwise=1;
static const int clockwise=-1;
static const int online_back=2;
static const int online_front=-2;
static const int on_segment=0;

int ccw(Point p0,Point p1,Point p2){
    Vector a=p1-p0;
    Vector b=p2-p0;
    
    if(cross(a,b)>eps) return counter_clockwise;
    if(cross(a,b)<-eps) return clockwise;
    if(dot(a,b)<-eps) return online_back;
    if(a.norm()<b.norm()) return online_front;
    
    return on_segment;
}

bool intersect(Point p1,Point p2,Point p3,Point p4){
    return(ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0&&ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}

bool intersect(Segment s1,Segment s2){
    return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}

bool overlap(Segment s1,Segment s2){
    int a=ccw(s1.p1,s1.p2,s2.p1),b=ccw(s1.p1,s1.p2,s2.p2);
    if(a&1||b&1) return 0;
    if(a==2){
        if(b==-2||(b==0&&!(s2.p2==s1.p1))) return 1;
        else return 0;
    }
    if(a==-2){
        if(b==2||(b==0&&!(s2.p2==s1.p2))) return 1;
        else return 0;
    }
    if(a==0){
        if(s1.p1==s2.p1){
            if(b!=2) return 1;
            else return 0;
        }
        else if(s1.p2==s2.p1){
            if(b!=-2) return 1;
            else return 0;
        }
        else return 1;
    }
    return 0;
}
//s1とs2の共通の線分(長さ0より大きい)があるかどうか

typedef Segment Line;

double getDistance(Point a,Point b){
    return abs(a-b);
}

double getDistanceLP(Line l,Point p){
    return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));
}

double getDistanceSP(Segment s,Point p){
    if(dot(s.p2-s.p1,p-s.p1)<0.0) return abs(p-s.p1);
    if(dot(s.p1-s.p2,p-s.p2)<0.0) return abs(p-s.p2);
    return getDistanceLP(s,p);
}

double getDistance(Segment s1,Segment s2){
    if(intersect(s1,s2)) return 0.0;
    return min({getDistanceSP(s1,s2.p1),getDistanceSP(s1,s2.p2),getDistanceSP(s2,s1.p1),getDistanceSP(s2,s1.p2)});
}

Point getCrossPointS(Segment s1,Segment s2){
    //if(ccw(s1.p1,s1.p2,s2.p1)==0&&ccw(s1.p1,s1.p2,s2.p2)==0) return s1.p1;
    Vector base=s2.p2-s2.p1;
    double d1=abs(cross(base,s1.p1-s2.p1));
    double d2=abs(cross(base,s1.p2-s2.p1));
    double t=d1/(d1+d2);
    return s1.p1+(s1.p2-s1.p1)*t;
}//同じ時壊れます

Point getCrossPointL(Line l1,Line l2){
    //if(ccw(s1.p1,s1.p2,s2.p1)==0&&ccw(s1.p1,s1.p2,s2.p2)==0) return s1.p1;
    
    Vector v1=l1.p2-l1.p1,v2=l2.p2-l2.p1;
    
    return l1.p1+v1*cross(v2,l2.p1-l1.p1)/cross(v2,v1);
}

Segment ParallelSegment(Segment s,double d){
    Vector v={-(s.p2-s.p1).y,(s.p2-s.p1).x};
    v=v/abs(v);
    
    s.p1=s.p1+v*d;
    s.p2=s.p2+v*d;
    
    return s;
}

Point naisin(Point p1,Point p2,Point p3){
    if(p1==p2&&p2==p3&&p3==p1) return p1;
    
    return (p1*abs(p2-p3)+p2*abs(p1-p3)+p3*abs(p1-p2))/(abs(p2-p3)+abs(p1-p3)+abs(p1-p2));
}

Point naisin(Line l1,Line l2,Line l3){
    //平行でない前提
    
    Point p1=getCrossPointL(l1,l2),p2=getCrossPointL(l1,l3),p3=getCrossPointL(l2,l3);
    return naisin(p1,p2,p3);
}

//ネットの適当を書いたのであってるか全く知りません→あってそう

class Circle{
public:
    Point c;
    double r;
    Circle(Point c=Point(),double r=0.0):c(c),r(r){}
};

Point CircleCenter(Point a,Point b,Point c){
    Point u=a-b,v=a-c;
    double m1=(norm(a)-norm(b))/2.0,m2=(norm(a)-norm(c))/2.0;
    
    Point res;
    if(cross(u,v)==0.0){
        res.x=1e9;
        res.y=1e9;
        
        return res;
    }
    res.x=(m1*v.y-m2*u.y)/cross(u,v);
    res.y=(m1*v.x-m2*u.x)/cross(v,u);
    
    return res;
}
//3点を通る円の中心を返す

//交わる 0
// c1がc2のinside 1
// c1がc2のoutside 2
// 交わらない 3

int not_intersect(Circle c1,Circle c2){
    double d=getDistance(c1.c,c2.c);
    double r1=c1.r,r2=c2.r;
    if(r1<r2){
        if(d<(r2-r1)) return 1;
    }
    if(r1>r2){
        if(d<(r1-r2)) return 2;
    }
    if(d<=r1+r2) return 0;
    else return 3;
}

pair<Point,Point> segCrossPpoints(Circle c,Line l){
    //assert(intersect(c,l));
    Vector pr=project(l,c.c);
    Vector e=(l.p2-l.p1)/abs(l.p2-l.p1);
    double base=sqrt(c.r*c.r-norm(pr-c.c));
    return make_pair(pr+e*base,pr-e*base);
}

double arg(Vector p){return atan2(p.y,p.x);}
Vector polar(double a,double r){return Point(cos(r)*a,sin(r)*a);}

//inside(outside)

pair<Point,Point> getCrossPoints(Circle c1,Circle c2){
    //assert(intersect(c1,c2));
    double d=abs(c1.c-c2.c);
    double a=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*c1.r*d));
    double t=arg(c2.c-c1.c);
    return make_pair(c1.c+polar(c1.r,t+a),c1.c+polar(c1.r,t-a));
}

vector<Line> Commontangent(Circle c1,Circle c2){
    vector<Line> res;
    Point p=c2.c-c1.c;
    
    if(abs(p)>=(c1.r+c2.r)){
        Point a,b;
        a.x=c1.r*(p.x*(c1.r+c2.r)+p.y*sqrt(norm(p)-(c1.r+c2.r)*(c1.r+c2.r)))/norm(p);
        a.y=c1.r*(p.y*(c1.r+c2.r)-p.x*sqrt(norm(p)-(c1.r+c2.r)*(c1.r+c2.r)))/norm(p);
        
        b.x=c1.r*(p.x*(c1.r+c2.r)-p.y*sqrt(norm(p)-(c1.r+c2.r)*(c1.r+c2.r)))/norm(p);
        b.y=c1.r*(p.y*(c1.r+c2.r)+p.x*sqrt(norm(p)-(c1.r+c2.r)*(c1.r+c2.r)))/norm(p);
        
        res.push_back(Line{a+c1.c,a+c1.c+Point{-a.y,a.x}});
        if(!(a==b)){
            res.push_back(Line{b+c1.c,b+c1.c+Point{-b.y,b.x}});
        }
    }
    
    if(abs(p)>=abs(c1.r-c2.r)){
        Point a,b;
        a.x=c1.r*(p.x*(c1.r-c2.r)+p.y*sqrt(norm(p)-(c1.r-c2.r)*(c1.r-c2.r)))/norm(p);
        a.y=c1.r*(p.y*(c1.r-c2.r)-p.x*sqrt(norm(p)-(c1.r-c2.r)*(c1.r-c2.r)))/norm(p);
        
        b.x=c1.r*(p.x*(c1.r-c2.r)-p.y*sqrt(norm(p)-(c1.r-c2.r)*(c1.r-c2.r)))/norm(p);
        b.y=c1.r*(p.y*(c1.r-c2.r)+p.x*sqrt(norm(p)-(c1.r-c2.r)*(c1.r-c2.r)))/norm(p);
        
        res.push_back(Line{a+c1.c,a+c1.c+Point{-a.y,a.x}});
        if(!(a==b)){
            res.push_back(Line{b+c1.c,b+c1.c+Point{-b.y,b.x}});
        }
    }
    
    return res;
}

typedef vector<Point> Polygon;

/*
 IN 2
 ON 1
 OUT 0
 */

int contains(Polygon g,Point p){
    int n=int(g.size());
    bool x=false;
    for(int i=0;i<n;i++){
        Point a=g[i]-p,b=g[(i+1)%n]-p;
        if(a.y>b.y) swap(a,b);
        if(a.y<eps&&0<b.y&&cross(a,b)<0) x=!x;
        if(abs(cross(a,b))<eps&&dot(a,b)<eps) return 1;
    }
    return (x?2:0);
}

Polygon andrewScan(Polygon s,bool ok){
    Polygon u,l;
    sort(all(s));
    
    if(int(s.size())<3) return s;
    int n=int(s.size());
    
    u.push_back(s[0]);
    u.push_back(s[1]);
    
    l.push_back(s[n-1]);
    l.push_back(s[n-2]);
    
    if(ok){
        for(int i=2;i<n;i++){
            for(int j=int(u.size());j>=2&&ccw(u[j-2],u[j-1],s[i])==counter_clockwise;j--){
                u.pop_back();
            }
            u.push_back(s[i]);
        }
        
        for(int i=int(s.size())-3;i>=0;i--){
            for(int j=int(l.size());j>=2&&ccw(l[j-2],l[j-1],s[i])==counter_clockwise;j--){
                l.pop_back();
            }
            l.push_back(s[i]);
        }
    }
    
    if(!ok){
        for(int i=2;i<n;i++){
            for(int j=int(u.size());j>=2&&ccw(u[j-2],u[j-1],s[i])!=clockwise;j--){
                u.pop_back();
            }
            u.push_back(s[i]);
        }
        
        for(int i=int(s.size())-3;i>=0;i--){
            for(int j=int(l.size());j>=2&&ccw(l[j-2],l[j-1],s[i])!=clockwise;j--){
                l.pop_back();
            }
            l.push_back(s[i]);
        }
    }
    
    reverse(all(l));
    
    for(int i=int(u.size())-2;i>=1;i--) l.push_back(u[i]);
    
    return l;
}//ok==1なら辺の上も含める

Polygon convex_cut(const Polygon& P, const Line& l) {
    Polygon Q;
    for(int i=0;i<si(P);i++){
        Point A=P[i],B=P[(i+1)%si(P)];
        if(ccw(l.p1,l.p2,A)!=-1)Q.push_back(A);
        if(ccw(l.p1,l.p2,A)*ccw(l.p1,l.p2,B)<0) Q.push_back(getCrossPointL(Line{A,B},l));
    }
    return Q;
}

double area(Point a,Point b,Point c){
    b=b-a;
    c=c-a;
    return abs(b.x*c.y-b.y*c.x)/2.0;
}

double area(Polygon &P){
    if(si(P)==0) return 0.0;
    double res=0;
    Point c={0.0,0.0};
    for(int i=0;i<si(P);i++){
        c=c+P[i];
    }
    c=c/si(P);
    
    for(int i=0;i<si(P);i++){
        res+=area(c,P[i],P[(i+1)%si(P)]);
    }
    
    return res;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        vector<Circle> C(N);
        for(int i=0;i<N;i++) cin>>C[i].c.x>>C[i].r;
        double left=0,right=100005;
        for(int q=0;q<50;q++){
            double mid=(left+right)/2;
            Line ln={{-2e5,mid},{2e5,mid}};
            bool ok=false;
            double l=-2e5,r=-2e5;
            for(int i=0;i<N;i++){
                if(C[i].r<mid) continue;
                auto P=segCrossPpoints(C[i],ln);
                if(P.fi.x>P.se.x) swap(P.fi,P.se);
                if(r+eps<P.fi.x){
                    if(r-l>=mid*2) ok=true;
                    l=P.fi.x;
                    r=P.se.x;
                }else{
                    chmin(l,P.fi.x);
                    chmax(r,P.se.x);
                }
            }
            if(r-l>=mid*2) ok=true;
            if(ok) left=mid;
            else right=mid;
        }
        cout<<fixed<<setprecision(25)<<(left*2)<<"\n";
    }
}
accuracy: 1
time_ms: 440
memory_kb: 4620
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
  cout << fixed << setprecision(20);
  while (true){
    int N;
    cin >> N;
    if (N == 0){
      break;
    }
    vector<double> X(N), R(N);
    for (int i = 0; i < N; i++){
      cin >> X[i] >> R[i];
    }
    double mx = 0;
    for (int i = 0; i < N; i++){
      mx = max(mx, R[i]);
    }
    vector<double> l(N), r(N);
    l[0] = X[0] - R[0];
    for (int i = 0; i < N - 1; i++){
      double d = X[i + 1] - X[i];
      double m = (R[i] * R[i] + d * d - R[i + 1] * R[i + 1]) / (d * 2);
      r[i] = X[i] + m;
      l[i + 1] = X[i] + m;
    }
    r[N - 1] = X[N - 1] + R[N - 1];
    double tv = 0, fv = mx * 2;
    for (int i = 0; i < 40; i++){
      double mid = (tv + fv) / 2;
      vector<double> p;
      for (int j = 0; j < N; j++){
        if (R[j] > mid / 2){
          double d = sqrt(R[j] * R[j] - (mid / 2) * (mid / 2));
          if (l[j] < X[j] - d && X[j] - d < r[j]){
            p.push_back(X[j] - d);
          }
          if (l[j] < X[j] + d && X[j] + d < r[j]){
            p.push_back(X[j] + d);
          }
        }
      }
      int M = p.size() / 2;
      bool ok = false;
      for (int j = 0; j < M; j++){
        if (p[j * 2 + 1] - p[j * 2] > mid){
          ok = true;
        }
      }
      if (ok){
        tv = mid;
      } else {
        fv = mid;
      }
    }
    cout << tv << endl;
  }
}
accuracy: 1
time_ms: 460
memory_kb: 6548
final_rank: 2

code_snippet: #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-10;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 21;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

int n;
void solve() {
	vector<ll> x(n), r(n);
	rep(i, n)cin >> x[i] >> r[i];
	vector<ld> px(n + 1);
	px[0] = x[0] - r[0];
	px[n] = x[n - 1] + r[n - 1];
	rep1(i, n - 1) {
		ld a = r[i - 1] * r[i - 1] - r[i] * r[i] - (x[i - 1] * x[i - 1] - x[i] * x[i]);
		ld b = -2 * (x[i - 1] - x[i]);
		px[i] = a / b;
	}
	auto can = [&](ld z) {
		vector<LDP> v;
		rep(i, n) {
			ld le = px[i];
			ld ri = px[i + 1];
			ld dif = 0;
			if (r[i] > z / 2) {
				dif = sqrtl(r[i] * r[i] - (z / 2) * (z / 2));
			}
			le = max(le, x[i] - dif);
			ri = min(ri, x[i] + dif);
			v.push_back({ le,ri });
		}
		rep(i, v.size()) {
			int le = i;
			while (i + 1 < v.size() && v[i + 1].first < v[i].second + eps) {
				i++;
			}
			ld dist = v[i].second - v[le].first;
			if (dist >= z)return true;
		}
		return false;
	};
	ld le = 0, ri = (x[n - 1] + r[n - 1]) - (x[0] - r[0]);
	rep(aa, 70) {
		ld mid=(le + ri) / 2;
		if (can(mid)) {
			le = mid;
		}
		else {
			ri = mid;
		}
	}
	cout << le << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);
	//init_f();
	//init();
	//expr();

	//int t; cin >> t; rep(i, t)
	while(cin>>n,n)
	solve();
	return 0;
}
accuracy: 1
time_ms: 750
memory_kb: 39124
final_rank: 20

code_snippet: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int t[55000][2];
typedef pair<long double,int> DP;

int main(){
    int n,m;
    int i,j,k;
    int a,b,c;
    long double da,db;
    while(cin>>n){
        long double ds=0;
        if(!n)break;
        a=0;
        for(i=0;i<n;i++){
            cin>>t[i][0]>>t[i][1];
            a=max(a,t[i][1]);
        }
        ds=a*sqrt(2);
        set<int> s1;
        s1.insert(0),s1.insert(n);
        priority_queue<DP,vector<DP>,greater<DP>> q1;
        for(i=0;i+1<n;i++){
            if(t[i+1][0]-t[i][0]>=t[i][1]+t[i+1][1]){
                s1.insert(i+1);
                continue;
            }
            a=t[i+1][0]-t[i][0],b=t[i][1],c=t[i+1][1];
            da=(double)(a+b+c)/2;
            db=sqrt(da*(da-a)*(da-b)*(da-c));
            da=2*db/a;
            q1.push(make_pair(da,i+1));
        }
        while(!q1.empty()){
            da=q1.top().first,a=q1.top().second,q1.pop();
            long double z[3]={0,da};
            auto itr=s1.lower_bound(a);
            c=*itr;
            itr--;
            b=*itr,c--;
            for(i=0;i<50;i++){
                z[2]=(z[0]+z[1])/2;
                db=t[c][0]-t[b][0];
                db+=sqrt(pow(t[b][1],2)-pow(z[2],2))+sqrt(pow(t[c][1],2)-pow(z[2],2));
                if(db<z[2]*2)z[1]=z[2];
                else z[0]=z[2];
            }
            ds=max(ds,z[0]*2);
            s1.insert(a);
        }
        cout<<fixed<<setprecision(10)<<ds<<endl;
    }
}
accuracy: 1
time_ms: 1290
memory_kb: 8084
final_rank: 8

code_snippet: #include <bits/stdc++.h>
#define int long long
using namespace std;

const double INF = 1e+7;

int n;
double x[50010],r[50010];

bool check(double y){
	vector<pair<double,bool>> vec;
	for(int i = 0;i < n;i++){
		double sq = r[i] * r[i] - y * y / 4;
		if(sq > 0){
			vec.emplace_back(x[i] - sqrt(sq),0);
			vec.emplace_back(x[i] + sqrt(sq),1);
		}
	}
	sort(vec.begin(),vec.end());
	double ma = 0,prv;
	int cnt = 0;
	for(auto p : vec){
		if(!p.second){
			cnt++;
			if(cnt == 1) prv = p.first;
		}else{
			cnt--;
			if(!cnt) ma = max(ma,p.first - prv);
		}
	}
	return ma >= y;
}

void solve(){
	for(int i = 0;i < n;i++) cin >> x[i] >> r[i];
	double ok = 0,ng = INF;
	for(int i = 0;i < 50;i++){
		double mid = (ok + ng) / 2;
		if(check(mid)) ok = mid;
		else ng = mid;
	}
	printf("%.15lf\n",ok);
}

signed main(){
	while(cin >> n,n) solve();
}
accuracy: 1
time_ms: 1740
memory_kb: 7364
final_rank: 12

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

typedef double D;
typedef complex<D> P;
typedef pair<P, P> L;
typedef vector<P> VP;
const D EPS = 1e-9;
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

D dot(P a, P b) {
  return (conj(a)*b).X;
}

P proj(P a1, P a2, P p) {
  return a1 + dot(a2-a1, p-a1)/norm(a2-a1) * (a2-a1);
}

VP crosspointLC(P a1, P a2, P c, D r) {
    VP ps;
    P ft = proj(a1, a2, c);
    if (!GE(r*r, norm(ft-c))) return ps;

    P dir = sqrt(max(r*r - norm(ft-c), 0.0)) / abs(a2-a1) * (a2-a1);
    ps.push_back(ft + dir);
    if (!EQ(r*r, norm(ft-c))) ps.push_back(ft - dir);
    return ps;
}

int n;
double x[50000], r[50000];

void solve() {
    rep(i,n) {
        cin >> x[i] >> r[i];
    }
    double le = 0.0, ri = 200000.0;
    rep(i,100) {
        double mid = (le + ri) / 2.0;
        P ho = P(0.0, mid), ge = P(1.0, mid);
        double nowl = -1000000.0, nowr = -1000000.0;
        bool ok = false;
        vector<pd> vd;
        rep(j,n) {
            VP vp = crosspointLC(ho, ge, P(x[j],0.0), r[j]);
            if (vp.size() != 2) continue;
            if (vp[0].X < vp[1].X) {
                vd.push_back(pd(vp[0].X, vp[1].X));
            } else {
                vd.push_back(pd(vp[1].X, vp[0].X));
            }
        }
        sort(vd.begin(), vd.end());
        rep(j,vd.size()) {
            if (nowr < vd[j].first) {
                nowl = vd[j].first;
                nowr = vd[j].second;
            } else {
                nowr = max(nowr, vd[j].second);
            }
            if (GE(nowr-nowl,2*mid)) {
                ok = true;
                break;
            }
        }
        if (ok) le = mid;
        else ri = mid;
    }
    printf("%.9f\n", le*2);
}

int main() {
    while (cin >> n) {
        if (n == 0) break;
        solve();
    }
}
accuracy: 1
time_ms: 5410
memory_kb: 5428
final_rank: 19

code_snippet: #include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	while (cin >> N, N) {
		vector<double> X(N), R(N);
		for (int i = 0; i < N; ++i) {
			cin >> X[i] >> R[i];
		}
		double l = 0.0, r = 2.0e+5;
		for (int rep = 0; rep < 40; ++rep) {
			double m = (l + r) / 2;
			vector<double> sl, sr, plist;
			for (int i = 0; i < N; ++i) {
				if (R[i] >= m / 2) {
					double delta = sqrt(double(R[i]) * R[i] - m * m / 4);
					sl.push_back(X[i] - delta);
					sr.push_back(X[i] + delta);
				}
			}
			plist.insert(plist.end(), sl.begin(), sl.end());
			plist.insert(plist.end(), sr.begin(), sr.end());
			sort(plist.begin(), plist.end());
			int SN = sl.size();
			vector<int> imos(2 * SN);
			for (int i = 0; i < SN; ++i) {
				int idl = lower_bound(plist.begin(), plist.end(), sl[i]) - plist.begin();
				int idr = lower_bound(plist.begin(), plist.end(), sr[i]) - plist.begin();
				++imos[idl];
				--imos[idr];
			}
			int pre = 0, sum = 0;
			bool ok = false;
			for (int i = 0; i < 2 * SN; ++i) {
				sum += imos[i];
				if (sum == 0) {
					double len = plist[i] - plist[pre];
					if (len >= m) ok = true;
					pre = i + 1;
				}
			}
			if (ok) l = m;
			else r = m;
		}
		cout.precision(15);
		cout << r << '\n';
	}
	return 0;
}
accuracy: 1
time_ms: 3030
memory_kb: 6156
final_rank: 14

code_snippet: #include <iostream>
#include <stdio.h>
#include <cmath>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;

int n;
double x[50005], r[50005];

bool check(double m)
{
	vector<pair<double, int> > vec;
	for(int i = 1; i <= n; i++){
		double l = r[i]*r[i] - m*m;
		if(l <= 0) continue;
		l = sqrt(l);
		vec.push_back(make_pair(x[i]-l, 0));
		vec.push_back(make_pair(x[i]+l, 1));
	}
	sort(vec.begin(), vec.end());
	
	double mx = 0, pre; int cnt = 0;
	for(int i = 0; i < vec.size(); i++){
		if(vec[i].second == 0){
			if(cnt == 0) pre = vec[i].first;
			cnt++;
		}
		else{
			cnt--;
			if(cnt == 0) mx = max(mx, vec[i].first - pre);
		}
	}
	return mx >= m*2;
}

int main(void)
{
	while(1){
		cin >> n;
		if(n == 0) break;
		for(int i = 1; i <= n; i++) cin >> x[i] >> r[i];
		
		double ub = 1e9, lb = 0, mid;
		for(int i = 0; i < 100; i++){
			mid = (ub+lb)/2;
			if(check(mid)) lb = mid;
			else ub = mid;
		}
		double ans = ub+lb;
		printf("%.11f\n", ans);
	}
	
	return 0;
}
accuracy: 1
time_ms: 3300
memory_kb: 7492
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 1e8;
const double EPS = 1e-8;

int main(){
    int n;
    while(scanf(" %d", &n),n){
        vector<int> x(n),r(n);
        rep(i,n) scanf(" %d %d", &x[i], &r[i]);

        auto check = [&](double a){
            double s = INF, e = -INF;
            rep(i,n){
                if(2*r[i]+EPS < a) continue;
                double theta = asin(a/r[i]/2);
                double dx = r[i]*cos(theta);

                double L = x[i]-dx, R=x[i]+dx;
                // printf(" %d:  %f %f\n",i,L,R);

                if(max(s,L) > min(e,R)){
                    s = L;
                    e = R;
                }
                else{
                    s = min(s,L);
                    e = max(e,R);
                }

                if(e-s>a) return true;
            }
            return false;
        };

        double ok=0, ng=200000;
        rep(loop,80){
            double mid = (ok+ng)/2;
            if(check(mid)) ok = mid;
            else ng = mid;
        }
        printf("%.10f\n", ok);
    }
    return 0;
}
accuracy: 1
time_ms: 1490
memory_kb: 3824
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 1e8;
const double EPS = 1e-8;

int main(){
    int n;
    while(scanf(" %d", &n),n){
        vector<int> x(n),r(n);
        rep(i,n) scanf(" %d %d", &x[i], &r[i]);

        auto check = [&](double a){
            double s = INF;
            double e = -INF;

            rep(i,n){
                if(2*r[i]+EPS < a) continue;
                double theta = asin(a/r[i]/2);
                double dx = r[i]*cos(theta);

                double L = x[i]-dx, R=x[i]+dx;
                // printf(" %d:  %f %f\n",i,L,R);

                if(max(s,L) > min(e,R)){
                    s = L;
                    e = R;
                }
                else{
                    s = min(s,L);
                    e = max(e,R);
                }

                if(e-s>a) return true;
            }

            return false;
        };

        double ok=0, ng=200000;
        rep(loop,100){
            double mid = (ok+ng)/2;
            if(check(mid)) ok = mid;
            else ng = mid;
        }
        printf("%.10f\n", ok);
    }
    return 0;
}
accuracy: 1
time_ms: 1900
memory_kb: 3864
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;

using pdd = pair<double, double>;

double solve(vector<double> x, vector<double> r) {
    const int n = x.size();
    auto check = [&] (double h) {
        vector<pdd> ps(n);
        for(int i = 0; i < n; ++i) {
            double x1 = x[i], x2 = x[i];
            if(h <= r[i]) {
                x1 -= sqrt(r[i] * r[i] - h * h);
                x2 += sqrt(r[i] * r[i] - h * h);
            }
            ps[i] = make_pair(x1, x2);
        }
        sort(begin(ps), end(ps));
        double lx = -1e9, rx = -2e9;
        for(int i = 0; i < n; ++i) {
            if(rx < ps[i].first) {
                if(rx - lx >= 2 * h) return true;
                lx = ps[i].first, rx = ps[i].second;
            } else {
                rx = max(rx, ps[i].second);
            }
        }
        return rx - lx >= 2 * h;
    };
    double lb = 0, ub = 2e5;
    for(int lp = 0; lp < 60; ++lp) {
        const auto mid = (lb + ub) / 2;
        (check(mid) ? lb : ub) = mid;
    }
    return lb * 2;
}

int main() {
    int n;
    while(cin >> n, n) {
        vector<double> x(n), r(n);
        for(int i = 0; i < n; ++i) {
            cin >> x[i] >> r[i];
        }
        cout << fixed << setprecision(10) << solve(move(x), move(r)) << endl;
    }
}
accuracy: 1
time_ms: 1330
memory_kb: 4588
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

typedef double D;
typedef complex<D> P;

#define X real()
#define Y imag()

const D eps=1e-9;
const D inf=1e12;
const D PI=acos(-1);

bool cmp_x(const P& a,const P& b){ return a.X==b.X?a.Y<b.Y:a.X<b.X; }
bool cmp_y(const P& a,const P& b){ return a.Y==b.Y?a.X<b.X:a.Y<b.Y; }
bool cmp_a(const P& a,const P& b){ return arg(a)==arg(b)?norm(a)<norm(b):arg(a)<arg(b); }
D cross(P a,P b){ return (conj(a)*b).Y; }
D dot(P a,P b){ return (conj(a)*b).X; }
D toRag(D deg){ return deg*PI/180.0; }
P rot(P base,P a,D theta){ return base+polar(abs(a-base),arg(a-base)+theta); }

struct C{
  P p; D r;
  C(const P& p,D r):p(p),r(r){}
};

void crosspointCC(const C& c1,const C& c2,P& p1,P& p2){
  D x1=c2.p.X-c1.p.X,y1=c2.p.Y-c1.p.Y;
  D r1=c1.r,r2=c2.r;
  D a=(x1*x1+y1*y1+r1*r1-r2*r2)/2.0;
  p1=P(((a*x1+y1*sqrt((x1*x1+y1*y1)*r1*r1-a*a))/(x1*x1+y1*y1))+c1.p.X,((a*y1-x1*sqrt((x1*x1+y1*y1)*r1*r1-a*a))/(x1*x1+y1*y1))+c1.p.Y);
  p2=P(((a*x1-y1*sqrt((x1*x1+y1*y1)*r1*r1-a*a))/(x1*x1+y1*y1))+c1.p.X,((a*y1+x1*sqrt((x1*x1+y1*y1)*r1*r1-a*a))/(x1*x1+y1*y1))+c1.p.Y);
}

int N;
int X0[50010],R[50010];
double l[50010],r[50010];
double crtl[50010],crtr[50010];

bool ok(double H){
  rep(i,N){
    if((double)R[i]<H){
      crtl[i]=-inf; crtr[i]=-inf;
      continue;
    }
    crtl[i]=max(l[i],X0[i]-sqrt(pow((double)R[i],2)-pow(H,2)));
    crtr[i]=min(r[i],X0[i]+sqrt(pow((double)R[i],2)-pow(H,2)));
    if(crtl[i]>crtr[i]){
      crtl[i]=-inf; crtr[i]=-inf;
    }
  }
  double mx=0,crt=0;
  rep(i,N){
    if(abs(l[i]-crtl[i])>eps){
      crt=0;
    }
    crt+=crtr[i]-crtl[i];
    maxch(mx,crt);
    if(abs(r[i]-crtr[i])>eps){
      crt=0;
    }
  }
  return mx>H*2-eps;
}

int main(){
  while(1){
    scanf("%d",&N);
    if(N==0)break;
    vector<C> cs;
    rep(i,N){
      scanf("%d%d",X0+i,R+i);
      cs.push_back(C(P(X0[i],0),R[i]));
    }
    l[0]=X0[0]-R[0];
    rep(i,N-1){
      P p1,p2;
      crosspointCC(cs[i],cs[i+1],p1,p2);
      r[i]=p1.X; l[i+1]=p1.X;
    }
    r[N-1]=X0[N-1]+R[N-1];

    double lb=0,ub=5e5;
    rep(_,50){
      double mid=(lb+ub)/2.0;
      if(ok(mid))lb=mid;
      else ub=mid;
    }
    printf("%.10f\n", 2.0*lb);
  }
  return 0;
}
accuracy: 1
time_ms: 340
memory_kb: 7456
final_rank: 3

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 50005

struct Point{
	double x,y;
};

struct Circle{
	Point center;
	double r;
};

struct Info{
	Info(double arg_loc,int arg_value){
		loc = arg_loc;
		value = arg_value;
	}
	bool operator<(const struct Info &arg) const{
		return loc < arg.loc; //場所の昇順
	}
	double loc;
	int value;
};

int N;
Circle circle[NUM];
vector<Info> V;

bool is_ok(double tmp_height){

	V.clear();
	double tmp_diff;

	for(int i = 0; i < N; i++){
		if(2.0*circle[i].r > tmp_height){
			//数直線上でimos
			tmp_diff = sqrt(circle[i].r*circle[i].r-(tmp_height*tmp_height)/4.0);
			V.push_back(Info(circle[i].center.x-tmp_diff,1));
			V.push_back(Info(circle[i].center.x+tmp_diff,-1));
		}
	}

	sort(V.begin(),V.end());

	int tmp_sum = 0;
	double pre_loc = 999999999.0,tmp_max = 0;

	for(int i = 0; i < V.size(); i++){

		if(tmp_sum == 0){ //重み区間外から、左端に遭遇

			pre_loc = V[i].loc;
		}

		tmp_sum += V[i].value;

		if(tmp_sum == 0){ //線分完成
			/*★高さは条件を満たしているので、幅の最大値がtmp_height以上であれば良い★*/
			tmp_max = max(tmp_max,V[i].loc-pre_loc);
		}
	}

	if(tmp_height <= tmp_max){

		return true;

	}else{
		return false;
	}
}

void func(){

	double maximum = 0;

	for(int i = 0; i < N; i++){
		scanf("%lf %lf",&circle[i].center.x,&circle[i].r);
		maximum = max(maximum,2.0*circle[i].r); //仮の最大長
	}

	double left = 0,right = maximum,mid = (left+right)/2.0;
	double ans = -1;

	for(int loop = 0; loop < 50; loop++){

		if(is_ok(mid)){

			ans = mid;
			left = mid+EPS; //より大きく

		}else{

			right = mid-EPS;
		}
		mid = (left+right)/2.0;
	}
	printf("%.10lf\n",ans);
}

int main(){

	while(true){

		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}
accuracy: 1
time_ms: 1670
memory_kb: 6088
final_rank: 10